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
However, it is valid for ValidArgsFunction to return completions that don't apply to the current toComplete prefix. This means file completion should be performed, but the script does not realize it as it still believes it received valid completions.
Say I have the following ValidArgsFunction for command withfile:
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.ShellCompDirectiveDefault
},
If I have a file called myfile and run in fish:
$ ./testprog withfile my<TAB>
I would expect to get file completion and get myfile as a completion, but I don't. This is because
Notice that above, the script would receive a completion even though it is not technically valid. This is allowed. But then, the script does not realize it must do file completion.
Bug 2: NoSpace is not respected all the time
For the exact same reason, ShellCompDirectiveNoSpace also fails when the __complete command returns completions that don't match the toComplete prefix.
Say I have the following ValidArgsFunction for command nospace:
But my ValidArgsFunction does not filter the completions but instead returns all of them, leaving fish to filter them. In this case:
$ ./testprog __complete nospace whe<ENTER>
when The time
who The person
:2
Completion ended with directive: ShellCompDirectiveNoSpace
Notice that with the result above the completion script would receive two completions even though the who completion is not technically valid. This is allowed.
Bug 3: NoSpace not respected with descriptions
Finally, the nospace logic for fish does not handle the case when there is a description. To achieve "nospace" the script adds a second completion with an extra "." to prevent the shell from adding a space. However if there is a description, the extra "." is added to the description instead of the completion, and the nospace directive does not work.
I will post a PR to handle this better.
The text was updated successfully, but these errors were encountered:
This is the same bug that is present for
zsh
and described in #1211 and #1212.Bug 1: File completion is not respected
The
fish
completion script performs file completion only if it receives no completions:cobra/fish_completions.go
Line 151 in b97b5ea
However, it is valid for
ValidArgsFunction
to return completions that don't apply to the currenttoComplete
prefix. This means file completion should be performed, but the script does not realize it as it still believes it received valid completions.Say I have the following
ValidArgsFunction
for commandwithfile
:If I have a file called
myfile
and run infish
:I would expect to get file completion and get
myfile
as a completion, but I don't. This is becauseNotice that above, the script would receive a completion even though it is not technically valid. This is allowed. But then, the script does not realize it must do file completion.
Bug 2: NoSpace is not respected all the time
For the exact same reason,
ShellCompDirectiveNoSpace
also fails when the__complete
command returns completions that don't match thetoComplete
prefix.Say I have the following
ValidArgsFunction
for commandnospace
:If I run in
fish
:a space is added after
./testprog nospace when
even though theShellCompDirectiveNoSpace
was given.This is because the script only handles
ShellCompDirectiveNoSpace
if a single completion is returned:cobra/fish_completions.go
Line 144 in b97b5ea
But my
ValidArgsFunction
does not filter the completions but instead returns all of them, leavingfish
to filter them. In this case:Notice that with the result above the completion script would receive two completions even though the
who
completion is not technically valid. This is allowed.Bug 3: NoSpace not respected with descriptions
Finally, the nospace logic for fish does not handle the case when there is a description. To achieve "nospace" the script adds a second completion with an extra "." to prevent the shell from adding a space. However if there is a description, the extra "." is added to the description instead of the completion, and the nospace directive does not work.
I will post a PR to handle this better.
The text was updated successfully, but these errors were encountered: