Skip to content

Commit e8b643a

Browse files
committed
Add the raw option
1 parent 12948c4 commit e8b643a

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

bin/git-stats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var recordOpt = new Clp.Option(["record"], "Records a new commit. Don't use this
3939
, dataPathOpt = new Clp.Option(["d", "data"], "Sets a custom data store file.", "path", GitStats.config.path)
4040
, globalActivityOpt = new Clp.Option(["g", "global-activity"], "Shows global activity calendar in the current repository.")
4141
, firstDayOpt = new Clp.Option(["f", "first-day"], "Sets the first day of the week.", "day", GitStats.config.first_day)
42+
, rawOpt = new Clp.Option(["r", "raw"], "Outputs a dump of the raw JSON data.")
4243
, parser = new Clp({
4344
name: "Git Stats"
4445
, version: Package.version
@@ -102,6 +103,7 @@ if (recordOpt.is_provided) {
102103
options = {
103104
start: sinceDateOpt.value ? Moment(sinceDateOpt.value) : Moment().subtract(1, "years")
104105
, end: untilDateOpt.value ? Moment(untilDateOpt.value) : Moment()
106+
, raw: rawOpt.is_provided
105107
};
106108

107109
// Validate the dates
@@ -153,5 +155,6 @@ if (globalActivityOpt.is_provided) {
153155
return GitStats.globalActivity(options, display);
154156
}
155157

158+
156159
// Show the graphs
157160
GitStats[authorsOpt.is_provided ? "authorsPie" : "ansiCalendar"](options, display);

lib/index.js

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -459,34 +459,38 @@ GitStats.prototype.calendar = function (data, callback) {
459459
*
460460
* @name ansiCalendar
461461
* @function
462-
* @param {Object} data The object passed to the `calendar` method.
462+
* @param {Object} options The object passed to the `calendar` method.
463463
* @param {Function} callback The callback function.
464464
* @return {GitStats} The `GitStats` instance.
465465
*/
466-
GitStats.prototype.ansiCalendar = function (data, callback) {
466+
GitStats.prototype.ansiCalendar = function (options, callback) {
467467

468-
if (typeof data === "function") {
469-
callback = data;
470-
data = undefined;
468+
if (typeof options === "function") {
469+
callback = options;
470+
options = undefined;
471471
}
472472

473473
var self = this;
474474

475-
self.graph(data, function (err, graph) {
476-
var cal = [];
475+
self.graph(options, function (err, graph) {
476+
var cal = []
477+
, data = {
478+
theme: options.theme
479+
, start: options.start
480+
, end: options.end
481+
, firstDay: options.firstDay
482+
, cal: cal
483+
}
484+
;
477485

478-
self.iterateDays(data, function (cDay) {
486+
self.iterateDays(options, function (cDay) {
479487
cDayObj = graph[cDay];
480488
if (!cDayObj) { return; }
481489
cal.push([cDay, cDayObj.c]);
482490
});
483491

484-
callback(null, CliGhCal(cal, {
485-
theme: data.theme
486-
, start: data.start
487-
, end: data.end
488-
, firstDay: data.firstDay
489-
}));
492+
493+
callback(null, options.raw ? data : CliGhCal(cal, data));
490494
});
491495

492496
return self;
@@ -535,6 +539,7 @@ GitStats.prototype.authors = function (options, callback) {
535539
* - `repo` (String): The repository path.
536540
* - `radius` (Number): The pie radius.
537541
* - `no_ansi` (Boolean): If `true`, the pie will not contain ansi characters.
542+
* - `raw` (Boolean): If `true`, the raw JSON will be displayed.
538543
*
539544
* @param {Function} callback The callback function.
540545
* @return {GitStats} The `GitStats` instance.
@@ -574,13 +579,14 @@ GitStats.prototype.authorsPie = function (options, callback) {
574579
authors.push(others);
575580
}
576581

577-
pie = new CliPie(options.radius, authors, {
582+
var data = {
578583
legend: true
579584
, flat: true
580585
, no_ansi: options.no_ansi
581-
});
586+
, authors: authors
587+
};
582588

583-
callback(null, pie.toString());
589+
callback(null, options.raw ? data : new CliPie(options.radius, authors, data).toString());
584590
});
585591

586592
return self;
@@ -598,6 +604,7 @@ GitStats.prototype.authorsPie = function (options, callback) {
598604
* - `start` (String): The start date.
599605
* - `end` (String): The end date.
600606
* - `theme` (String|Object): The calendar theme.
607+
* - `raw` (Boolean): If `true`, the raw JSON will be displayed.
601608
*
602609
* @param {Function} callback The callback function.
603610
* @return {GitStats} The `GitStats` instance.
@@ -632,11 +639,13 @@ GitStats.prototype.globalActivity = function (options, callback) {
632639
Object.keys(commits).forEach(function (c) {
633640
cal.push([c, commits[c]])
634641
});
635-
callback(null, CliGhCal(cal, {
642+
var data = {
636643
theme: options.theme
637644
, start: options.start
638645
, end: options.end
639-
}));
646+
, cal: cal
647+
};
648+
callback(null, options.raw ? data : CliGhCal(cal, data));
640649
});
641650

642651
return this;

0 commit comments

Comments
 (0)