In Commander if the CLI is ran without specifying a command I get something like:
Options:
-h, --help display help for command
Commands:
foo [options] Foo
bar [options] Bar
help [command] display help for command
but if I run the CLI as:
app foo
I'd like to return all available options for that sole command.
Code
const foo = () => {
program
.command('foo')
.description('This is a foo')
.option('-a, --alpha [string]', 'Show Alpha', false)
.option('-b, --beta [string]', 'Show Beta', false)
.action(async options => {
clear()
try {
const { alpha, beta } = options
if (alpha === false && beta === false) return program.help()
} catch (e) {
console.log(chalk.red('Error: '), chalk.white(e.message))
return process.exit(1)
}
})
}
export default foo
However program.help()
doesn't specify the command's options but shows the output like in the first example.
Research
- Get multiple command option using commander
- Commander.js display help when called with no commands
- NodeJS, Commander - How to identify if user has passed un-supported option
- How to provide options across many commands with node.js commander
- Commander.js - Implementing sub commands that executes when the previous one is finished
- How to process options before commands in commander.js?
- Node.js commander with optional+variadic arguments
In Commander how to return options
for a command if no option
is passed?