patriot
Version:
Patriot command-line interface and node.js library.
62 lines (54 loc) • 1.63 kB
JavaScript
/**
* Base Command.
*
* > All your base are belong to us.
*
* All commands should inherit from the base `Command` object.
*
* This object handles the dependency injection of the `patriot` object.
*
* This has two major benefits:
* 1. Allows `Patriot` to create instances. This is helpful for testing.
* 2. Allows test framework to mock public interfaces during tests.
*
* Options:
*
* - `patriot` {Object} is the instance of `Patriot` for this command.
*
* Returns:
*
* {Function} that will call the inheriting class' `run` function.
*/
function Command(patriot) {
this.patriot = patriot;
var self = this;
return function() {
return self.run.apply(self, arguments);
};
}
Date.prototype.format = function(format) //author: meizz
{
var o = {
"M+" : this.getMonth()+1, //month
"d+" : this.getDate(), //day
"h+" : this.getHours(), //hour
"m+" : this.getMinutes(), //minute
"s+" : this.getSeconds(), //second
"q+" : Math.floor((this.getMonth()+3)/3), //quarter
"S" : this.getMilliseconds() //millisecond
}
if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
(this.getFullYear()+"").substr(4 - RegExp.$1.length));
for(var k in o)if(new RegExp("("+ k +")").test(format))
format = format.replace(RegExp.$1,
RegExp.$1.length==1 ? o[k] :
("00"+ o[k]).substr((""+ o[k]).length));
return format;
}
Command.prototype.run = function(options, callback) {
// subclasses should override this function
};
/*!
* Expose module.
*/
module.exports = Command;