Skip to content

Commit

Permalink
fix(complete): Fix multiple occurence pos args zsh
Browse files Browse the repository at this point in the history
This fixes e.g. CommandWithArguments with previous positional arguments
in zsh.
  • Loading branch information
pseyfert committed May 9, 2022
1 parent a57a411 commit f5ecbed
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion clap_complete/src/shells/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ fn write_positionals_of(p: &Command) -> String {
debug!("write_positionals_of:iter: arg={}", arg.get_id());

let cardinality = if arg.is_multiple_values_set() || arg.is_multiple_occurrences_set() {
"*:"
"*::"
} else if !arg.is_required_set() {
":"
} else {
Expand Down
5 changes: 5 additions & 0 deletions clap_complete/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ pub fn value_hint_command(name: &'static str) -> clap::Command<'static> {
.short('c')
.value_hint(clap::ValueHint::CommandString),
)
.arg(
clap::Arg::new("positional")
.required(true)
.possible_values(["stable", "nightly"]),
)
.arg(
clap::Arg::new("command_with_args")
.takes_value(true)
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/snapshots/basic.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ _arguments "${_arguments_options[@]}" /
(help)
_arguments "${_arguments_options[@]}" /
'-c[]' /
'*::subcommand -- The subcommand whose help message to display:' /
'*:::subcommand -- The subcommand whose help message to display:' /
&& ret=0
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/snapshots/feature_sample.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ _arguments "${_arguments_options[@]}" /
;;
(help)
_arguments "${_arguments_options[@]}" /
'*::subcommand -- The subcommand whose help message to display:' /
'*:::subcommand -- The subcommand whose help message to display:' /
&& ret=0
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/snapshots/quoting.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ _arguments "${_arguments_options[@]}" /
;;
(help)
_arguments "${_arguments_options[@]}" /
'*::subcommand -- The subcommand whose help message to display:' /
'*:::subcommand -- The subcommand whose help message to display:' /
&& ret=0
;;
esac
Expand Down
4 changes: 2 additions & 2 deletions clap_complete/tests/snapshots/special_commands.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ _arguments "${_arguments_options[@]}" /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*::path:' /
'*:::path:' /
&& ret=0
;;
(some-cmd-with-hyphens)
Expand All @@ -71,7 +71,7 @@ _arguments "${_arguments_options[@]}" /
;;
(help)
_arguments "${_arguments_options[@]}" /
'*::subcommand -- The subcommand whose help message to display:' /
'*:::subcommand -- The subcommand whose help message to display:' /
&& ret=0
;;
esac
Expand Down
4 changes: 2 additions & 2 deletions clap_complete/tests/snapshots/sub_subcommands.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ _arguments "${_arguments_options[@]}" /
;;
(help)
_arguments "${_arguments_options[@]}" /
'*::subcommand -- The subcommand whose help message to display:' /
'*:::subcommand -- The subcommand whose help message to display:' /
&& ret=0
;;
esac
Expand All @@ -79,7 +79,7 @@ esac
;;
(help)
_arguments "${_arguments_options[@]}" /
'*::subcommand -- The subcommand whose help message to display:' /
'*:::subcommand -- The subcommand whose help message to display:' /
&& ret=0
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/snapshots/value_hint.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _my-app() {

case "${cmd}" in
my__app)
opts="-p -f -d -e -c -u -h --help --choice --unknown --other --path --file --dir --exe --cmd-name --cmd --user --host --url --email <command_with_args>..."
opts="-p -f -d -e -c -u -h --help --choice --unknown --other --path --file --dir --exe --cmd-name --cmd --user --host --url --email stable nightly <command_with_args>..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
3 changes: 2 additions & 1 deletion clap_complete/tests/snapshots/value_hint.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ _my-app() {
'--url=[]: :_urls' /
'--email=[]: :_email_addresses' /
'--help[Print help information]' /
'*::command_with_args:_cmdambivalent' /
':positional:(stable nightly)' /
'*:::command_with_args:_cmdambivalent' /
&& ret=0
}

Expand Down

0 comments on commit f5ecbed

Please sign in to comment.