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() {