1.4.0 • Published 1 year ago

commander-extras v1.4.0

Weekly downloads
6
License
MIT
Repository
github
Last release
1 year ago

Commander-Extras

Extremely small utility which adds additional functionality to the Commander NPM module.

// Using the global prototype mutate method
var commander = require('commander');
require('commander-extras');

var program = commander.option('-v, --verbose', 'Be verbose')
	.env('FOO', 'FOO Environment variable desription')
	.env('BAR', 'BAR Environment variable desription')
	.env('BAZ', 'FOO environment variable desription')
	.note('Note one')
	.note('Note two')
	.note('Note three')
	.parse(process.argv)
	.opts()
// Using the global prototype mutate method
var Commander = require('commander');
var commanderExtras = require('commander-extras');

var command = new Commander.Command();
var commander = commanderExtras(command); // Mutate only our custom command

var program = commander.option('-v, --verbose', 'Be verbose')
	.env('FOO', 'FOO Environment variable desription')
	.env('BAR', 'BAR Environment variable desription')
	.env('BAZ', 'FOO environment variable desription')
	.note('Note one')
	.note('Note two')
	.note('Note three')
	.parse(process.argv)
	.opts()

API

The following API's are added to the existing Commander prototype:

CommanderExtras(Command?)

Take an optional Commander.Command instance and add the custom methods to it.

env(name, description)

Used to define an environment variable.

example(cli, title)

Used to define an example with an optional title.

extend(function)

Run a function with the current commander context to extend it. This is useful to extend sub-commands with common settings. The function is called as (commanderContext) and has the same as its context.

note(description)

Add an additional note to display at the bottom of the help output.