@@ -138,3 +138,43 @@ func TestBashCompletions(t *testing.T) {
138
138
t .Fatalf ("shellcheck failed: %v" , err )
139
139
}
140
140
}
141
+
142
+ func TestBashCompletionHiddenFlag (t * testing.T ) {
143
+ var cmdTrue = & Command {
144
+ Use : "does nothing" ,
145
+ Run : func (cmd * Command , args []string ) {},
146
+ }
147
+
148
+ const flagName = "hidden-foo-bar-baz"
149
+
150
+ var flagValue bool
151
+ cmdTrue .Flags ().BoolVar (& flagValue , flagName , false , "hidden flag" )
152
+ cmdTrue .Flags ().MarkHidden (flagName )
153
+
154
+ out := new (bytes.Buffer )
155
+ cmdTrue .GenBashCompletion (out )
156
+ bashCompletion := out .String ()
157
+ if strings .Contains (bashCompletion , flagName ) {
158
+ t .Error ("expected completion to not include %q flag: Got %v" , flagName , bashCompletion )
159
+ }
160
+ }
161
+
162
+ func TestBashCompletionDeprecatedFlag (t * testing.T ) {
163
+ var cmdTrue = & Command {
164
+ Use : "does nothing" ,
165
+ Run : func (cmd * Command , args []string ) {},
166
+ }
167
+
168
+ const flagName = "deprecated-foo-bar-baz"
169
+
170
+ var flagValue bool
171
+ cmdTrue .Flags ().BoolVar (& flagValue , flagName , false , "hidden flag" )
172
+ cmdTrue .Flags ().MarkDeprecated (flagName , "use --does-not-exist instead" )
173
+
174
+ out := new (bytes.Buffer )
175
+ cmdTrue .GenBashCompletion (out )
176
+ bashCompletion := out .String ()
177
+ if strings .Contains (bashCompletion , flagName ) {
178
+ t .Errorf ("expected completion to not include %q flag: Got %v" , flagName , bashCompletion )
179
+ }
180
+ }
0 commit comments