@@ -18,19 +18,28 @@ import (
18
18
19
19
const Usage = `usage: git-sizer [OPTS]
20
20
21
- -v, --verbose report all statistics, whether concerning or not
22
21
--threshold THRESHOLD minimum level of concern (i.e., number of stars)
23
22
that should be reported. Default:
24
- '--threshold=1'.
25
- --critical only report critical statistics
23
+ '--threshold=1'. Can be set via gitconfig:
24
+ 'sizer.threshold'.
25
+ -v, --verbose report all statistics, whether concerning or
26
+ not; equivalent to '--threshold=0
27
+ --no-verbose equivalent to '--threshold=1'
28
+ --critical only report critical statistics; equivalent
29
+ to '--threshold=30'
26
30
--names=[none|hash|full] display names of large objects in the specified
27
- style: 'none' (omit footnotes entirely), 'hash'
28
- (show only the SHA-1s of objects), or 'full'
29
- (show full names). Default is '--names=full'.
31
+ style. Values:
32
+ * 'none' - omit footnotes entirely
33
+ * 'hash' - show only the SHA-1s of objects
34
+ * 'full' - show full names
35
+ Default is '--names=full'. Can be set via
36
+ gitconfig: 'sizer.names'.
30
37
-j, --json output results in JSON format
31
38
--json-version=[1|2] choose which JSON format version to output.
32
- Default: --json-version=1.
33
- --[no-]progress report (don't report) progress to stderr.
39
+ Default: --json-version=1. Can be set via
40
+ gitconfig: 'sizer.jsonVersion'.
41
+ --[no-]progress report (don't report) progress to stderr. Can
42
+ be set via gitconfig: 'sizer.progress'.
34
43
--version only report the git-sizer version number
35
44
36
45
Reference selection:
@@ -164,8 +173,8 @@ func mainImplementation(args []string) error {
164
173
var nameStyle sizes.NameStyle = sizes .NameStyleFull
165
174
var cpuprofile string
166
175
var jsonOutput bool
167
- var jsonVersion uint
168
- var threshold sizes.Threshold = 1
176
+ var jsonVersion int
177
+ var threshold sizes.Threshold
169
178
var progress bool
170
179
var version bool
171
180
var filter git.IncludeExcludeFilter
@@ -217,6 +226,12 @@ func mainImplementation(args []string) error {
217
226
)
218
227
flags .Lookup ("verbose" ).NoOptDefVal = "true"
219
228
229
+ flags .Var (
230
+ sizes .NewThresholdFlagValue (& threshold , 1 ),
231
+ "no-verbose" , "report statistics that are at all concerning" ,
232
+ )
233
+ flags .Lookup ("no-verbose" ).NoOptDefVal = "true"
234
+
220
235
flags .Var (
221
236
& threshold , "threshold" ,
222
237
"minimum level of concern (i.e., number of stars) that should be\n " +
@@ -238,7 +253,7 @@ func mainImplementation(args []string) error {
238
253
)
239
254
240
255
flags .BoolVarP (& jsonOutput , "json" , "j" , false , "output results in JSON format" )
241
- flags .UintVar (& jsonVersion , "json-version" , 1 , "JSON format version to output (1 or 2)" )
256
+ flags .IntVar (& jsonVersion , "json-version" , 1 , "JSON format version to output (1 or 2)" )
242
257
243
258
atty , err := isatty .Isatty (os .Stderr .Fd ())
244
259
if err != nil {
@@ -263,10 +278,6 @@ func mainImplementation(args []string) error {
263
278
return err
264
279
}
265
280
266
- if jsonOutput && ! (jsonVersion == 1 || jsonVersion == 2 ) {
267
- return fmt .Errorf ("JSON version must be 1 or 2" )
268
- }
269
-
270
281
if cpuprofile != "" {
271
282
f , err := os .Create (cpuprofile )
272
283
if err != nil {
@@ -295,6 +306,55 @@ func mainImplementation(args []string) error {
295
306
}
296
307
defer repo .Close ()
297
308
309
+ if jsonOutput {
310
+ if ! flags .Changed ("json-version" ) {
311
+ v , err := repo .ConfigIntDefault ("sizer.jsonVersion" , jsonVersion )
312
+ if err != nil {
313
+ return err
314
+ }
315
+ jsonVersion = v
316
+ if ! (jsonVersion == 1 || jsonVersion == 2 ) {
317
+ return fmt .Errorf ("JSON version (read from gitconfig) must be 1 or 2" )
318
+ }
319
+ } else if ! (jsonVersion == 1 || jsonVersion == 2 ) {
320
+ return fmt .Errorf ("JSON version must be 1 or 2" )
321
+ }
322
+ }
323
+
324
+ if ! flags .Changed ("threshold" ) &&
325
+ ! flags .Changed ("verbose" ) &&
326
+ ! flags .Changed ("no-verbose" ) &&
327
+ ! flags .Changed ("critical" ) {
328
+ s , err := repo .ConfigStringDefault ("sizer.threshold" , fmt .Sprintf ("%g" , threshold ))
329
+ if err != nil {
330
+ return err
331
+ }
332
+ v , err := strconv .ParseFloat (s , 64 )
333
+ if err != nil {
334
+ return fmt .Errorf ("parsing gitconfig value for 'sizer.threshold': %w" , err )
335
+ }
336
+ threshold = sizes .Threshold (v )
337
+ }
338
+
339
+ if ! flags .Changed ("names" ) {
340
+ s , err := repo .ConfigStringDefault ("sizer.names" , "full" )
341
+ if err != nil {
342
+ return err
343
+ }
344
+ err = nameStyle .Set (s )
345
+ if err != nil {
346
+ return fmt .Errorf ("parsing gitconfig value for 'sizer.names': %w" , err )
347
+ }
348
+ }
349
+
350
+ if ! flags .Changed ("progress" ) && ! flags .Changed ("no-progress" ) {
351
+ v , err := repo .ConfigBoolDefault ("sizer.progress" , progress )
352
+ if err != nil {
353
+ return fmt .Errorf ("parsing gitconfig value for 'sizer.progress': %w" , err )
354
+ }
355
+ progress = v
356
+ }
357
+
298
358
var historySize sizes.HistorySize
299
359
300
360
var refFilter git.ReferenceFilter = filter .Filter
0 commit comments