-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
monteri
committed
Sep 7, 2023
1 parent
b8bdc7b
commit c3ca114
Showing
4 changed files
with
138 additions
and
8 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.keys(commands).forEach(command => { | ||
console.log(` ${chalk.green.bold(command)}`); | ||
if (commands[command].description) { | ||
console.log(` ${commands[command].description}`); | ||
} | ||
|
||
if (commands[command].parameters && commands[command].parameters.length > 0) { | ||
console.log(` ${chalk.cyan('Parameters: ')}`); | ||
commands[command].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 (commands[command].options && commands[command].options.length > 0) { | ||
console.log(` ${chalk.cyan('Options: ')}`); | ||
commands[command].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