Fix zsh completion

4ec533b introduced a bug which causes the 'hidden' cli parameter
`__complete` to be ignored.

Add a check for this parameter, so that it can pass to `cobra`

Signed-off-by: Tom Whitwell <tom@whi.tw>
This commit is contained in:
Tom Whitwell 2022-02-13 00:27:45 +00:00
parent a5f6a80cf6
commit f618d56538
No known key found for this signature in database
GPG Key ID: CDEFD21A6438FA40
2 changed files with 10 additions and 1 deletions

9
acceptance_tests/completion.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
testCompletionRuns() {
result=$(./yq __complete "" 2>&1)
assertEquals 0 $?
assertContains "$result" "Completion ended with directive:"
}
source ./scripts/shunit2

2
yq.go
View File

@ -12,7 +12,7 @@ func main() {
args := os.Args[1:]
_, _, err := cmd.Find(args)
if err != nil {
if err != nil && args[0] != "__complete" {
// default command when nothing matches...
newArgs := []string{"eval"}
cmd.SetArgs(append(newArgs, os.Args[1:]...))