Package Exports
- command-line-args
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (command-line-args) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
command-line-args
A mature, feature-complete library to parse command-line options.
If your app requires a git-like command interface, consider using command-line-commands.
Synopsis
You can set options using the main notation standards (learn more). These commands are all equivalent, setting the same values:
$ example --verbose --timeout=1000 --src one.js --src two.js
$ example --verbose --timeout 1000 --src one.js two.js
$ example -vt 1000 --src one.js two.js
$ example -vt 1000 one.js two.js
To access the values, first create a list of option definitions describing your accepted options. The type
property is a setter function (the value supplied is passed through this), giving you full control over the value received.
const optionDefinitions = [
{ name: 'verbose', alias: 'v', type: Boolean },
{ name: 'src', type: String, multiple: true, defaultOption: true },
{ name: 'timeout', alias: 't', type: Number }
]
Next, parse the options using commandLineArgs():
const commandLineArgs = require('command-line-args')
const options = commandLineArgs(optionDefinitions)
options
now looks like this:
{
files: [
'one.js',
'two.js'
],
verbose: true,
timeout: 1000
}
Usage guide generation
A usage guide (typically printed when --help
is set) can be generated using command-line-usage. See the examples below and read the documentation for instructions how to create them.
A typical usage guide example.
The polymer-cli usage guide is a good real-life example.
Further Reading
There is plenty more to learn, please see the wiki for further examples and documentation.
Install
$ npm install command-line-args --save
© 2014-18 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.