argchecker
A command line options parser for Node.js.
Installation
$ npm install argchecker
Usage
#!/usr/bin/env node var ac = ; // When invalid arg comes from command line, this script shows the usage information, and exit here. var log = ac; // get '-l' option's param var arg1 = ac; // get non option argsvar arg2 = ac; // if ac // check '-a' option // ...
Example
in command line
$ app2 -a -l log1.txt XXX YYY
app2
#!/usr/bin/env node var ac = ; var log = ac; // log1.txt var arg1 = ac; // XXXvar arg2 = ac; // YYY if ac // true // ...
Tags
repeat
in command line
app3 -a -l log1.txt XXX1 XXX2 XXX3 YYY
app3
#!/usr/bin/env node var ac = ; var arg1 = ac; // [XXX1, XXX2, XXX3]var arg2 = ac; // YYY
repeat (for option)
in command line
$ app4 -b 10 -b 20 -b 30 XXX
app4
#!/usr/bin/env node var ac = ; var b = ac; // [10, 20, 30] var arg1 = ac; // XXXvar arg2 = ac; // undefined
must
in command line
$ app5 -b 10 YYY
app5
#!/usr/bin/env node var ac = ; var b = ac; // 10 var arg1 = ac; // undefined <-- skipedvar arg2 = ac; // YYY <-- must
Other tags
param (for option)
You have to set this tag, when an option has a next parameter.
var ac = ;
default (for option)
This tag can be set when the "param" tag exists.
var ac = ;
solo (for option)
If 'solo' tag's option comes, all other 'must' tags are not checked.
var ac = ;
name (top level only)
"name" is used in the usage information.
var ac = ;
in stderr message
Usage: app_name [-b B_PARAM]
exit (top level only)
The status code at the time of an error. Default: 1
var ac = ;
License
The MIT License