Home

Awesome

npm

help-version

Build Status Dependency Status

Anything you wanted to do with --help and --version:

Example

#!/usr/bin/env node

var Cli = require('help-version');

var cli = Cli('Usage:  my-cat [file]');

cli.version()
//=> "v0.1.0"

if (process.argv.length != 3) {
  // Show help and exit with code 1.
  cli.help(1);
}

fs.createReadStream(process.argv[2])
  .pipe(process.stdout);

Catches --help and --version automatically.

$ ./cat.js --help
Usage:  my-cat [file]
$ ./cat.js --version
v0.1.0
$ ./cat.js file.txt
contents of file.txt

API

cli = Cli(helpText, [opts])

Checks opts.argv for --help or --version.

  1. If --help is found, prints helpText to opts.stdout and calls opts.exit.

  2. If --version is found, prints app version (determined from the version field from your local package.json) to opts.stdout and calls opts.exit.

Returns object with two (bound) methods: cli.help([code], [stream]) and cli.version([code], [stream]).

OptionDefault
argvprocess.argv.slice(2)
exit([code])process.exit
stdoutprocess.stdout
stderrprocess.stderr

cli.help([code], [stream])

With no arguments, returns the help string.

With one or two arguments, writes it to stream instead and exits (via opts.exit) with code. stream defaults to opts.stdout if code==0 and opts.stderr otherwise.

cli.version([code], [stream])

With no arguments, returns the version string.

With one or two arguments, writes it to the stream instead and exits (via opts.exit) with code. stream defaults to opts.stdout if code==0 and opts.stderr otherwise.

Install

npm install help-version

License

MIT