feat(builder): Infer takes_vaue from action

This commit is contained in:
Ed Page 2022-05-31 16:04:02 -05:00
parent 91480de6d2
commit e53dd937be
2 changed files with 7 additions and 2 deletions

View file

@ -35,7 +35,6 @@ pub enum ArgAction {
/// .arg( /// .arg(
/// Arg::new("flag") /// Arg::new("flag")
/// .long("flag") /// .long("flag")
/// .takes_value(true)
/// .action(clap::builder::ArgAction::StoreValue) /// .action(clap::builder::ArgAction::StoreValue)
/// ); /// );
/// ///

View file

@ -1014,7 +1014,6 @@ impl<'help> Arg<'help> {
/// .arg( /// .arg(
/// Arg::new("flag") /// Arg::new("flag")
/// .long("flag") /// .long("flag")
/// .takes_value(true)
/// .action(clap::builder::ArgAction::StoreValue) /// .action(clap::builder::ArgAction::StoreValue)
/// ); /// );
/// ///
@ -4892,6 +4891,13 @@ impl<'help> Arg<'help> {
if self.is_positional() { if self.is_positional() {
self.settings.set(ArgSettings::TakesValue); 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.value_parser.is_none() {
if self.is_allow_invalid_utf8_set() { if self.is_allow_invalid_utf8_set() {