diff --git a/examples/tutorial_builder/03_03_positional_mult.rs b/examples/tutorial_builder/03_03_positional_mult.rs index bcd288d8dc1..a4d620513df 100644 --- a/examples/tutorial_builder/03_03_positional_mult.rs +++ b/examples/tutorial_builder/03_03_positional_mult.rs @@ -2,7 +2,7 @@ use clap::{command, Arg, ArgAction}; fn main() { let matches = command!() // requires `cargo` feature - .arg(Arg::new("name").action(ArgAction::Append)) + .arg(Arg::new("name").num_args(1..).action(ArgAction::Append)) .get_matches(); let args = matches diff --git a/src/parser/parser.rs b/src/parser/parser.rs index dc99e32ece6..ebf6b2d9444 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -406,6 +406,19 @@ impl<'cmd> Parser<'cmd> { _parse_result ); } else { + if let Some(length_range) = arg.get_num_args() { + if length_range.max_values() == 1 + && matcher.args.get(arg.get_id()).is_some() + { + return Err(ClapError::unknown_argument( + self.cmd, + arg_os.display().to_string(), + None, + true, + Usage::new(self.cmd).create_usage_with_title(&[]), + )); + } + } let arg_values = matcher.pending_values_mut( arg.get_id(), Some(Identifier::Index),