mirror of
https://github.com/spf13/cobra
synced 2025-05-06 05:17:21 +00:00
This is a temporary fix to get some zsh completion. The idea is taken from kubectl where the bash completion script is wrapped with some zsh adapter code. The zsh magic is taken from kubectl.
35 lines
619 B
Go
35 lines
619 B
Go
package cobra
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
const (
|
|
expectedTail = `BASH_COMPLETION_EOF
|
|
}
|
|
|
|
__cobra_bash_source <(__trivialapp_convert_bash_to_zsh)
|
|
_complete trivialapp 2>/dev/null
|
|
`
|
|
expectedHead = `#compdef trivialapp`
|
|
)
|
|
|
|
func TestZshCompletion(t *testing.T) {
|
|
root := &Command{Use: "trivialapp"}
|
|
|
|
buf := &bytes.Buffer{}
|
|
err := root.GenZshCompletion(buf)
|
|
if err != nil {
|
|
t.Errorf("Unexpected error: %s", err)
|
|
}
|
|
actual := buf.String()
|
|
|
|
if !strings.HasPrefix(actual, expectedHead) {
|
|
t.Error("Unexpected head")
|
|
}
|
|
if !strings.HasSuffix(actual, expectedTail) {
|
|
t.Error("Unexpected tail")
|
|
}
|
|
}
|