-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve completion cmd handling (#290)
* fix: improve completion cmd handling The way it works today, its not possible to install the completions automatically on Nix, as the build needs to be pure. This is kinda hacky, but I think it'll work: we only allow the completion cmd to run if there is good evidence that it is a completion command, and not a prompt that happens to start with completion. refs #287 * docs: update * docs: wording
- Loading branch information
Showing
3 changed files
with
87 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestIsCompletionCmd(t *testing.T) { | ||
for args, is := range map[string]bool{ | ||
"": false, | ||
"something": false, | ||
"something something": false, | ||
"completion for my bash script how to": false, | ||
"completion bash how to": false, | ||
"completion": false, | ||
"completion -h": true, | ||
"completion --help": true, | ||
"completion help": true, | ||
"completion bash": true, | ||
"completion fish": true, | ||
"completion zsh": true, | ||
"completion powershell": true, | ||
"completion bash -h": true, | ||
"completion fish -h": true, | ||
"completion zsh -h": true, | ||
"completion powershell -h": true, | ||
"completion bash --help": true, | ||
"completion fish --help": true, | ||
"completion zsh --help": true, | ||
"completion powershell --help": true, | ||
"__complete": true, | ||
"__complete blah blah blah": true, | ||
} { | ||
t.Run(args, func(t *testing.T) { | ||
vargs := append([]string{"mods"}, strings.Fields(args)...) | ||
if b := isCompletionCmd(vargs); b != is { | ||
t.Errorf("%v: expected %v, got %v", vargs, is, b) | ||
} | ||
}) | ||
} | ||
} |