parsy
v0.1.2
Published
Tiny command line options parser for node.js in CoffeeScript.
Downloads
1
Readme
parsy
Tiny command line options parser for node.js in CoffeeScript.
Installation
$ npm install parsy
Usage
It automatically parse process.argv
so you just have to "subscribe" for the options you want.
Example
var parsy = require('parsy');
// register options
parsy
// no options passed
.on('', function () {
console.log('Enter option or -h for help');
})
// script -h
.on('-h', function (option, value) {
console.log('Hey give me some help here');
})
// script --file file1.js
.on('--file', function (option, value) {
// if no files passed show a message
if (!value) {
console.log('Usage: --file <file1.js file2.js>');
// simple check if the value passed to --file are js files
} else if (!/\.js$/.test(value)) {
console.log('Only .js files can be passed using the --file option!');
}
});
See parsy options object with all options passed
console.log(parsy.options);
// example
// { node: 'script.js', '-h': true, '--file': 'file1.js' }
License
See LICENSE.txt