Package Exports
- make-cli
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 (make-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
make-cli
Build command line tools declaratively with a configuration object and a single function call. Based on Commander.js.
Install
# npm
$ npm install make-cli
# Yarn
$ yarn add make-cli
Usage
First the CLI has to be implemented:
#!/usr/bin/env node
const makeCli = require('make-cli')
makeCli({
version: '0.1.0',
name: 'my-cli',
usage: 'Usage description here',
arguments: '<remote> [extra]',
options: [
{
name: '-y, --yes',
description: 'Skip questions',
},
{
name: '--value <value>',
description: 'Specifies the value',
defaultValue: 'foo',
choices: ['foo', 'bar'],
},
],
action: (remote, extra, options) => {
// options.value and options.yes
// contain the options.
},
})
// It is also possible to define sub-commands
makeCli({
commands: [
{
name: 'push',
description: 'Pushes to the repo',
arguments: '<remote>',
options: [
{
name: '-y, --yes',
},
],
action: (remote, options) => { /* push the stuff */ },
},
{
name: 'pull',
// ...
},
],
})
Then it can be called like so:
$ my-cli push origin --yes
$ my-cli pull origin
$ my-cli --help
$ my-cli --version
You can also allow to pass unknown options and those are then available in the action like so:
#!/usr/bin/env node
const makeCli = require('make-cli')
makeCli({
// ...
allowUnknownOption: true,
options: [
{
name: '-y, --yes',
description: 'Skip questions',
},
],
action: (options, command) => {
// options.yes = true
// command.args = ['--foo']
},
})
If you now run my-cli --yes --foo
, command.args
will contain ['--foo']
.
Contribute
Are you missing something or want to contribute? Feel free to file an issue or a pull request! ⚙️
Support
Hey, I am Sebastian Landwehr, a freelance web developer, and I love developing web apps and open source packages. If you want to support me so that I can keep packages up to date and build more helpful tools, you can donate here:
If you want to send me a one time donation. The coffee is pretty good 😊.
Also for one time donations if you like PayPal.
Here you can support me regularly, which is great so I can steadily work on projects.
Thanks a lot for your support! ❤️