-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
This is the same as part of #1248 (fish), as well as #1212 (zsh).
The powershell completion script disables file completion only if it receives no completions from the __complete command. Notice the last line of:
cobra/powershell_completions.go
Lines 143 to 146 in eb3b639
| if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) { | |
| __%[1]s_debug "ShellCompDirectiveNoFileComp is called" | |
| if ($Values.Length -eq 0) { |
However, it is valid for ValidArgsFunction to return completions that don't apply to the current toComplete prefix. This means file completion should still be disabled if requested by the directive, but the script does not realize it as it still believes it received valid completions.
Say I have the following ValidArgsFunction for command nofilecomp:
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
// We do not consider the toComplete prefix and always return a completion
return []string{"why"}, cobra.ShellCompDirectiveNoFileComp
},
If I have a file called myfile and run in powershell:
$ ./testprog nofilecomp my<TAB>
I would expect not to get file completion, but I do, and myfile gets completed. This is because
$ ./testprog __complete nofilecomp my<ENTER>
why
:0
Completion ended with directive: ShellCompDirectiveNoFileComp
Notice that above, the script receives a completion even though it is not technically valid. This is allowed. But then, the script does not realize it must disable file completion.
/cc @Luap99