nodejs-argv
Simple command line parsing nodejs module.
Installation
$ npm install nodejs-agrv
Usage
e.g.
const nodejs_argv = ;const argv = nodejs_argvargvtry argvcatch e consoleif argv consoleif argv consoleconsole
$ node test.js --help
$ node test.js -v
$ node test.js -u google.com --types png jpg gif -o ./download
e.g. Arguments is error!
$ node test.js --outdir ./download$ node test.js --limit abc
Nodejs-argv Module Methods
-
new(options, args)
arguments options and args is optional
Return a new nodejs-argv object
Nodejs-argv Object Methods
-
option(options)
Define options, argument like [[shot name, long name, type=default value, description]]
e.g.
argv// —url : limit type is string and can not be emptyargv// --limit: limit type is number and default value is 5argv// --types: limit type is array -
parse(args)
Parse command line arguments, args type is array. if not args, then parse process.argv
-
get(name)
Return command line arguments
-
help()
Return options description string
-
values()
Return all the arguments
-
pipe(callback, timeout = 500)
Receive stdin from the command line
argv$ ls ./ | node test.js -
version()
Return package.json.version in the require.main directory