@kuscamara/cli-helper
v1.0.5
Published
A multicommand CLI helper that uses yargs for command options and inquirer for prompt
Downloads
3
Maintainers
Readme
CliHelper
A multicommand CLI helper that uses yargs and inquirer.
Install
npm i @kuscamara/cli-helper
Usage
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 });
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();
Registering custom prompt types
const { CliHelper } = require('@kuscamara/cli-helper');
const { PathPrompt } = require('inquirer-path');
CliHelper.registerPrompt('path', PathPrompt);
const cli = new CliHelper(options);
cli.run();
License
This project is licensed under the MIT License.