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);
break;
default:
var options = {};
if (process.argv.length !== 2) {
if (process.argv[2]) {
options.start = Moment(process.argv[2]);
var options = {
theme: "DARK"
},
parameter,
i;
// iterate over all parameters and assign them in options object
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);
}
if (process.argv[3]) {
options.end = Moment(process.argv[3]);
} 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()) {
options.start = Moment().subtract(1, "years");
}
@ -55,9 +69,10 @@ switch (process.argv[2]) {
GitStats.ansiCalendar(options, function (err, data) {
if (err) { return Logger.log(err, "error"); }
data = AnsiParser.removeAnsi(data);
if (process.argv.indexOf("--no-ansi") === -1) {
data = GitStatsColors(data, process.argv.indexOf("--light") !== -1 ? "LIGHT": "DARK");
if (!options.noansi) {
data = GitStatsColors(data, options.theme);
}
console.log(err || data);