Skip to content

Commit

Permalink
fix(clap_complete_fig): Correct requiresEquals name and add it to t…
Browse files Browse the repository at this point in the history
…he right objects
  • Loading branch information
fedeci committed Mar 18, 2022
1 parent 3034fdb commit 5689adc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion clap_complete/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ pub fn special_commands_command(name: &'static str) -> clap::Command<'static> {
.long("--config")
.hide(true)
.takes_value(true)
.require_equals(true)
.help("the other case to test"),
)
.arg(
clap::Arg::new("path")
.takes_value(true)
.require_equals(true),
.multiple_occurrences(true),
),
)
.subcommand(clap::Command::new("some-cmd-with-hyphens").alias("hyphen"))
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/snapshots/special_commands.bash.log
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ _my-app() {
return 0
;;
my__app__some_cmd)
opts="-h -V --config --help --version <path>"
opts="-h -V --config --help --version <path>..."
if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/snapshots/special_commands.zsh.log
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 Down
16 changes: 8 additions & 8 deletions clap_complete_fig/src/fig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ fn gen_fig_inner(

let args = cmd.get_positionals().collect::<Vec<_>>();

if args.iter().any(|&x| x.is_require_equals_set()) {
buffer.push_str(&format!(
"{:indent$}requireEquals: true,\n",
"",
indent = indent
));
}

match args.len() {
0 => {}
1 => {
Expand Down Expand Up @@ -210,6 +202,14 @@ fn gen_options(cmd: &Command, indent: usize) -> String {
));
}

if option.is_require_equals_set() {
buffer.push_str(&format!(
"{:indent$}requiresEquals: true,\n",
"",
indent = indent + 4
));
}

buffer.push_str(&format!("{:indent$}args: ", "", indent = indent + 4));

buffer.push_str(&gen_args(option, indent + 4));
Expand Down
3 changes: 2 additions & 1 deletion clap_complete_fig/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ pub fn special_commands_command(name: &'static str) -> clap::Command<'static> {
.long("--config")
.hide(true)
.takes_value(true)
.require_equals(true)
.help("the other case to test"),
)
.arg(
clap::Arg::new("path")
.takes_value(true)
.require_equals(true),
.multiple_occurrences(true),
),
)
.subcommand(clap::Command::new("some-cmd-with-hyphens").alias("hyphen"))
Expand Down
2 changes: 1 addition & 1 deletion clap_complete_fig/tests/snapshots/special_commands.fig.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const completion: Fig.Spec = {
name: "--config",
description: "the other case to test",
hidden: true,
requiresEquals: true,
args: {
name: "config",
isOptional: true,
Expand All @@ -46,7 +47,6 @@ const completion: Fig.Spec = {
description: "Print version information",
},
],
requireEquals: true,
args: {
name: "path",
isOptional: true,
Expand Down

0 comments on commit 5689adc

Please sign in to comment.