mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2024-12-22 05:12:11 +01:00
Changed handling of parameters (allowing any order)
This commit is contained in:
parent
3a899b3184
commit
4d1de322fa
1 changed files with 26 additions and 11 deletions
|
@ -32,19 +32,33 @@ switch (process.argv[2]) {
|
|||
console.log(require("../package.json").version);
|
||||
break;
|
||||
default:
|
||||
var options = {};
|
||||
var options = {
|
||||
theme: "DARK"
|
||||
},
|
||||
parameter,
|
||||
i;
|
||||
|
||||
if (process.argv.length !== 2) {
|
||||
if (process.argv[2]) {
|
||||
options.start = Moment(process.argv[2]);
|
||||
|
||||
}
|
||||
|
||||
if (process.argv[3]) {
|
||||
options.end = Moment(process.argv[3]);
|
||||
// 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);
|
||||
}
|
||||
} 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);
|
||||
|
|
Loading…
Reference in a new issue