From 5689adc875e55edc32dcdc301b363b4262339c16 Mon Sep 17 00:00:00 2001 From: Federico Ciardi Date: Fri, 18 Mar 2022 14:46:20 +0100 Subject: [PATCH] fix(clap_complete_fig): Correct `requiresEquals` name and add it to the right objects --- clap_complete/tests/common.rs | 3 ++- .../tests/snapshots/special_commands.bash.log | 2 +- .../tests/snapshots/special_commands.zsh.log | 2 +- clap_complete_fig/src/fig.rs | 16 ++++++++-------- clap_complete_fig/tests/common.rs | 3 ++- .../tests/snapshots/special_commands.fig.js | 2 +- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/clap_complete/tests/common.rs b/clap_complete/tests/common.rs index 54c8633d..3fd22100 100644 --- a/clap_complete/tests/common.rs +++ b/clap_complete/tests/common.rs @@ -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")) diff --git a/clap_complete/tests/snapshots/special_commands.bash.log b/clap_complete/tests/snapshots/special_commands.bash.log index b941350a..33f99ad0 100644 --- a/clap_complete/tests/snapshots/special_commands.bash.log +++ b/clap_complete/tests/snapshots/special_commands.bash.log @@ -90,7 +90,7 @@ _my-app() { return 0 ;; my__app__some_cmd) - opts="-h -V --config --help --version " + opts="-h -V --config --help --version ..." if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 diff --git a/clap_complete/tests/snapshots/special_commands.zsh.log b/clap_complete/tests/snapshots/special_commands.zsh.log index 07338475..c906b334 100644 --- a/clap_complete/tests/snapshots/special_commands.zsh.log +++ b/clap_complete/tests/snapshots/special_commands.zsh.log @@ -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) diff --git a/clap_complete_fig/src/fig.rs b/clap_complete_fig/src/fig.rs index 107c8ba1..de6e7a78 100644 --- a/clap_complete_fig/src/fig.rs +++ b/clap_complete_fig/src/fig.rs @@ -96,14 +96,6 @@ fn gen_fig_inner( let args = cmd.get_positionals().collect::>(); - 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 => { @@ -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)); diff --git a/clap_complete_fig/tests/common.rs b/clap_complete_fig/tests/common.rs index 54c8633d..3fd22100 100644 --- a/clap_complete_fig/tests/common.rs +++ b/clap_complete_fig/tests/common.rs @@ -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")) diff --git a/clap_complete_fig/tests/snapshots/special_commands.fig.js b/clap_complete_fig/tests/snapshots/special_commands.fig.js index c903a1a8..3c50ece8 100644 --- a/clap_complete_fig/tests/snapshots/special_commands.fig.js +++ b/clap_complete_fig/tests/snapshots/special_commands.fig.js @@ -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, @@ -46,7 +47,6 @@ const completion: Fig.Spec = { description: "Print version information", }, ], - requireEquals: true, args: { name: "path", isOptional: true,