From e53dd937bee8bc96f617ded67b01355d288727b9 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 31 May 2022 16:04:02 -0500 Subject: [PATCH] feat(builder): Infer takes_vaue from action --- src/builder/action.rs | 1 - src/builder/arg.rs | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/builder/action.rs b/src/builder/action.rs index f83e62d1..0f58738d 100644 --- a/src/builder/action.rs +++ b/src/builder/action.rs @@ -35,7 +35,6 @@ pub enum ArgAction { /// .arg( /// Arg::new("flag") /// .long("flag") - /// .takes_value(true) /// .action(clap::builder::ArgAction::StoreValue) /// ); /// diff --git a/src/builder/arg.rs b/src/builder/arg.rs index fa4e870a..d8892cef 100644 --- a/src/builder/arg.rs +++ b/src/builder/arg.rs @@ -1014,7 +1014,6 @@ impl<'help> Arg<'help> { /// .arg( /// Arg::new("flag") /// .long("flag") - /// .takes_value(true) /// .action(clap::builder::ArgAction::StoreValue) /// ); /// @@ -4892,6 +4891,13 @@ impl<'help> Arg<'help> { if self.is_positional() { self.settings.set(ArgSettings::TakesValue); } + if let Some(action) = self.action.as_ref() { + if action.takes_value() { + self.settings.set(ArgSettings::TakesValue); + } else { + self.settings.unset(ArgSettings::TakesValue); + } + } if self.value_parser.is_none() { if self.is_allow_invalid_utf8_set() {