Skip to content

Commit

Permalink
fix!: Remove multiple occurrences in favor of Append/Count
Browse files Browse the repository at this point in the history
For num_vals and friends, this only implements hacks until clap-rs#2688

Fixes clap-rs#3021
  • Loading branch information
epage committed Jul 25, 2022
1 parent 8c7fe8b commit 6f03b4f
Show file tree
Hide file tree
Showing 23 changed files with 101 additions and 217 deletions.
17 changes: 3 additions & 14 deletions clap_complete/src/shells/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,7 @@ fn write_opts_of(p: &Command, p_global: Option<&Command>) -> String {
let help = o.get_help().map_or(String::new(), escape_help);
let conflicts = arg_conflicts(p, o, p_global);

#[allow(deprecated)]
let multiple = if o.is_multiple_occurrences_set() {
"*"
} else {
""
};
let multiple = "*";

let vn = match o.get_value_names() {
None => " ".to_string(),
Expand Down Expand Up @@ -555,12 +550,7 @@ fn write_flags_of(p: &Command, p_global: Option<&Command>) -> String {
let help = f.get_help().map_or(String::new(), escape_help);
let conflicts = arg_conflicts(p, &f, p_global);

#[allow(deprecated)]
let multiple = if f.is_multiple_occurrences_set() {
"*"
} else {
""
};
let multiple = "*";

if let Some(short) = f.get_short() {
let s = format!(
Expand Down Expand Up @@ -634,8 +624,7 @@ fn write_positionals_of(p: &Command) -> String {
for arg in p.get_positionals() {
debug!("write_positionals_of:iter: arg={}", arg.get_id());

#[allow(deprecated)]
let cardinality = if arg.is_multiple_values_set() || arg.is_multiple_occurrences_set() {
let cardinality = if arg.is_multiple_values_set() {
"*:"
} else if !arg.is_required_set() {
":"
Expand Down
8 changes: 4 additions & 4 deletions clap_complete/tests/snapshots/aliases.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ _my-app() {
'*-O+[cmd option]: : ' /
'*--option=[cmd option]: : ' /
'*--opt=[cmd option]: : ' /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
'*-f[cmd flag]' /
'*-F[cmd flag]' /
'*--flag[cmd flag]' /
Expand Down
8 changes: 4 additions & 4 deletions clap_complete/tests/snapshots/basic.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ _my-app() {

local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-c[]' /
'(-c)*-v[]' /
":: :_my-app_commands" /
Expand All @@ -31,8 +31,8 @@ _my-app() {
(test)
_arguments "${_arguments_options[@]}" /
'*-d[]' /
'-h[Print help information]' /
'--help[Print help information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-c[]' /
&& ret=0
;;
Expand Down
16 changes: 8 additions & 8 deletions clap_complete/tests/snapshots/feature_sample.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ _my-app() {

local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
'*-c[some config file]' /
'*-C[some config file]' /
'*--config[some config file]' /
Expand All @@ -37,10 +37,10 @@ _my-app() {
(test)
_arguments "${_arguments_options[@]}" /
'*--case=[the case to test]: : ' /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
&& ret=0
;;
(help)
Expand Down
32 changes: 16 additions & 16 deletions clap_complete/tests/snapshots/quoting.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ _my-app() {

local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
'*--single-quotes[Can be '/''always'/'', '/''auto'/'', or '/''never'/'']' /
'*--double-quotes[Can be "always", "auto", or "never"]' /
'*--backticks[For more information see `echo test`]' /
Expand All @@ -36,38 +36,38 @@ _my-app() {
case $line[1] in
(cmd-single-quotes)
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
&& ret=0
;;
(cmd-double-quotes)
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
&& ret=0
;;
(cmd-backticks)
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
&& ret=0
;;
(cmd-backslash)
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
&& ret=0
;;
(cmd-brackets)
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
&& ret=0
;;
(cmd-expansions)
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
&& ret=0
;;
(help)
Expand Down
40 changes: 20 additions & 20 deletions clap_complete/tests/snapshots/special_commands.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ _my-app() {

local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
'*-c[some config file]' /
'*-C[some config file]' /
'*--config[some config file]' /
Expand All @@ -37,36 +37,36 @@ _my-app() {
(test)
_arguments "${_arguments_options[@]}" /
'*--case=[the case to test]: : ' /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
&& ret=0
;;
(some_cmd)
_arguments "${_arguments_options[@]}" /
'*--config=[the other case to test]: : ' /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
'*::path:' /
&& ret=0
;;
(some-cmd-with-hyphens)
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
&& ret=0
;;
(some-hidden-cmd)
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
&& ret=0
;;
(help)
Expand Down
32 changes: 16 additions & 16 deletions clap_complete/tests/snapshots/sub_subcommands.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ _my-app() {

local context curcontext="$curcontext" state line
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
'*-c[some config file]' /
'*-C[some config file]' /
'*--config[some config file]' /
Expand All @@ -37,18 +37,18 @@ _my-app() {
(test)
_arguments "${_arguments_options[@]}" /
'*--case=[the case to test]: : ' /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
&& ret=0
;;
(some_cmd)
_arguments "${_arguments_options[@]}" /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
":: :_my-app__some_cmd_commands" /
"*::: :->some_cmd" /
&& ret=0
Expand All @@ -62,10 +62,10 @@ _arguments "${_arguments_options[@]}" /
(sub_cmd)
_arguments "${_arguments_options[@]}" /
'*--config=[the other case to test]: :(Lest quotes aren't escaped.)' /
'-h[Print help information]' /
'--help[Print help information]' /
'-V[Print version information]' /
'--version[Print version information]' /
'*-h[Print help information]' /
'*--help[Print help information]' /
'*-V[Print version information]' /
'*--version[Print version information]' /
&& ret=0
;;
(help)
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/snapshots/value_hint.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ _my-app() {
'*--host=[]: :_hosts' /
'*--url=[]: :_urls' /
'*--email=[]: :_email_addresses' /
'--help[Print help information]' /
'*--help[Print help information]' /
'*::command_with_args:_cmdambivalent' /
&& ret=0
}
Expand Down
1 change: 1 addition & 0 deletions clap_complete_fig/tests/snapshots/basic.fig.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const completion: Fig.Spec = {
],
args: {
name: "subcommand",
isVariadic: true,
isOptional: true,
},
},
Expand Down
1 change: 1 addition & 0 deletions clap_complete_fig/tests/snapshots/feature_sample.fig.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const completion: Fig.Spec = {
description: "Print this message or the help of the given subcommand(s)",
args: {
name: "subcommand",
isVariadic: true,
isOptional: true,
},
},
Expand Down
1 change: 1 addition & 0 deletions clap_complete_fig/tests/snapshots/quoting.fig.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const completion: Fig.Spec = {
description: "Print this message or the help of the given subcommand(s)",
args: {
name: "subcommand",
isVariadic: true,
isOptional: true,
},
},
Expand Down
1 change: 1 addition & 0 deletions clap_complete_fig/tests/snapshots/special_commands.fig.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const completion: Fig.Spec = {
description: "Print this message or the help of the given subcommand(s)",
args: {
name: "subcommand",
isVariadic: true,
isOptional: true,
},
},
Expand Down
2 changes: 2 additions & 0 deletions clap_complete_fig/tests/snapshots/sub_subcommands.fig.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const completion: Fig.Spec = {
description: "Print this message or the help of the given subcommand(s)",
args: {
name: "subcommand",
isVariadic: true,
isOptional: true,
},
},
Expand All @@ -80,6 +81,7 @@ const completion: Fig.Spec = {
description: "Print this message or the help of the given subcommand(s)",
args: {
name: "subcommand",
isVariadic: true,
isOptional: true,
},
},
Expand Down
Loading

0 comments on commit 6f03b4f

Please sign in to comment.