new-command

Simplifying defining commands and options by combining minimist, show-help, show-version modules

Simplifies creating command-line programs by combining minimist, show-help, show-version modules.

Usage Examples: prova, bud, personal-api, ourtunes

$ npm install new-command

Define a command and options by calling new-command:

command = require('new-command')({ 'p': 'port', 'n': 'hostname' })
 
command.port
// => 8080 
 
command.hostname
// => foobar.com 
 
command._
// => ['rest', 'of the', 'arguments'] 

To define subcommands like git push npm publish etc, just pass subcommand names before options:

command = require('new-command')('install', 'publish', 'unpublish', { r: 'registry', s: 'save' })
 
command.install
// =>  
 
command.publish
// => true 
 
command.registry
// => 'localhost:3000' 

new-command will take care of --version (-v) and --help (-h) options for you, by calling show-version and show-help. So, if you call this command with -v parameter:

$ start-server --version
 
start-server v0.0.0

It reads your package name and version and outputs automatically. When user calls -h parameter:

$ start-server --help

It'll look for following paths in the project directory and will output the one it finds first:

  • docs/man
  • bin/help.txt
  • bin/usage.txt
  • help.txt
  • usage.txt
  • README
  • README.md
  • README.markdown