A lightweight lib that makes more easier to create a CLI (Command Line Interface), with your own commands and it custom params, that can be easily validated too.
You just need to register the commands that your application will have and configure the validators of the params, if it have.
For example:
import CLI from 'lil-cli';
// This path will be optimized in a next version
import CLIEvents from 'lil-cli/dist/events';
// Initialize the CLI class
const cli = new CLI();
// Create command config
const config = {
description: 'Send a message',
model: [
{
name: 'say',
join: true
}
]
}
// If you want, you can register an event, for any purpose.
// CLIEvents.on('onTriggerCommand', () => {
// console.log('An command was triggered.')
// });
// Register command
cli.registerCommand('say', config, (err, params) => {
// Emitting an event
// CLIEvents.emit('onTriggerCommand')
console.log(params.message);
});
cli.listen();
If you're using npm, run in your project:
npm install lil-cli
or if you're using yarn:
yarn add lil-cli
cd ./examples
npm install
// choose one of examples, ex:
npm run start-password-generator