#short options
ls -a
ls -a -R
ls -aR
#long options
ls --all
ls --all --recursive
ls --version
#long options with values
ls --color=auto
npm install
npm update
npm remove
npm search
npm test
npm publish
npm version
npm install --help
npm install -g grunt
npm install -S grunt
npm install --global grunt
npm install --save grunt
npm install --save-dev grunt
# gzip multiple files
gzip file1 file2
# checksum multiple files
sum file1 file2 file3
# remove multiple directories
rmdir mydir yourdir deer
npm install --save commander
cli = require('commander');
cli.option('-v, --version', 'output the version number');
cli
.command('sort <list>')
.description('returns the list sorted')
.action(function (list) {
console.log(sort(list));
});
cli
.command('sort <list>')
.description('returns the list sorted')
.option("--direction [direction]", "Which order to sort by [asc | desc]")
.action(function (list) {
if (options.direction !== 'desc') {
console.log( sort(list, 'asc') );
} else {
console.log( sort(list, 'desc') );
}
});
cli
.command('sum <value> [moreValues...]')
.description('returns the sum of the values passed')
.action(function (value, moreValues) {
var result = parseInt(value, 10);
moreValues.forEach(function (value) {
result += parseInt(value, 10);
});
console.log(result);
});
{
"preferGlobal": true,
"bin": {
"clitools": "index.js"
}
}
#!/usr/bin/env node