mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2024-12-22 13:22:11 +01:00
Add the raw option
This commit is contained in:
parent
12948c4d66
commit
e8b643a718
2 changed files with 31 additions and 19 deletions
|
@ -39,6 +39,7 @@ var recordOpt = new Clp.Option(["record"], "Records a new commit. Don't use this
|
|||
, dataPathOpt = new Clp.Option(["d", "data"], "Sets a custom data store file.", "path", GitStats.config.path)
|
||||
, globalActivityOpt = new Clp.Option(["g", "global-activity"], "Shows global activity calendar in the current repository.")
|
||||
, firstDayOpt = new Clp.Option(["f", "first-day"], "Sets the first day of the week.", "day", GitStats.config.first_day)
|
||||
, rawOpt = new Clp.Option(["r", "raw"], "Outputs a dump of the raw JSON data.")
|
||||
, parser = new Clp({
|
||||
name: "Git Stats"
|
||||
, version: Package.version
|
||||
|
@ -102,6 +103,7 @@ if (recordOpt.is_provided) {
|
|||
options = {
|
||||
start: sinceDateOpt.value ? Moment(sinceDateOpt.value) : Moment().subtract(1, "years")
|
||||
, end: untilDateOpt.value ? Moment(untilDateOpt.value) : Moment()
|
||||
, raw: rawOpt.is_provided
|
||||
};
|
||||
|
||||
// Validate the dates
|
||||
|
@ -153,5 +155,6 @@ if (globalActivityOpt.is_provided) {
|
|||
return GitStats.globalActivity(options, display);
|
||||
}
|
||||
|
||||
|
||||
// Show the graphs
|
||||
GitStats[authorsOpt.is_provided ? "authorsPie" : "ansiCalendar"](options, display);
|
||||
|
|
47
lib/index.js
47
lib/index.js
|
@ -459,34 +459,38 @@ GitStats.prototype.calendar = function (data, callback) {
|
|||
*
|
||||
* @name ansiCalendar
|
||||
* @function
|
||||
* @param {Object} data The object passed to the `calendar` method.
|
||||
* @param {Object} options The object passed to the `calendar` method.
|
||||
* @param {Function} callback The callback function.
|
||||
* @return {GitStats} The `GitStats` instance.
|
||||
*/
|
||||
GitStats.prototype.ansiCalendar = function (data, callback) {
|
||||
GitStats.prototype.ansiCalendar = function (options, callback) {
|
||||
|
||||
if (typeof data === "function") {
|
||||
callback = data;
|
||||
data = undefined;
|
||||
if (typeof options === "function") {
|
||||
callback = options;
|
||||
options = undefined;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
self.graph(data, function (err, graph) {
|
||||
var cal = [];
|
||||
self.graph(options, function (err, graph) {
|
||||
var cal = []
|
||||
, data = {
|
||||
theme: options.theme
|
||||
, start: options.start
|
||||
, end: options.end
|
||||
, firstDay: options.firstDay
|
||||
, cal: cal
|
||||
}
|
||||
;
|
||||
|
||||
self.iterateDays(data, function (cDay) {
|
||||
self.iterateDays(options, function (cDay) {
|
||||
cDayObj = graph[cDay];
|
||||
if (!cDayObj) { return; }
|
||||
cal.push([cDay, cDayObj.c]);
|
||||
});
|
||||
|
||||
callback(null, CliGhCal(cal, {
|
||||
theme: data.theme
|
||||
, start: data.start
|
||||
, end: data.end
|
||||
, firstDay: data.firstDay
|
||||
}));
|
||||
|
||||
callback(null, options.raw ? data : CliGhCal(cal, data));
|
||||
});
|
||||
|
||||
return self;
|
||||
|
@ -535,6 +539,7 @@ GitStats.prototype.authors = function (options, callback) {
|
|||
* - `repo` (String): The repository path.
|
||||
* - `radius` (Number): The pie radius.
|
||||
* - `no_ansi` (Boolean): If `true`, the pie will not contain ansi characters.
|
||||
* - `raw` (Boolean): If `true`, the raw JSON will be displayed.
|
||||
*
|
||||
* @param {Function} callback The callback function.
|
||||
* @return {GitStats} The `GitStats` instance.
|
||||
|
@ -574,13 +579,14 @@ GitStats.prototype.authorsPie = function (options, callback) {
|
|||
authors.push(others);
|
||||
}
|
||||
|
||||
pie = new CliPie(options.radius, authors, {
|
||||
var data = {
|
||||
legend: true
|
||||
, flat: true
|
||||
, no_ansi: options.no_ansi
|
||||
});
|
||||
, authors: authors
|
||||
};
|
||||
|
||||
callback(null, pie.toString());
|
||||
callback(null, options.raw ? data : new CliPie(options.radius, authors, data).toString());
|
||||
});
|
||||
|
||||
return self;
|
||||
|
@ -598,6 +604,7 @@ GitStats.prototype.authorsPie = function (options, callback) {
|
|||
* - `start` (String): The start date.
|
||||
* - `end` (String): The end date.
|
||||
* - `theme` (String|Object): The calendar theme.
|
||||
* - `raw` (Boolean): If `true`, the raw JSON will be displayed.
|
||||
*
|
||||
* @param {Function} callback The callback function.
|
||||
* @return {GitStats} The `GitStats` instance.
|
||||
|
@ -632,11 +639,13 @@ GitStats.prototype.globalActivity = function (options, callback) {
|
|||
Object.keys(commits).forEach(function (c) {
|
||||
cal.push([c, commits[c]])
|
||||
});
|
||||
callback(null, CliGhCal(cal, {
|
||||
var data = {
|
||||
theme: options.theme
|
||||
, start: options.start
|
||||
, end: options.end
|
||||
}));
|
||||
, cal: cal
|
||||
};
|
||||
callback(null, options.raw ? data : CliGhCal(cal, data));
|
||||
});
|
||||
|
||||
return this;
|
||||
|
|
Loading…
Reference in a new issue