-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add help command for Paragon CLI (#2603)
* feat: help command for Paragon CLI * feat: remove console log * feat: PR comments update * feat: update commands code --------- Co-authored-by: monteri <lansevermore>
- Loading branch information
Showing
4 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* eslint-disable no-console */ | ||
const chalk = require('chalk'); | ||
|
||
const DESCRIPTION_PAD = 20; | ||
|
||
/** | ||
* Pads a description string to align with a specified offset string. | ||
* | ||
* @param {string} description - The description to pad. | ||
* @param {string} offsetString - The offset string that the description should align with. | ||
* @returns {string} - The padded description. | ||
*/ | ||
function padLeft(description, offsetString) { | ||
// Calculate the necessary padding based on the offsetString length | ||
const padding = ' '.repeat(Math.max(0, DESCRIPTION_PAD - offsetString.length)); | ||
return `${padding}${description}`; | ||
} | ||
|
||
/** | ||
* Displays a help message for available commands, including descriptions, parameters, and options. | ||
* | ||
* @param {Object} commands - An object containing information about available commands. | ||
*/ | ||
function helpCommand(commands) { | ||
console.log(chalk.yellow.bold('Paragon Help')); | ||
console.log(); | ||
console.log('Available commands:'); | ||
console.log(); | ||
|
||
Object.entries(commands).forEach(([command, { parameters, description, options }]) => { | ||
console.log(` ${chalk.green.bold(command)}`); | ||
if (description) { | ||
console.log(` ${description}`); | ||
} | ||
|
||
if (parameters && parameters.length > 0) { | ||
console.log(` ${chalk.cyan('Parameters: ')}`); | ||
parameters.forEach(parameter => { | ||
const requiredStatus = parameter.required ? 'Required' : 'Optional'; | ||
const formattedDescription = padLeft(parameter.description, parameter.name); | ||
console.log(` ${parameter.name}${formattedDescription} (${requiredStatus}, Default: ${parameter.defaultValue || 'None'})`); | ||
}); | ||
} | ||
|
||
if (options && options.length > 0) { | ||
console.log(` ${chalk.cyan('Options: ')}`); | ||
options.forEach(option => { | ||
const formattedDescription = padLeft(option.description, option.name); | ||
console.log(` ${option.name}${formattedDescription}`); | ||
}); | ||
} | ||
|
||
console.log(); | ||
}); | ||
} | ||
|
||
module.exports = helpCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters