In node-optimist, argv._ is an array of the "extra" parameters

In substack's node-optimist, you can use argv._ to fetch any parameters remaining after optimist has done its parsing.

For example (in CoffeeScript):

# file: example.coffee
optimist = require 'optimist'
options = {
  'help' : { description:'Show this message and exit.', boolean:true, alias:'h' }
}
argv = optimist.usage('Usage: $0 [--help]', options).argv

# Now argv._ contains an array "extra" parameters, if any
console.log argv._

For example

coffee example.coffee --help

yields

[ ]

but either of

coffee example.coffee --help foo.txt bar.png

or

coffee example.coffee foo.txt bar.png

yield

[ "foo.txt", "bar.png" ]
Published 3 Mar 2013

 

This page was generated at 4:16 PM on 26 Feb 2018.
Copyright © 1999 - 2018 Rodney Waldhoff.