@@ -65,54 +65,59 @@ func mainImplementation() error {
65
65
var progress bool
66
66
var version bool
67
67
68
- pflag .BoolVar (& processBranches , "branches" , false , "process all branches" )
69
- pflag .BoolVar (& processTags , "tags" , false , "process all tags" )
70
- pflag .BoolVar (& processRemotes , "remotes" , false , "process all remote-tracking branches" )
68
+ flags := pflag .NewFlagSet ("" , pflag .ContinueOnError )
71
69
72
- pflag .VarP (
70
+ flags .BoolVar (& processBranches , "branches" , false , "process all branches" )
71
+ flags .BoolVar (& processTags , "tags" , false , "process all tags" )
72
+ flags .BoolVar (& processRemotes , "remotes" , false , "process all remote-tracking branches" )
73
+
74
+ flags .VarP (
73
75
sizes .NewThresholdFlagValue (& threshold , 0 ),
74
76
"verbose" , "v" , "report all statistics, whether concerning or not" ,
75
77
)
76
- pflag .Lookup ("verbose" ).NoOptDefVal = "true"
78
+ flags .Lookup ("verbose" ).NoOptDefVal = "true"
77
79
78
- pflag .Var (
80
+ flags .Var (
79
81
& threshold , "threshold" ,
80
82
"minimum level of concern (i.e., number of stars) that should be\n " +
81
83
" reported" ,
82
84
)
83
85
84
- pflag .Var (
86
+ flags .Var (
85
87
sizes .NewThresholdFlagValue (& threshold , 30 ),
86
88
"critical" , "only report critical statistics" ,
87
89
)
88
- pflag .Lookup ("critical" ).NoOptDefVal = "true"
90
+ flags .Lookup ("critical" ).NoOptDefVal = "true"
89
91
90
- pflag .Var (
92
+ flags .Var (
91
93
& nameStyle , "names" ,
92
94
"display names of large objects in the specified `style`:\n " +
93
95
" --names=none omit footnotes entirely\n " +
94
96
" --names=hash show only the SHA-1s of objects\n " +
95
97
" --names=full show full names" ,
96
98
)
97
99
98
- pflag .BoolVarP (& jsonOutput , "json" , "j" , false , "output results in JSON format" )
99
- pflag .UintVar (& jsonVersion , "json-version" , 1 , "JSON format version to output (1 or 2)" )
100
+ flags .BoolVarP (& jsonOutput , "json" , "j" , false , "output results in JSON format" )
101
+ flags .UintVar (& jsonVersion , "json-version" , 1 , "JSON format version to output (1 or 2)" )
100
102
101
103
atty , err := isatty .Isatty (os .Stderr .Fd ())
102
104
if err != nil {
103
105
atty = false
104
106
}
105
- pflag .BoolVar (& progress , "progress" , atty , "report progress to stderr" )
106
- pflag .BoolVar (& version , "version" , false , "report the git-sizer version number" )
107
- pflag .Var (& NegatedBoolValue {& progress }, "no-progress" , "suppress progress output" )
108
- pflag .Lookup ("no-progress" ).NoOptDefVal = "true"
107
+ flags .BoolVar (& progress , "progress" , atty , "report progress to stderr" )
108
+ flags .BoolVar (& version , "version" , false , "report the git-sizer version number" )
109
+ flags .Var (& NegatedBoolValue {& progress }, "no-progress" , "suppress progress output" )
110
+ flags .Lookup ("no-progress" ).NoOptDefVal = "true"
109
111
110
- pflag .StringVar (& cpuprofile , "cpuprofile" , "" , "write cpu profile to file" )
111
- pflag . CommandLine .MarkHidden ("cpuprofile" )
112
+ flags .StringVar (& cpuprofile , "cpuprofile" , "" , "write cpu profile to file" )
113
+ flags .MarkHidden ("cpuprofile" )
112
114
113
- pflag . CommandLine .SortFlags = false
115
+ flags .SortFlags = false
114
116
115
- pflag .Parse ()
117
+ err = flags .Parse (os .Args [1 :])
118
+ if err != nil {
119
+ return err
120
+ }
116
121
117
122
if jsonOutput && ! (jsonVersion == 1 || jsonVersion == 2 ) {
118
123
return fmt .Errorf ("JSON version must be 1 or 2" )
@@ -136,7 +141,7 @@ func mainImplementation() error {
136
141
return nil
137
142
}
138
143
139
- args := pflag .Args ()
144
+ args := flags .Args ()
140
145
141
146
if len (args ) != 0 {
142
147
return errors .New ("excess arguments" )
0 commit comments