Probably the sole command line option parser you'll ever need to...
npm install optjs!opt.js
======
Probably the sole command line option parser you'll ever need to Ctrl+C, Ctrl+V. Proof:
npm install optjs
``js
`
function opt(argv) {
var opt={},arg,p;argv=Array.prototype.slice.call(argv||process.argv);for(var i=2;i
return {'node':argv[0],'script':argv[1],'argv':argv.slice(2),'opt':opt};
}
`
Usage
-----
js
`
var opt = require("optjs")();
console.log(opt.node); // Path to node executable
console.log(opt.script); // Path to the current script
console.log(opt.opt); // Command line options as a hash
console.log(opt.argv); // Remaining non-option arguments
node somescript.js foo -a=1 -b --c="hello world" bar ----d
Example
-------
`
js
`
// Result
opt.node == "/path/to/node[.exe]"
opt.script == "/path/to/somescript.js"
opt.opt == { a: 1, b: true, c: "hello world", d: true }
opt.argv == ["foo", "bar"]
`
Full-featured test suite
------------------------
js
``
#!/usr/bin/env node
console.log(require("./opt.js")());
License
-------
MIT