@@ -18,19 +18,28 @@ import (
1818
1919const Usage = `usage: git-sizer [OPTS]
2020
21- -v, --verbose report all statistics, whether concerning or not
2221 --threshold THRESHOLD minimum level of concern (i.e., number of stars)
2322 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'
2630 --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'.
3037 -j, --json output results in JSON format
3138 --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'.
3443 --version only report the git-sizer version number
3544
3645 Reference selection:
@@ -164,8 +173,8 @@ func mainImplementation(args []string) error {
164173 var nameStyle sizes.NameStyle = sizes .NameStyleFull
165174 var cpuprofile string
166175 var jsonOutput bool
167- var jsonVersion uint
168- var threshold sizes.Threshold = 1
176+ var jsonVersion int
177+ var threshold sizes.Threshold
169178 var progress bool
170179 var version bool
171180 var filter git.IncludeExcludeFilter
@@ -217,6 +226,12 @@ func mainImplementation(args []string) error {
217226 )
218227 flags .Lookup ("verbose" ).NoOptDefVal = "true"
219228
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+
220235 flags .Var (
221236 & threshold , "threshold" ,
222237 "minimum level of concern (i.e., number of stars) that should be\n " +
@@ -238,7 +253,7 @@ func mainImplementation(args []string) error {
238253 )
239254
240255 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)" )
242257
243258 atty , err := isatty .Isatty (os .Stderr .Fd ())
244259 if err != nil {
@@ -263,10 +278,6 @@ func mainImplementation(args []string) error {
263278 return err
264279 }
265280
266- if jsonOutput && ! (jsonVersion == 1 || jsonVersion == 2 ) {
267- return fmt .Errorf ("JSON version must be 1 or 2" )
268- }
269-
270281 if cpuprofile != "" {
271282 f , err := os .Create (cpuprofile )
272283 if err != nil {
@@ -295,6 +306,55 @@ func mainImplementation(args []string) error {
295306 }
296307 defer repo .Close ()
297308
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+
298358 var historySize sizes.HistorySize
299359
300360 var refFilter git.ReferenceFilter = filter .Filter
0 commit comments