diff --git a/bin/paragon-scripts.js b/bin/paragon-scripts.js index 488fd0c817f..6181363d164 100755 --- a/bin/paragon-scripts.js +++ b/bin/paragon-scripts.js @@ -173,7 +173,7 @@ const COMMANDS = { } if (command === HELP_COMMAND) { - helpCommand(COMMANDS); + helpCommand(COMMANDS, commandArgs); return; } diff --git a/lib/build-scss.js b/lib/build-scss.js index 11fa8bbd52e..6ed27c4b487 100755 --- a/lib/build-scss.js +++ b/lib/build-scss.js @@ -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'; diff --git a/lib/help.js b/lib/help.js index 48f2c7cccb1..2ec78fbb997 100644 --- a/lib/help.js +++ b/lib/help.js @@ -1,18 +1,35 @@ /* 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 in 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) { + const retrievedCommands = commandArgs.length ? findCommandByName(commandArgs, commands) : commands; + if (!retrievedCommands) { + console.error(chalk.red.bold('Unknown command. Usage: paragon help .')); + return; + } + 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 }]) => { + Object.entries(retrievedCommands).forEach(([command, { parameters, description, options }]) => { console.log(` ${chalk.green.underline.bold(command)}`); if (description) { console.log(` ${description}`); diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 00000000000..53eae1eece5 --- /dev/null +++ b/lib/utils.js @@ -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 }; diff --git a/package-lock.json b/package-lock.json index 6b8922048e3..411e50303cd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,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", @@ -24911,7 +24910,8 @@ "node_modules/lodash.capitalize": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/lodash.capitalize/-/lodash.capitalize-4.2.1.tgz", - "integrity": "sha512-kZzYOKspf8XVX5AvmQF94gQW0lejFVgb80G85bU4ZWzoJ6C03PQg3coYAUpSTpQWelrZELd3XWgHzw4Ck5kaIw==" + "integrity": "sha512-kZzYOKspf8XVX5AvmQF94gQW0lejFVgb80G85bU4ZWzoJ6C03PQg3coYAUpSTpQWelrZELd3XWgHzw4Ck5kaIw==", + "dev": true }, "node_modules/lodash.clonedeep": { "version": "4.5.0", diff --git a/package.json b/package.json index 69ee3beaca2..5b94424e26c 100644 --- a/package.json +++ b/package.json @@ -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",