From 4b2b47af48639a3caa43de0f1bc67f4a24f9cde2 Mon Sep 17 00:00:00 2001 From: whi-tw Date: Sun, 13 Feb 2022 21:03:24 +0000 Subject: [PATCH] Fix zsh completion (#1108) 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 --- acceptance_tests/completion.sh | 9 +++++++++ yq.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100755 acceptance_tests/completion.sh diff --git a/acceptance_tests/completion.sh b/acceptance_tests/completion.sh new file mode 100755 index 00000000..2d639221 --- /dev/null +++ b/acceptance_tests/completion.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +testCompletionRuns() { + result=$(./yq __complete "" 2>&1) + assertEquals 0 $? + assertContains "$result" "Completion ended with directive:" +} + +source ./scripts/shunit2 diff --git a/yq.go b/yq.go index 21e71284..239ff0fd 100644 --- a/yq.go +++ b/yq.go @@ -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:]...))