mirror of
https://github.com/spf13/cobra
synced 2025-05-06 13:27:26 +00:00
backport __fish_seen_argument.
This commit is contained in:
parent
5ee6b2337b
commit
157737b787
2 changed files with 23 additions and 0 deletions
|
@ -39,6 +39,28 @@ function __fish_%s_seen_subcommand_path --description 'Test whether the full pat
|
||||||
set -e cmd[1]
|
set -e cmd[1]
|
||||||
return (test (string trim -- "$argv") = (string trim -- "$cmd"))
|
return (test (string trim -- "$argv") = (string trim -- "$cmd"))
|
||||||
end
|
end
|
||||||
|
# borrowed from current fish-shell master, since it is not in current 2.7.1 release
|
||||||
|
function __fish_seen_argument
|
||||||
|
argparse 's/short=+' 'l/long=+' -- $argv
|
||||||
|
|
||||||
|
set cmd (commandline -co)
|
||||||
|
set -e cmd[1]
|
||||||
|
for t in $cmd
|
||||||
|
for s in $_flag_s
|
||||||
|
if string match -qr "^-[A-z0-9]*"$s"[A-z0-9]*\$" -- $t
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for l in $_flag_l
|
||||||
|
if string match -q -- "--$l" $t
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return 1
|
||||||
|
end
|
||||||
`, cmd.Name(), cmd.Name(), strings.Join(subCommandNames, " "), cmd.Name()))
|
`, cmd.Name(), cmd.Name(), strings.Join(subCommandNames, " "), cmd.Name()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@ func TestFishCompletions(t *testing.T) {
|
||||||
// check for preamble helper functions
|
// check for preamble helper functions
|
||||||
check(t, output, "__fish_root_no_subcommand")
|
check(t, output, "__fish_root_no_subcommand")
|
||||||
check(t, output, "__fish_root_seen_subcommand_path")
|
check(t, output, "__fish_root_seen_subcommand_path")
|
||||||
|
check(t, output, "__fish_seen_argument")
|
||||||
|
|
||||||
// check for subcommands
|
// check for subcommands
|
||||||
check(t, output, "-a echo")
|
check(t, output, "-a echo")
|
||||||
|
|
Loading…
Add table
Reference in a new issue