From 68363b77407016e08f93cc5512d35f8c7449916c Mon Sep 17 00:00:00 2001 From: Tim Reddehase Date: Tue, 25 Sep 2018 13:11:06 +0200 Subject: [PATCH] add additional support for argument aliases. --- fish_completions.go | 2 +- fish_completions_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fish_completions.go b/fish_completions.go index 5fc8df09..0034402f 100644 --- a/fish_completions.go +++ b/fish_completions.go @@ -50,7 +50,7 @@ func writeFishCommandCompletion(rootCmd, cmd *Command, buf *bytes.Buffer) { condition := commandCompletionCondition(rootCmd, cmd) buf.WriteString(fmt.Sprintf("complete -c %s -f %s -a %s -d '%s'\n", rootCmd.Name(), condition, subCmd.Name(), subCmd.Short)) }) - for _, validArg := range cmd.ValidArgs { + for _, validArg := range append(cmd.ValidArgs, cmd.ArgAliases...) { condition := commandCompletionCondition(rootCmd, cmd) buf.WriteString( fmt.Sprintf("complete -c %s -f %s -a %s -d '%s'\n", diff --git a/fish_completions_test.go b/fish_completions_test.go index 4ba8eb71..e85c86c8 100644 --- a/fish_completions_test.go +++ b/fish_completions_test.go @@ -117,4 +117,14 @@ func TestFishCompletions(t *testing.T) { checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a node`) checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a service`) checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a replicationcontroller`) + + // check for aliases to positional arguments for a command + checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a pods`) + checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a nodes`) + checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a services`) + checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a replicationcontrollers`) + checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a po`) + checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a no`) + checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a svc`) + checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a rc`) }