You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
Make sure to filter the returned completions before we check if
there are valid completions are left.
Fixesspf13#1362
Signed-off-by: Paul Holzinger <[email protected]>
Luap99
pushed a commit
to Luap99/cobra
that referenced
this issue
Mar 5, 2021
Make sure to filter the returned completions before we check if
there are valid completions left.
Fixesspf13#1362
Signed-off-by: Paul Holzinger <[email protected]>
Make sure to filter the returned completions before we check if
there are valid completions left.
Fixes#1362
Signed-off-by: Paul Holzinger <[email protected]>
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
However, it is valid for
ValidArgsFunction
to return completions that don't apply to the currenttoComplete
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 commandnofilecomp
:If I have a file called
myfile
and run in powershell:I would expect not to get file completion, but I do, and
myfile
gets completed. This is becauseNotice 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
The text was updated successfully, but these errors were encountered: