Skip to content

Commit

Permalink
feat: added help description for single command
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Oct 3, 2023
1 parent 3032258 commit dfd8156
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bin/paragon-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const COMMANDS = {
}

if (command === HELP_COMMAND) {
helpCommand(COMMANDS);
helpCommand(COMMANDS, commandArgs);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/build-scss.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const { pathToFileURL } = require('url');
const path = require('path');
const minimist = require('minimist');
const chalk = require('chalk');
const capitalize = require('lodash.capitalize');
const ora = require('ora');
const { capitalize } = require('./utils');

const paragonThemeOutputFilename = 'theme-urls.json';

Expand Down
18 changes: 15 additions & 3 deletions lib/help.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
/* eslint-disable no-console */
const chalk = require('chalk');

/**
* Finds a command based on the given name in the commands object.
*
* @param {Array} commandName - The name to find the command.
* @param {Object} commands - The object containing commands to search in.
* @returns {Object|null} - The found command or null if the command is not found.
*/
const findCommandByName = (commandName, commands) => ({ [commandName]: commands[commandName] } ?? null);

/**
* Displays a help message for available commands, including descriptions, parameters, and options.
*
* @param {Object} commands - An object containing information about available commands.
* @param {Array} commandArgs - An array containing the command name.
*/
function helpCommand(commands) {
function helpCommand(commands, commandArgs) {
console.log(chalk.yellow.bold('Paragon Help'));
console.log();
console.log('Available commands:');
console.log(`Available ${commandArgs.length ? 'command' : 'commands'}:`);
console.log();

Object.entries(commands).forEach(([command, { parameters, description, options }]) => {
const retrievedCommands = commandArgs.length ? findCommandByName(commandArgs, commands) : commands;

Object.entries(retrievedCommands).forEach(([command, { parameters, description, options }]) => {
console.log(` ${chalk.green.underline.bold(command)}`);
if (description) {
console.log(` ${description}`);
Expand Down
15 changes: 15 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Capitalizes the first letter of a string.
*
* @param {string} str - The input string to be capitalized.
* @returns {string} The string with the first letter capitalized.
*/
// eslint-disable-next-line import/prefer-default-export
function capitalize(str) {
if (typeof str !== 'string' || str.length === 0) {
return '';
}
return str.charAt(0).toUpperCase() + str.slice(1);
}

module.exports = { capitalize };
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"file-selector": "^0.6.0",
"glob": "^8.0.3",
"inquirer": "^8.2.5",
"lodash.capitalize": "^4.2.1",
"lodash.uniqby": "^4.7.0",
"log-update": "^4.0.0",
"mailto-link": "^2.0.0",
Expand Down

0 comments on commit dfd8156

Please sign in to comment.