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
work in progress, draft documentation
#command-line-args A command-line parser and usage-guide producer.. Particularly good at organising large sets of options.
##Install
$ npm install command-line-args --save
##Synopsis
the following app.js
...
var cliArgs = require("command-line-args");
/* define the command-line options */
var cli = cliArgs([
{ name: "verbose", type: Boolean, alias: "v", description: "Write plenty output" },
{ name: "help", type: Boolean, description: "Print usage instructions" },
{ name: "files", type: Array, defaultOption: true, description: "The input files" }
]);
/* parse the supplied command-line values */
var options = cli.parse();
/* generate a usage guide */
var usage = cli.usage({
header: "A synopsis application.",
footer: "For more information, visit http://example.com"
});
console.log(options.help ? usage : options);
...returns this output at the command line:
$ node app.js
{}
$ node app.js -v
{ verbose: true }
$ node app.js README.md package.json
{ files: [ 'README.md', 'package.json' ] }
$ node app.js README.md package.json -v
{ verbose: true, files: [ 'README.md', 'package.json' ] }
$ node app.js --help
A synopsis application.
Usage
-v, --verbose Write plenty output
--help Print usage instructions
--files <array> The input files
For more information, visit http://example.com
#API Reference Example
var cliArgs = require("command-line-args");
var cli = cliArgs([
{ name: "help", type: Boolean, alias: "h" },
{ name: "files", type: Array, defaultOption: true}
]);
var argv = cli.parse();
###new CliArgs(options)
A constructor function, taking your desired command-line option definitions as input, returning an instance of command-line-args
which you can parse()
or getUsage()
.
Params
- options Array.<OptionDefinition> - list of option definitions
###cli.parse([argv]) Returns a flat, or grouped object containing the values set at the command-line
Params
- [argv=process.argv]
object
- Optional argv array, pass to override the defaultprocess.argv
.
Returns: object
Example
Output from parse()
looks something like this:
{
delete: "thisfile.txt",
force: true
}
or, if the option definitions are grouped:
{
standard: {
delete: "thisfile.txt",
force: true
},
extra: {
intentions: "bad"
}
}
###cli.getUsage(options) Params
- options
object
- options for template- title
string
- a title - header
string
- a header - footer
string
- a footer - forms
array
- the invocation forms
- title
Returns: string
###type: cli~OptionDefinition
Defines an option
Scope: inner typedef of command-line-args
Type: object
documented by jsdoc-to-markdown.