Skip to content

Instantly share code, notes, and snippets.

@egoist
Last active June 29, 2017 14:54
Show Gist options
  • Save egoist/069d26e4b51ff984a7d80a471136d4ee to your computer and use it in GitHub Desktop.
Save egoist/069d26e4b51ff984a7d80a471136d4ee to your computer and use it in GitHub Desktop.
const cli = require('cac')
// call cli.option to add global options
cli.option({
name: 'cool',
desc: 'Make CLI cool again',
required: true,
type: String
})
cli.option({
name: 'wow,w',
desc: 'Say wow',
type: Boolean
})
cli.command({
name: 'build',
// Basically `cmd` == `cli` but with command context
// i.e. it only adds options to this command
builder: cmd => cmd.option({
name: 'production,p',
default: true,
desc: 'Minimize code'
}),
handler: (args, flags) => {
console.log(flags.p) // true
}
})
cli.parse(process.argv)
@egoist
Copy link
Author

egoist commented Jun 29, 2017

cli.option adds global option, cmd.option adds command option.

@egoist
Copy link
Author

egoist commented Jun 29, 2017

Would be great if the generated help message looks like this:

image

@egoist
Copy link
Author

egoist commented Jun 29, 2017

The debug logger could be very useful too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment