mirror of
https://github.com/TangentFoxy/argparse.git
synced 2025-07-28 02:52:20 +00:00
Fish completions: fully support nested commands
This commit is contained in:
@@ -217,37 +217,84 @@ _comptest
|
||||
|
||||
it("generates correct fish completion script", function()
|
||||
assert.equal([=[
|
||||
function __fish_comptest_print_command
|
||||
set -l cmdline (commandline -poc)
|
||||
set -l cmd
|
||||
set -e cmdline[1]
|
||||
for arg in $cmdline
|
||||
switch $arg
|
||||
case help
|
||||
set cmd $cmd help
|
||||
break
|
||||
case completion
|
||||
set cmd $cmd completion
|
||||
break
|
||||
case install i
|
||||
set cmd $cmd install
|
||||
break
|
||||
case admin
|
||||
set cmd $cmd admin
|
||||
set -e cmdline[1]
|
||||
for arg in $cmdline
|
||||
switch $arg
|
||||
case help
|
||||
set cmd $cmd help
|
||||
break
|
||||
case add
|
||||
set cmd $cmd add
|
||||
break
|
||||
case remove
|
||||
set cmd $cmd remove
|
||||
break
|
||||
end
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
echo "$cmd"
|
||||
end
|
||||
|
||||
complete -c comptest -n '__fish_use_subcommand' -xa 'help' -d 'Show help for commands'
|
||||
complete -c comptest -n '__fish_use_subcommand' -xa 'completion' -d 'Output a shell completion script'
|
||||
complete -c comptest -n '__fish_use_subcommand' -xa 'install' -d 'Install a rock'
|
||||
complete -c comptest -n '__fish_use_subcommand' -xa 'i' -d 'Install a rock'
|
||||
complete -c comptest -n '__fish_use_subcommand' -xa 'admin' -d 'Rock server administration interface'
|
||||
function __fish_comptest_using_command
|
||||
test (__fish_comptest_print_command) = "$argv"
|
||||
and return 0
|
||||
or return 1
|
||||
end
|
||||
|
||||
function __fish_comptest_seen_command
|
||||
string match -q "$argv*" (__fish_comptest_print_command)
|
||||
and return 0
|
||||
or return 1
|
||||
end
|
||||
|
||||
complete -c comptest -n '__fish_comptest_using_command' -xa 'help' -d 'Show help for commands'
|
||||
complete -c comptest -n '__fish_comptest_using_command' -xa 'completion' -d 'Output a shell completion script'
|
||||
complete -c comptest -n '__fish_comptest_using_command' -xa 'install i' -d 'Install a rock'
|
||||
complete -c comptest -n '__fish_comptest_using_command' -xa 'admin' -d 'Rock server administration interface'
|
||||
complete -c comptest -s h -l help -d 'Show this help message and exit'
|
||||
complete -c comptest -l completion -xa 'bash zsh fish' -d 'Output a shell completion script for the specified shell'
|
||||
complete -c comptest -s v -l verbose -d 'Set the verbosity level'
|
||||
complete -c comptest -s f -l files -r -d 'A description with illegal "\' characters'
|
||||
|
||||
complete -c comptest -n '__fish_seen_subcommand_from help' -xa 'help completion install i admin'
|
||||
complete -c comptest -n '__fish_seen_subcommand_from help' -s h -l help -d 'Show this help message and exit'
|
||||
complete -c comptest -n '__fish_comptest_using_command help' -xa 'help completion install i admin'
|
||||
complete -c comptest -n '__fish_comptest_seen_command help' -s h -l help -d 'Show this help message and exit'
|
||||
|
||||
complete -c comptest -n '__fish_seen_subcommand_from completion' -s h -l help -d 'Show this help message and exit'
|
||||
complete -c comptest -n '__fish_comptest_seen_command completion' -s h -l help -d 'Show this help message and exit'
|
||||
|
||||
complete -c comptest -n '__fish_seen_subcommand_from install i' -s h -l help -d 'Show this help message and exit'
|
||||
complete -c comptest -n '__fish_seen_subcommand_from install i' -l deps-mode -xa 'all one order none'
|
||||
complete -c comptest -n '__fish_seen_subcommand_from install i' -l no-doc -d 'Install without documentation'
|
||||
complete -c comptest -n '__fish_comptest_seen_command install' -s h -l help -d 'Show this help message and exit'
|
||||
complete -c comptest -n '__fish_comptest_seen_command install' -l deps-mode -xa 'all one order none'
|
||||
complete -c comptest -n '__fish_comptest_seen_command install' -l no-doc -d 'Install without documentation'
|
||||
|
||||
complete -c comptest -n '__fish_use_subcommand' -xa 'help' -d 'Show help for commands'
|
||||
complete -c comptest -n '__fish_use_subcommand' -xa 'add' -d 'Add a rock to a server'
|
||||
complete -c comptest -n '__fish_use_subcommand' -xa 'remove' -d 'Remove a rock from a server'
|
||||
complete -c comptest -n '__fish_seen_subcommand_from admin' -s h -l help -d 'Show this help message and exit'
|
||||
complete -c comptest -n '__fish_comptest_using_command admin' -xa 'help' -d 'Show help for commands'
|
||||
complete -c comptest -n '__fish_comptest_using_command admin' -xa 'add' -d 'Add a rock to a server'
|
||||
complete -c comptest -n '__fish_comptest_using_command admin' -xa 'remove' -d 'Remove a rock from a server'
|
||||
complete -c comptest -n '__fish_comptest_seen_command admin' -s h -l help -d 'Show this help message and exit'
|
||||
|
||||
complete -c comptest -n '__fish_seen_subcommand_from help' -xa 'help add remove'
|
||||
complete -c comptest -n '__fish_seen_subcommand_from help' -s h -l help -d 'Show this help message and exit'
|
||||
complete -c comptest -n '__fish_comptest_using_command admin help' -xa 'help add remove'
|
||||
complete -c comptest -n '__fish_comptest_seen_command admin help' -s h -l help -d 'Show this help message and exit'
|
||||
|
||||
complete -c comptest -n '__fish_seen_subcommand_from add' -s h -l help -d 'Show this help message and exit'
|
||||
complete -c comptest -n '__fish_comptest_seen_command admin add' -s h -l help -d 'Show this help message and exit'
|
||||
|
||||
complete -c comptest -n '__fish_seen_subcommand_from remove' -s h -l help -d 'Show this help message and exit'
|
||||
complete -c comptest -n '__fish_comptest_seen_command admin remove' -s h -l help -d 'Show this help message and exit'
|
||||
]=], get_output("completion fish"))
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user