Package Exports
- @maartennnn/cli-builder
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@maartennnn/cli-builder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Installing
npm install cli-builderTake a look at bin/example-cli.js
Instantiate CLI with new CliInterface({ ...options }, commands)
options.command- Type:stringCommand to put in logsoptions.enableInteractive- Type:booleanAllow interactive modeoptions.beforeLoad- Type:PromiseFunction to execute before initializationoptions.afterLoad- Type:PromiseFunction to execute after initializationoptions.helpHeader- Type:stringHeader to show in helpoptions.helpFooter- Type:stringFooter to show in help
commands example
// DO NOT ADD HELP TO THE ROOT OBJECT.
const commands = {
test: {
execute: () => console.log('this is the test run'),
help: () => console.log('help of test'),
testing: {
execute: () => console.log('executing testing'),
help: () => console.log('testing help'),
},
testing2: {
execute: () => console.log('executing testing2'),
help: () => console.log('testing2 help'),
},
},
test2: {
execute: () => console.log('this is the test2 run'),
help: () => console.log('help of test2'),
},
deep: {
nesting: {
works: {
as: {
// Without help
command: () => console.log('to run this type `deep nesting works as command`')
// Or with help
command: {
// this get executed as `deep nesting works as command`
execute: () => console.log('to run this type `deep nesting works as command`'),
// this get executed as `deep nesting works as command help`
help: () => console.log('help of command')
}
}
}
}
},
runSomeFunction: async () => {
// DO SOME INSANE LOGIC HERE
}
}Help is executed on the object. Eg. in this case executing test help will reveal help of test and all child help functions (this case testing.help() and testing2.help())
Running a command is in a nesting way: deep nesting works as command for the example above (executes execute function case it's an object).
deep nesting works as command help (executes help function in case it's an object)
functions are added as camelCase but inside the command line you'll need to use kebab-case:
run-some-function will call function runSomeFunction.