From 1dd1056cd7f989deca3c2bc2f61f6fb571dbb6ee Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sat, 6 Jul 2024 17:45:12 +0000 Subject: [PATCH] fix: Check for real optional arguments --- clap_complete/src/shells/fish.rs | 7 ++++++- .../exhaustive/fish/fish/completions/exhaustive.fish | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clap_complete/src/shells/fish.rs b/clap_complete/src/shells/fish.rs index 65f49b73409..31a6c88a1f5 100644 --- a/clap_complete/src/shells/fish.rs +++ b/clap_complete/src/shells/fish.rs @@ -231,7 +231,12 @@ fn gen_subcommand_helpers( } optspecs.push_str(&escape_string(long, false)); } - if option.is_required_set() { + + let is_an_option = option + .get_num_args() + .map(|r| r.takes_values()) + .unwrap_or(true); + if is_an_option { optspecs.push('='); } } diff --git a/clap_complete/tests/snapshots/home/static/exhaustive/fish/fish/completions/exhaustive.fish b/clap_complete/tests/snapshots/home/static/exhaustive/fish/fish/completions/exhaustive.fish index c5e0689aee7..a5bb92fbd11 100644 --- a/clap_complete/tests/snapshots/home/static/exhaustive/fish/fish/completions/exhaustive.fish +++ b/clap_complete/tests/snapshots/home/static/exhaustive/fish/fish/completions/exhaustive.fish @@ -1,6 +1,6 @@ # Print an optspec for argparse to handle cmd's options that are independent of any subcommand. function __fish_exhaustive_global_optspecs - string join \n global generate h/help V/version + string join \n global generate= h/help V/version end function __fish_exhaustive_needs_command