Skip to content

Commit fcf91a3

Browse files
committed
Merge branch 'furgerf-small-fixes'
2 parents c941e03 + 049b8b7 commit fcf91a3

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

bin/git-stats

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,48 @@ Moment.suppressDeprecationWarnings = true;
1818
switch (process.argv[2]) {
1919
case "--record":
2020
var data = process.argv[3].replace(/^\"|\"$/g, "");
21-
try {
22-
data = JSON.parse(data);
23-
} catch (e) {
24-
throw e;
25-
}
21+
data = JSON.parse(data);
22+
2623
GitStats.record(data, function (err) {
2724
if (err) { return Logger.log(err, "error"); }
2825
});
2926
break;
3027
case "--help":
28+
case "-h":
3129
console.log(Fs.readFileSync(__dirname + "/docs/help", "utf-8"));
3230
break;
3331
case "-v":
3432
console.log(require("../package.json").version);
3533
break;
3634
default:
37-
var options = {};
38-
39-
if (process.argv.length !== 2) {
40-
if (process.argv[2]) {
41-
options.start = Moment(process.argv[2]);
42-
35+
var options = {
36+
theme: "DARK"
4337
}
38+
, parameter
39+
, i
40+
;
4441

45-
if (process.argv[3]) {
46-
options.end = Moment(process.argv[3]);
42+
// iterate over all parameters and assign them in options object
43+
for (i = 2; i < process.argv.length; i++) {
44+
parameter = process.argv[i];
45+
// does the parameter represent a date?
46+
if (Moment(parameter).isValid()) {
47+
// the date is end date if start date is set
48+
if (options.start) {
49+
options.end = Moment(parameter);
50+
} else {
51+
options.start = Moment(parameter);
52+
}
53+
} else if (parameter == "--light") {
54+
// change theme
55+
options.theme = "LIGHT";
56+
} else if (parameter == "--no-ansi") {
57+
// request no-ansi
58+
options.noansi = true;
4759
}
4860
}
4961

62+
5063
if (!options.start || !options.start.isValid()) {
5164
options.start = Moment().subtract(1, "years");
5265
}
@@ -57,9 +70,10 @@ switch (process.argv[2]) {
5770

5871
GitStats.ansiCalendar(options, function (err, data) {
5972
if (err) { return Logger.log(err, "error"); }
73+
6074
data = AnsiParser.removeAnsi(data);
61-
if (process.argv.indexOf("--no-ansi") === -1) {
62-
data = GitStatsColors(data, process.argv.indexOf("--light") !== -1 ? "LIGHT": "DARK");
75+
if (!options.noansi) {
76+
data = GitStatsColors(data, options.theme);
6377
}
6478

6579
console.log(err || data);

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"author": "Ionică Bizău <[email protected]>",
1313
"contributors": [
1414
15-
"William Boman <[email protected]>"
15+
"William Boman <[email protected]>",
16+
"Fabian Furger <[email protected]>"
1617
],
1718
"license": "MIT",
1819
"devDependencies": {},
@@ -38,4 +39,4 @@
3839
"moment": "^2.9.0",
3940
"ul": "^1.1.0"
4041
}
41-
}
42+
}

0 commit comments

Comments
 (0)