A multicommand CLI helper that uses yargs and inquirer.
npm i @kuscamara/cli-helper
CliHelper
creates CLIs from the specified commands object and uses yargs for command options and inquirer to prompt for missing params not passed as flags / options.
const { CliHelper } = require('@kuscamara/cli-helper');
const cli = new CliHelper({ options });
description
(string
): Main command description.defaultCommandMessage
(string
): Prompt message of the default command. Default "Choose a command".commands
(object
): CLI commands. Accepts anaction
key (function
) for each command that will receive the executed command and the command options asoptions
object. Theparams
property uses the same options that inquirer questions.
Full example
const { CliHelper } = require('@kuscamara/cli-helper');
const cli = new CliHelper({
description: 'My awesome CLI',
commands: {
'print': {
desc: 'Prints something',
params: {
color: {
message: 'Use colors in output',
type: 'boolean'
}
},
action: ({ command, options }) => {
console.log(`${command} executed with ${options.color}`);
}
},
'greet': {
desc: 'Says hello',
params: {
name: {
message: 'Name',
type: 'string'
}
},
action: ({ options }) => {
console.log(`Hello ${options.name}!`);
}
}
}
});
cli.run();
const { CliHelper } = require('@kuscamara/cli-helper');
const { PathPrompt } = require('inquirer-path');
CliHelper.registerPrompt('path', PathPrompt);
const cli = new CliHelper(options);
cli.run();
This project is licensed under the MIT License.