Probably the sole command line option parser you'll ever need to Ctrl+C, Ctrl+V. Proof:npm install optjs
{ var opt={}argp;argv=Arrayprototypeslice;forvar i=2;i<argvlength;i++ifargvi=='-' p=arg=""+argv>0?optarg=arg:optarg=true; return 'node':argv0'script':argv1'argv':argv'opt':opt;}
Usage
var opt = ;console; // Path to node executableconsole; // Path to the current scriptconsole; // Command line options as a hashconsole; // Remaining non-option arguments
Example
node somescript.js foo -a=1 -b --c="hello world" bar ----d
// Resultoptnode == "/path/to/node[.exe]"optscript == "/path/to/somescript.js"optopt == a: 1 b: true c: "hello world" d: true optargv == "foo" "bar"
Full-featured test suite
#!/usr/bin/env nodeconsole;
License
MIT