@@ -102,7 +102,7 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
102
102
Short : "generate autocompletion script for bash" ,
103
103
Long : bashCompDesc ,
104
104
Args : require .NoArgs ,
105
- ValidArgsFunction : noCompletions ,
105
+ ValidArgsFunction : noMoreArgsCompFunc ,
106
106
RunE : func (cmd * cobra.Command , _ []string ) error {
107
107
return runCompletionBash (out , cmd )
108
108
},
@@ -114,7 +114,7 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
114
114
Short : "generate autocompletion script for zsh" ,
115
115
Long : zshCompDesc ,
116
116
Args : require .NoArgs ,
117
- ValidArgsFunction : noCompletions ,
117
+ ValidArgsFunction : noMoreArgsCompFunc ,
118
118
RunE : func (cmd * cobra.Command , _ []string ) error {
119
119
return runCompletionZsh (out , cmd )
120
120
},
@@ -126,7 +126,7 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
126
126
Short : "generate autocompletion script for fish" ,
127
127
Long : fishCompDesc ,
128
128
Args : require .NoArgs ,
129
- ValidArgsFunction : noCompletions ,
129
+ ValidArgsFunction : noMoreArgsCompFunc ,
130
130
RunE : func (cmd * cobra.Command , _ []string ) error {
131
131
return runCompletionFish (out , cmd )
132
132
},
@@ -138,7 +138,7 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
138
138
Short : "generate autocompletion script for powershell" ,
139
139
Long : powershellCompDesc ,
140
140
Args : require .NoArgs ,
141
- ValidArgsFunction : noCompletions ,
141
+ ValidArgsFunction : noMoreArgsCompFunc ,
142
142
RunE : func (cmd * cobra.Command , _ []string ) error {
143
143
return runCompletionPowershell (out , cmd )
144
144
},
@@ -209,7 +209,15 @@ func runCompletionPowershell(out io.Writer, cmd *cobra.Command) error {
209
209
return cmd .Root ().GenPowerShellCompletionWithDesc (out )
210
210
}
211
211
212
- // Function to disable file completion
213
- func noCompletions (_ * cobra.Command , _ []string , _ string ) ([]string , cobra.ShellCompDirective ) {
214
- return nil , cobra .ShellCompDirectiveNoFileComp
212
+ // noMoreArgsCompFunc deactivates file completion when doing argument shell completion.
213
+ // It also provides some ActiveHelp to indicate no more arguments are accepted.
214
+ func noMoreArgsCompFunc (_ * cobra.Command , _ []string , _ string ) ([]string , cobra.ShellCompDirective ) {
215
+ return noMoreArgsComp ()
216
+ }
217
+
218
+ // noMoreArgsComp deactivates file completion when doing argument shell completion.
219
+ // It also provides some ActiveHelp to indicate no more arguments are accepted.
220
+ func noMoreArgsComp () ([]string , cobra.ShellCompDirective ) {
221
+ activeHelpMsg := "This command does not take any more arguments (but may accept flags)."
222
+ return cobra .AppendActiveHelp (nil , activeHelpMsg ), cobra .ShellCompDirectiveNoFileComp
215
223
}
0 commit comments