mirror of
https://github.com/clap-rs/clap
synced 2024-12-04 18:19:13 +00:00
fix(zsh): Use _default as zsh completion fallback
That is for a ValueHint of Unknown. This is consistent with bash where compgen -f is used in such cases. In long experience with completions distributed with zsh, the worst thing you can do is break filename completion as that's the minimum most user's expect.
This commit is contained in:
parent
55a18f518b
commit
e40168c2fd
10 changed files with 31 additions and 33 deletions
|
@ -396,10 +396,8 @@ fn value_completion(arg: &Arg) -> Option<String> {
|
|||
// NB! If you change this, please also update the table in `ValueHint` documentation.
|
||||
Some(
|
||||
match arg.get_value_hint() {
|
||||
ValueHint::Unknown => {
|
||||
return None;
|
||||
}
|
||||
ValueHint::Other => "( )",
|
||||
ValueHint::Unknown => "_default",
|
||||
ValueHint::Other => "",
|
||||
ValueHint::AnyPath => "_files",
|
||||
ValueHint::FilePath => "_files",
|
||||
ValueHint::DirPath => "_files -/",
|
||||
|
|
|
@ -15,10 +15,10 @@ _my-app() {
|
|||
|
||||
local context curcontext="$curcontext" state line
|
||||
_arguments "${_arguments_options[@]}" : \
|
||||
'-o+[cmd option]: : ' \
|
||||
'-O+[cmd option]: : ' \
|
||||
'--option=[cmd option]: : ' \
|
||||
'--opt=[cmd option]: : ' \
|
||||
'-o+[cmd option]: :_default' \
|
||||
'-O+[cmd option]: :_default' \
|
||||
'--option=[cmd option]: :_default' \
|
||||
'--opt=[cmd option]: :_default' \
|
||||
'-f[cmd flag]' \
|
||||
'-F[cmd flag]' \
|
||||
'--flag[cmd flag]' \
|
||||
|
@ -27,7 +27,7 @@ _my-app() {
|
|||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
'--version[Print version]' \
|
||||
'::positional:' \
|
||||
'::positional:_default' \
|
||||
&& ret=0
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ _my-app() {
|
|||
case $line[3] in
|
||||
(test)
|
||||
_arguments "${_arguments_options[@]}" : \
|
||||
'--case=[the case to test]: : ' \
|
||||
'--case=[the case to test]: :_default' \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
|
|
|
@ -32,7 +32,7 @@ _exhaustive() {
|
|||
case $line[1] in
|
||||
(action)
|
||||
_arguments "${_arguments_options[@]}" : \
|
||||
'--set=[value]: : ' \
|
||||
'--set=[value]: :_default' \
|
||||
'--choice=[enum]: :(first second)' \
|
||||
'--set-true[bool]' \
|
||||
'*--count[number]' \
|
||||
|
@ -187,15 +187,15 @@ esac
|
|||
;;
|
||||
(value)
|
||||
_arguments "${_arguments_options[@]}" : \
|
||||
'--delim=[]: : ' \
|
||||
'--tuple=[]: : : : ' \
|
||||
'--require-eq=[]: : ' \
|
||||
'--delim=[]: :_default' \
|
||||
'--tuple=[]: :_default: :_default' \
|
||||
'--require-eq=[]: :_default' \
|
||||
'--global[everywhere]' \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
'--version[Print version]' \
|
||||
'*;::term:' \
|
||||
'*;::term:_default' \
|
||||
&& ret=0
|
||||
;;
|
||||
(pacman)
|
||||
|
@ -272,16 +272,16 @@ _arguments "${_arguments_options[@]}" : \
|
|||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
'--version[Print version]' \
|
||||
'::first:' \
|
||||
'::free:' \
|
||||
'::first:_default' \
|
||||
'::free:_default' \
|
||||
&& ret=0
|
||||
;;
|
||||
(alias)
|
||||
_arguments "${_arguments_options[@]}" : \
|
||||
'-o+[cmd option]: : ' \
|
||||
'-O+[cmd option]: : ' \
|
||||
'--option=[cmd option]: : ' \
|
||||
'--opt=[cmd option]: : ' \
|
||||
'-o+[cmd option]: :_default' \
|
||||
'-O+[cmd option]: :_default' \
|
||||
'--option=[cmd option]: :_default' \
|
||||
'--opt=[cmd option]: :_default' \
|
||||
'-f[cmd flag]' \
|
||||
'-F[cmd flag]' \
|
||||
'--flag[cmd flag]' \
|
||||
|
@ -291,14 +291,14 @@ _arguments "${_arguments_options[@]}" : \
|
|||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
'--version[Print version]' \
|
||||
'::positional:' \
|
||||
'::positional:_default' \
|
||||
&& ret=0
|
||||
;;
|
||||
(hint)
|
||||
_arguments "${_arguments_options[@]}" : \
|
||||
'--choice=[]: :(bash fish zsh)' \
|
||||
'--unknown=[]: : ' \
|
||||
'--other=[]: :( )' \
|
||||
'--unknown=[]: :_default' \
|
||||
'--other=[]: :' \
|
||||
'-p+[]: :_files' \
|
||||
'--path=[]: :_files' \
|
||||
'-f+[]: :_files' \
|
||||
|
|
|
@ -36,7 +36,7 @@ _my-app() {
|
|||
case $line[3] in
|
||||
(test)
|
||||
_arguments "${_arguments_options[@]}" : \
|
||||
'--case=[the case to test]: : ' \
|
||||
'--case=[the case to test]: :_default' \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
|
@ -45,12 +45,12 @@ _arguments "${_arguments_options[@]}" : \
|
|||
;;
|
||||
(some_cmd)
|
||||
_arguments "${_arguments_options[@]}" : \
|
||||
'--config=[the other case to test]: : ' \
|
||||
'--config=[the other case to test]: :_default' \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
'--version[Print version]' \
|
||||
'*::path:' \
|
||||
'*::path:_default' \
|
||||
&& ret=0
|
||||
;;
|
||||
(some-cmd-with-hyphens)
|
||||
|
|
|
@ -36,7 +36,7 @@ _my-app() {
|
|||
case $line[3] in
|
||||
(test)
|
||||
_arguments "${_arguments_options[@]}" : \
|
||||
'--case=[the case to test]: : ' \
|
||||
'--case=[the case to test]: :_default' \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'-V[Print version]' \
|
||||
|
|
|
@ -17,7 +17,7 @@ _my-app() {
|
|||
_arguments "${_arguments_options[@]}" : \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'::free:' \
|
||||
'::free:_default' \
|
||||
":: :_my-app_commands" \
|
||||
"*::: :->my-app" \
|
||||
&& ret=0
|
||||
|
|
|
@ -17,7 +17,7 @@ _my-app() {
|
|||
_arguments "${_arguments_options[@]}" : \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'*::first -- first multi-valued argument:' \
|
||||
'*::first -- first multi-valued argument:_default' \
|
||||
&& ret=0
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ _my-app() {
|
|||
local context curcontext="$curcontext" state line
|
||||
_arguments "${_arguments_options[@]}" : \
|
||||
'--choice=[]: :(bash fish zsh)' \
|
||||
'--unknown=[]: : ' \
|
||||
'--other=[]: :( )' \
|
||||
'--unknown=[]: :_default' \
|
||||
'--other=[]: :' \
|
||||
'-p+[]: :_files' \
|
||||
'--path=[]: :_files' \
|
||||
'-f+[]: :_files' \
|
||||
|
|
|
@ -17,7 +17,7 @@ _my-app() {
|
|||
_arguments "${_arguments_options[@]}" : \
|
||||
'-h[Print help]' \
|
||||
'--help[Print help]' \
|
||||
'*;::arguments -- multi-valued argument with a value terminator:' \
|
||||
'*;::arguments -- multi-valued argument with a value terminator:_default' \
|
||||
&& ret=0
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue