Changed handling of parameters (allowing any order)

This commit is contained in:
Fabian Furger 2015-05-03 20:26:26 +01:00
parent 3a899b3184
commit 4d1de322fa

View file

@ -32,19 +32,33 @@ switch (process.argv[2]) {
console.log(require("../package.json").version); console.log(require("../package.json").version);
break; break;
default: default:
var options = {}; var options = {
theme: "DARK"
},
parameter,
i;
if (process.argv.length !== 2) { // iterate over all parameters and assign them in options object
if (process.argv[2]) { for (i = 2; i < process.argv.length; i++) {
options.start = Moment(process.argv[2]); 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 (process.argv[3]) { if (options.start) {
options.end = Moment(process.argv[3]); 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");
} }
@ -55,9 +69,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);