@@ -3,7 +3,6 @@ package main
33import (
44 "encoding/json"
55 "errors"
6- "flag"
76 "fmt"
87 "io"
98 "os"
@@ -13,6 +12,8 @@ import (
1312 "github.com/github/git-sizer/git"
1413 "github.com/github/git-sizer/isatty"
1514 "github.com/github/git-sizer/sizes"
15+
16+ "github.com/spf13/pflag"
1617)
1718
1819type NegatedBoolValue struct {
@@ -37,8 +38,8 @@ func (b *NegatedBoolValue) String() string {
3738 }
3839}
3940
40- func (v * NegatedBoolValue ) IsBoolFlag () bool {
41- return true
41+ func (v * NegatedBoolValue ) Type () string {
42+ return "bool"
4243}
4344
4445func main () {
@@ -59,43 +60,52 @@ func mainImplementation() error {
5960 var threshold sizes.Threshold = 1
6061 var progress bool
6162
62- flag .BoolVar (& processBranches , "branches" , false , "process all branches" )
63- flag .BoolVar (& processTags , "tags" , false , "process all tags" )
64- flag .BoolVar (& processRemotes , "remotes" , false , "process all remote-tracking branches" )
65- flag .Var (
63+ pflag .BoolVar (& processBranches , "branches" , false , "process all branches" )
64+ pflag .BoolVar (& processTags , "tags" , false , "process all tags" )
65+ pflag .BoolVar (& processRemotes , "remotes" , false , "process all remote-tracking branches" )
66+
67+ pflag .VarP (
68+ sizes .NewThresholdFlagValue (& threshold , 0 ),
69+ "verbose" , "v" , "report all statistics, whether concerning or not" ,
70+ )
71+ pflag .Lookup ("verbose" ).NoOptDefVal = "true"
72+
73+ pflag .Var (
6674 & threshold , "threshold" ,
6775 "minimum level of concern (i.e., number of stars) that should be\n " +
68- " reported" ,
76+ " reported" ,
6977 )
70- flag .Var (
78+
79+ pflag .Var (
7180 sizes .NewThresholdFlagValue (& threshold , 30 ),
7281 "critical" , "only report critical statistics" ,
7382 )
74- flag .Var (
75- sizes .NewThresholdFlagValue (& threshold , 0 ),
76- "verbose" , "report all statistics, whether concerning or not" ,
77- )
78- flag .Var (
83+ pflag .Lookup ("critical" ).NoOptDefVal = "true"
84+
85+ pflag .Var (
7986 & nameStyle , "names" ,
8087 "display names of large objects in the specified `style`:\n " +
81- " --names=none omit footnotes entirely\n " +
82- " --names=hash show only the SHA-1s of objects\n " +
83- " --names=full show full names" ,
88+ " --names=none omit footnotes entirely\n " +
89+ " --names=hash show only the SHA-1s of objects\n " +
90+ " --names=full show full names" ,
8491 )
85- flag . BoolVar ( & jsonOutput , "json" , false , "output results in JSON format" )
86- flag . BoolVar (& jsonOutput , "j" , false , "output results in JSON format" )
92+
93+ pflag . BoolVarP (& jsonOutput , "json" , "j" , false , "output results in JSON format" )
8794
8895 atty , err := isatty .Isatty (os .Stderr .Fd ())
8996 if err != nil {
9097 atty = false
9198 }
99+ pflag .BoolVar (& progress , "progress" , atty , "report progress to stderr" )
100+ pflag .Var (& NegatedBoolValue {& progress }, "no-progress" , "suppress progress output" )
101+ pflag .Lookup ("no-progress" ).NoOptDefVal = "true"
92102
93- flag . BoolVar ( & progress , "progress " , atty , "report progress to stderr " )
94- flag . Var ( & NegatedBoolValue { & progress }, "no-progress" , "suppress progress output " )
103+ pflag . StringVar ( & cpuprofile , "cpuprofile " , "" , "write cpu profile to file " )
104+ pflag . CommandLine . MarkHidden ( "cpuprofile " )
95105
96- flag . StringVar ( & cpuprofile , "cpuprofile" , "" , "write cpu profile to file" )
106+ pflag . CommandLine . SortFlags = false
97107
98- flag .Parse ()
108+ pflag .Parse ()
99109
100110 if cpuprofile != "" {
101111 f , err := os .Create (cpuprofile )
@@ -106,7 +116,7 @@ func mainImplementation() error {
106116 defer pprof .StopCPUProfile ()
107117 }
108118
109- args := flag .Args ()
119+ args := pflag .Args ()
110120
111121 if len (args ) != 0 {
112122 return errors .New ("excess arguments" )
0 commit comments