-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
193 lines (175 loc) · 4.36 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#! /usr/bin/env node
let os = require('os');
let argv = require( 'argv' );
let whodid_config = require('./whodid-config.js')
let whodid_base = require('./whodid.js')
let whodid_author = require('./whodid-author.js')
let whodid_heavy = require('./whodid-heavy.js')
let whodid_file = require('./whodid-file.js')
let whodid_history = require('./whodid-history.js')
let whodid_debug = require('./whodid-debug.js')
let to_snake_case = require('lodash.snakecase')
argv.version('1.1.4');
function make_extra_option(options){
return [
{
name:"verbose",
type:"boolean",
description:"show process or not (default:false)",
example:"whodid author --verbose"
},{
name:"cwd",
type:"string",
description:"the specification git project cwd.(default: './')",
example:"whodid author --cwd=/home/ubuntu/someProj"
},{
name:"since",
type:"string",
description:"counting start day. (default:2.month)",
example:"whodid author --since=2.month"
},{
name:"until",
type:"string",
description:"counting end day. (default:now)",
example:"whodid author --until=now"
},{
name:"include-merge",
type:"boolean",
description:"specify include merge commit or not.(default: false)",
example:"whodid author --include-merge=true"
},{
name:"line-accept-max",
type:"integer",
description:"set acceptable limit of modified line number",
example:"whodid author --line-accept-max=10000"
},{
name:"output-as",
type:"string",
description:"output type <table|json|csv> (default:table) csv requires --csv-seperator=<seperator> option also",
example:"whodid author --output-as=table"
},{
name:"csv-seperator",
type:"string",
description:"csv seperator",
example:"whodid author --csv-seperator=','"
},{
name:"num",
type:"integer",
description:"number of result",
example:"whodid heavy --since=2.month --num=10"
},{
name:"author",
type:"string",
description:"show only specific author",
example:"whodid heavy --author='zero <[email protected]>'"
}
].concat(options)
}
argv.info([
"whodid",
"Usage 1: whodid",
"Usage 2: whodid author|file"
].join(os.EOL));
argv.mod({
mod:'author',
description:[
"Check modified or added line numbers of each committer",
"Examples:",
"\twhodid author",
"\twhodid author --verbose=false",
"\twhodid author --path=~/someProj",
"\twhodid author --path=~/someProj --since=1.month"
].join(os.EOL),
options:make_extra_option([])
});
argv.mod({
mod:'file',
description:[
"Check file list of most modified",
"Example:",
"\twhodid file",
"\twhodid file --path=~/someProj",
"\twhodid file --path=~/someProj --since=1.month"
].join(os.EOL),
options:make_extra_option([])
});
argv.mod({
mod:'heavy',
description:[
"Check what is heavy commit",
"Examples:",
"\twhodid heavy",
"\twhodid heavy --path=~/someProj",
"\twhodid heavy --path=~/someProj --since=1.month",
"\twhodid heavy --path=~/someProj --author='zero <[email protected]>'",
].join(os.EOL),
options:make_extra_option([])
});
argv.mod({
mod:'debug',
description:[
"show log commit parsing log",
"Examples:",
"\twhodid debug --commit=<commit-id>",
].join(os.EOL),
options:make_extra_option([{
name:"commit",
type:"string",
description:"commit hash",
example:"whodid debug --commit=a1b2c3d"
}])
});
argv.mod({
mod:'history',
description:[
"show commit scores each day",
"Examples:",
'\twhodid history --author="tom"',
].join(os.EOL),
options:make_extra_option([])
});
var args = argv.run();
var opts = {}
for(let k in args.options)
opts[to_snake_case(k)] = args.options[k]
whodid_config.load_from_file("whodid.json", opts.cwd)
whodid_config.adjust(opts)
if(!!opts.verbose)
console.log(JSON.stringify(whodid_config.retrieve(), null, 4))
switch(args.mod) {
case "author":
default:
{
let commits = whodid_base.get_commits()
whodid_author.run(commits)
}
break;
case "heavy":
{
let commits = whodid_base.get_commits()
whodid_heavy.run(commits)
}
break;
case "file":
{
let commits = whodid_base.get_commits()
whodid_file.run(commits)
}
break;
case "history":
{
let commits = whodid_base.get_commits()
whodid_history.run(commits)
}
break;
case "debug":
{
let commit_hash = args.options.commit?args.options.commit:null;
if(commit_hash == null)
console.log("commit option required")
else{
whodid_debug.run(commit_hash)
}
}
break;
}