commandment

Commandline for node.js

Commandment

Commandline for node.js

npm install commandment
var Commandment = require('commandment')
  , commands = new Commandment({name: 'my-app', command_dir: __dirname + '/commands'});
 
commands.before_execute(function(contextnext) {
  context.hello_helper = function() {
    // You can call me from commands now 
    return 'hello world';
  };
});
 
commands.after_execute(function(contexterrnext) {
  if (err) return console.error(err.stack);
  context.log('Yay! Everything is fine');
  next();
});
 
commands.execute(process.argv);

Commands are just exported from files in the commands directory

exports.hello = function(callback) {
  this.log(this.hello_helper());
  callback()
};
 
// There can be multiple per file 
exports.hello_person = function(namecallback) {
  this.log('Hello ' + name);
  callback();
};

Copyright (c) 2013 Matt Insler
Licensed under the MIT license.