This is a vorpal wrapper. It provides a way to dynamically configure your commands with the help of simple yaml files.
It's main feature is to integration with the third party library functions, inside command executing function i.e. inside action.
Its work in progress, I am yet to integrate all possible vorpal options via YAML config.
To install it via npm
npm install dynamic_cli_creator
Another way is to mention it in package.json shown below
"dependencies": {
"dynamic_cli_creator" : "git://github.com/bmhaskar/DynamicCLI.git#master"
}
Import it via ES6 syntax like
import DynamicCLI from 'dynamic_cli_creator';
To create CLI, create an instance of imported class i.e. DynamicCLI with props having following interface
export interface cliPropsExtensionsInterface {
[index:string]:{"extFunc":Function, options:Object}
}
export interface cliPropsInterface {
cliName?:string;
pathToCommandFiles?:string;
extensions?:cliPropsExtensionsInterface;
}
For example
//I am using typescript in example, it does not restrict use of library
//to typescript, it also can be used with ES6/ES5
const simulatorOptions = <cliPropsInterface> {
cliName: "dataSimulator",
pathToCommandFiles: path.resolve(__dirname , 'commands'),
extensions: {"dataGenerator": { "extFunc": dataGenerator, options: {name: "commentsGenerator"}}}
} ;
const dataSimulator = new DynamicCLI(simulatorOptions);
For YAML command syntax checkout the example/commands/command.yml
The interface of YAML config is as follows
export interface vorpalCommandConfigInterface {
command:commandInterface,
action:(args:Object, cb?:Function) => void | Promise<void>,
description?:string,
alias?:string,
autocomplete?:autoCompleteInterface,
option?:commandOptionsInterface | Array<commandOptionsInterface>,
types?:Object,
hidden?:boolean,
parse?:(command:string, args:Object) => string,
help?:(args:Object) => void
validate?:(args:Object) => boolean | string,
cancel?:() => void,
use?:any;
}
example for above is
command: 'foo <requiredArg> [optionalArg]'
option:
optionName: "-v"
description: "Option description"
description: 'Outputs "bar"'
alias: 'fooseball'
action: !!js/function >
function (args, cb) {
this.parent.generateData(args);
console.log( 'Wow! JS-YAML Rocks!', args);
cb();
}
help: "This is a dummy command just logs arguments you passed."
cancel: !!js/function >
function() {
console.log('Cancel function was called')
}
option
can be an array like
option:
-
optionName: "-o1"
description: "Option1 description"
-
optionName: "-o2"
description: "Option2 description"
This can be used when your porject need to do have Command Line Interface and you dont want to recode stuff you already have you can use this library to create a CLI and integrate your existing code/functions.
This library helps in quick bootstrapping of CLI. No need of writting the boilerplate for your commands, YAML configuration saves, writing code and testing the same.
When you create a new instance of DynamicCLI by writing
const dataSimulator = new DynamicCLI(options);
It accepts the [options](#how to use) overrides the defaults by the values provided.
It initialises vorpal with cliOptions.cliName as delimiter and vorpal-log extension.
Extensions provided via cliOptions.extensions are added to vorpal instance.
When you call start on the DynamicCLI instance as shown below.
dataSimulator.start()
The commands specified via yaml are added to vorpal and CLI is shown.
- Add how it works
- Create NPM package
- Add tests
- Add code coverage