Merge branch 'furgerf-small-fixes'

This commit is contained in:
Ionică Bizău 2015-05-05 16:56:41 +03:00
commit fcf91a32c3
2 changed files with 32 additions and 17 deletions

View file

@ -18,35 +18,48 @@ Moment.suppressDeprecationWarnings = true;
switch (process.argv[2]) { switch (process.argv[2]) {
case "--record": case "--record":
var data = process.argv[3].replace(/^\"|\"$/g, ""); var data = process.argv[3].replace(/^\"|\"$/g, "");
try { data = JSON.parse(data);
data = JSON.parse(data);
} catch (e) {
throw e;
}
GitStats.record(data, function (err) { GitStats.record(data, function (err) {
if (err) { return Logger.log(err, "error"); } if (err) { return Logger.log(err, "error"); }
}); });
break; break;
case "--help": case "--help":
case "-h":
console.log(Fs.readFileSync(__dirname + "/docs/help", "utf-8")); console.log(Fs.readFileSync(__dirname + "/docs/help", "utf-8"));
break; break;
case "-v": case "-v":
console.log(require("../package.json").version); console.log(require("../package.json").version);
break; break;
default: default:
var options = {}; var options = {
theme: "DARK"
if (process.argv.length !== 2) {
if (process.argv[2]) {
options.start = Moment(process.argv[2]);
} }
, parameter
, i
;
if (process.argv[3]) { // iterate over all parameters and assign them in options object
options.end = Moment(process.argv[3]); for (i = 2; i < process.argv.length; i++) {
parameter = process.argv[i];
// does the parameter represent a date?
if (Moment(parameter).isValid()) {
// the date is end date if start date is set
if (options.start) {
options.end = Moment(parameter);
} else {
options.start = Moment(parameter);
}
} else if (parameter == "--light") {
// change theme
options.theme = "LIGHT";
} else if (parameter == "--no-ansi") {
// request no-ansi
options.noansi = true;
} }
} }
if (!options.start || !options.start.isValid()) { if (!options.start || !options.start.isValid()) {
options.start = Moment().subtract(1, "years"); options.start = Moment().subtract(1, "years");
} }
@ -57,9 +70,10 @@ switch (process.argv[2]) {
GitStats.ansiCalendar(options, function (err, data) { GitStats.ansiCalendar(options, function (err, data) {
if (err) { return Logger.log(err, "error"); } if (err) { return Logger.log(err, "error"); }
data = AnsiParser.removeAnsi(data); data = AnsiParser.removeAnsi(data);
if (process.argv.indexOf("--no-ansi") === -1) { if (!options.noansi) {
data = GitStatsColors(data, process.argv.indexOf("--light") !== -1 ? "LIGHT": "DARK"); data = GitStatsColors(data, options.theme);
} }
console.log(err || data); console.log(err || data);

View file

@ -12,7 +12,8 @@
"author": "Ionică Bizău <bizauionica@gmail.com>", "author": "Ionică Bizău <bizauionica@gmail.com>",
"contributors": [ "contributors": [
"Gnab <as0n@gnab.fr>", "Gnab <as0n@gnab.fr>",
"William Boman <william@redwill.se>" "William Boman <william@redwill.se>",
"Fabian Furger <mystyfly@gmail.com>"
], ],
"license": "MIT", "license": "MIT",
"devDependencies": {}, "devDependencies": {},