@ -102,7 +102,7 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
Short : "generate autocompletion script for bash" ,
Short : "generate autocompletion script for bash" ,
Long : bashCompDesc ,
Long : bashCompDesc ,
Args : require . NoArgs ,
Args : require . NoArgs ,
ValidArgsFunction : no Completions ,
ValidArgsFunction : no MoreArgsCompFunc ,
RunE : func ( cmd * cobra . Command , _ [ ] string ) error {
RunE : func ( cmd * cobra . Command , _ [ ] string ) error {
return runCompletionBash ( out , cmd )
return runCompletionBash ( out , cmd )
} ,
} ,
@ -114,7 +114,7 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
Short : "generate autocompletion script for zsh" ,
Short : "generate autocompletion script for zsh" ,
Long : zshCompDesc ,
Long : zshCompDesc ,
Args : require . NoArgs ,
Args : require . NoArgs ,
ValidArgsFunction : no Completions ,
ValidArgsFunction : no MoreArgsCompFunc ,
RunE : func ( cmd * cobra . Command , _ [ ] string ) error {
RunE : func ( cmd * cobra . Command , _ [ ] string ) error {
return runCompletionZsh ( out , cmd )
return runCompletionZsh ( out , cmd )
} ,
} ,
@ -126,7 +126,7 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
Short : "generate autocompletion script for fish" ,
Short : "generate autocompletion script for fish" ,
Long : fishCompDesc ,
Long : fishCompDesc ,
Args : require . NoArgs ,
Args : require . NoArgs ,
ValidArgsFunction : no Completions ,
ValidArgsFunction : no MoreArgsCompFunc ,
RunE : func ( cmd * cobra . Command , _ [ ] string ) error {
RunE : func ( cmd * cobra . Command , _ [ ] string ) error {
return runCompletionFish ( out , cmd )
return runCompletionFish ( out , cmd )
} ,
} ,
@ -138,7 +138,7 @@ func newCompletionCmd(out io.Writer) *cobra.Command {
Short : "generate autocompletion script for powershell" ,
Short : "generate autocompletion script for powershell" ,
Long : powershellCompDesc ,
Long : powershellCompDesc ,
Args : require . NoArgs ,
Args : require . NoArgs ,
ValidArgsFunction : no Completions ,
ValidArgsFunction : no MoreArgsCompFunc ,
RunE : func ( cmd * cobra . Command , _ [ ] string ) error {
RunE : func ( cmd * cobra . Command , _ [ ] string ) error {
return runCompletionPowershell ( out , cmd )
return runCompletionPowershell ( out , cmd )
} ,
} ,
@ -209,7 +209,15 @@ func runCompletionPowershell(out io.Writer, cmd *cobra.Command) error {
return cmd . Root ( ) . GenPowerShellCompletionWithDesc ( out )
return cmd . Root ( ) . GenPowerShellCompletionWithDesc ( out )
}
}
// Function to disable file completion
// noMoreArgsCompFunc deactivates file completion when doing argument shell completion.
func noCompletions ( _ * cobra . Command , _ [ ] string , _ string ) ( [ ] string , cobra . ShellCompDirective ) {
// It also provides some ActiveHelp to indicate no more arguments are accepted.
return nil , cobra . ShellCompDirectiveNoFileComp
func noMoreArgsCompFunc ( _ * cobra . Command , _ [ ] string , _ string ) ( [ ] string , cobra . ShellCompDirective ) {
return noMoreArgsComp ( )
}
// noMoreArgsComp deactivates file completion when doing argument shell completion.
// It also provides some ActiveHelp to indicate no more arguments are accepted.
func noMoreArgsComp ( ) ( [ ] string , cobra . ShellCompDirective ) {
activeHelpMsg := "This command does not take any more arguments (but may accept flags)."
return cobra . AppendActiveHelp ( nil , activeHelpMsg ) , cobra . ShellCompDirectiveNoFileComp
}
}