The running node process from running a subcommand executable
Allow unknown options on the command line.
if false
, error will be thrown if unknown option passed. Defaults to false
for unknown options.
Define argument syntax for the top-level command.
Add command name
.
The action callback is invoked when the
command name
is specified via ARGV,
and the remaining arguments are applied to the
function for access.
When the name
is "*" an un-matched command
will be passed as the first arg, followed by
the rest of ARGV remaining.
Examples:
const prog = program()
.version('0.0.1')
.option('-C, --chdir <path>', 'change the working directory')
.option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
.option('-T, --no-tests', 'ignore test hook')
prog
.command('setup')
.description('run remote setup commands')
.action(() => {
console.log('setup');
});
prog
.command('exec <cmd>')
.description('run the given remote command')
.action((cmd) => {
console.log('exec "%s"', cmd);
});
prog
.command('teardown <dir> [otherDirs...]')
.description('run teardown commands')
.action((dir, otherDirs) => {
console.log('dir "%s"', dir);
if (otherDirs) {
otherDirs.forEach((oDir) => {
console.log('dir "%s"', oDir);
});
}
});
prog
.command('*')
.description('deploy the given env')
.action((env) => {
console.log('deploying "%s"', env);
});
prog.init();
Command the new command
Define completion rules which will later be used by autocomplete to generate appropriate response
program()
.arguments('<a> <b>')
.option('--verbose', 'verbose')
.option('-n, --name <name>', 'specify name')
.option('--description <desc>', 'specify description')
.complete({
options: {
'--name': (typedArgs) => ['kate', 'jim'],
'--description': ['desc1', 'desc2']
},
arguments: {
a: (typedArgs) => ['a-1', 'a-2'],
b: ['b-1', 'b-2']
}
});
Get the value of an option
The name of the option you want to get
the value of the requested option
Output help information and exit with code 0
Parse argv
, settings options and invoking commands when defined.
Arguments to argv
come in the following form:
['/path/to/node', '/path/to/command', 'help']
The second argument is the path to the command. This is usually the entrypoint
of your dark
cli app.
The third argument is the name of the subcommand you want to call.
the argments to parse and send to your cli app
Command for chaining
Define option with flags
, description
and optional
coercion fn
.
The flags
string should contain both the short and long flags,
separated by comma, a pipe or space. The following are all valid
all will output this way when --help
is used.
Examples:
// simple boolean defaulting to false
program.option('-p, --pepper', 'add pepper');
// --pepper
program.pepper
// => Boolean
// simple boolean defaulting to true
program.option('-C, --no-cheese', 'remove cheese');
program.cheese
// => true
// --no-cheese
program.cheese
// => false
// required argument
program.option('-C, --chdir <path>', 'change the working directory');
// --chdir /tmp
program.chdir
// => "/tmp"
// optional argument
program.option('-c, --cheese [type]', 'add cheese [marble]');
Command for chaining
Get an object containing options as key-value pairs
an object containing options as key-value pairs
Output help information for this command
Generated using TypeDoc
A command builder