Commandline Parser
CommandParser is a simple tool for parsing our commandline arguments, and printing help text for them.
Installation
npm install commandline-parser
Usage
Registering arguments
var CommandLine = Parser parser = name : "command" desc : 'Description' extra : 'Extra text' ; //simplest formparser; //with all argumentsparser;
Printing help text
parser; /* Help for command Description --foo assign a value to foo -h, --help help -b, --bar assign a value to bar Extra text*/
Also note, that the parser already pre-registers the -h
and --help
commands for the printHelp
method
Parsing arguments
//for the following command://$: Command --foo='a' -b a.js b.js parser;//aparser;//trueparser;//['a.js','b.js'] //If we want to test which required arguments are missing we can useparser;//returns an array of missing parameters
Registering actions
You can use the parser to route arguments to functions:
parser; parser;//will execute all actions that have values assigned to them
Full constructor options:
parser name : "command" desc : 'Description' extra : 'Extra text' arguments : foo : flags : 'f' optional : false desc : 'description of command' {} ;
An example of all possible argument assignments
$: cmd -a -bcd -e aaa -fgh bbb --foo --bar=ccc ddd eee /*a:trueb:truec:truee:"aaa"f:trueg:trueh:"bbb"foo:tuebar:cccgetArguments:["ddd","eee"]*/