support ValidArgs completion of commands in fish.

This commit is contained in:
Tim Reddehase 2018-09-25 13:07:54 +02:00
parent 4ced14453a
commit 582ef5667a
2 changed files with 16 additions and 4 deletions

View file

@ -50,6 +50,12 @@ 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 {
condition := commandCompletionCondition(rootCmd, cmd)
buf.WriteString(
fmt.Sprintf("complete -c %s -f %s -a %s -d '%s'\n",
rootCmd.Name(), condition, validArg, fmt.Sprintf("Positional Argument to %s", cmd.Name())))
}
writeCommandFlagsCompletion(rootCmd, cmd, buf)
rangeCommands(cmd, func(subCmd *Command) {
writeFishCommandCompletion(rootCmd, subCmd, buf)

View file

@ -111,4 +111,10 @@ func TestFishCompletions(t *testing.T) {
check(t, output, "-n '__fish_seen_subcommand_from echo' -r -l persistent-filename")
check(t, output, "-n '__fish_seen_subcommand_from echo times' -r -l persistent-filename")
check(t, output, "-n '__fish_seen_subcommand_from print' -r -l persistent-filename")
// check for positional arguments to a command
checkRegex(t, output, `-n '__fish_root_no_subcommand(; and[^']*)?' -a pod`)
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`)
}