mirror of
https://github.com/spf13/cobra
synced 2025-05-06 13:27:26 +00:00
support ValidArgs completion of commands in fish.
This commit is contained in:
parent
640b79d2cb
commit
575081ea12
2 changed files with 16 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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`)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue