mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 06:12:40 +00:00
fix(derive): Make Command::allow_hyphen_values forward to Arg
This commit is contained in:
parent
fd9a5a1d50
commit
7a2bbca62b
3 changed files with 10 additions and 13 deletions
|
@ -3818,6 +3818,14 @@ impl Command {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
if self.is_allow_hyphen_values_set() {
|
||||
for arg in self.args.args_mut() {
|
||||
if arg.is_takes_value_set() {
|
||||
arg.settings.insert(ArgSettings::AllowHyphenValues.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
assert_app(self);
|
||||
|
|
|
@ -634,8 +634,7 @@ impl<'cmd> Parser<'cmd> {
|
|||
current_positional.get_id()
|
||||
);
|
||||
|
||||
if self.cmd.is_allow_hyphen_values_set()
|
||||
|| self.cmd[¤t_positional.id].is_allow_hyphen_values_set()
|
||||
if self.cmd[¤t_positional.id].is_allow_hyphen_values_set()
|
||||
|| (self.cmd.is_allow_negative_numbers_set() && next.is_number())
|
||||
{
|
||||
// If allow hyphen, this isn't a new arg.
|
||||
|
@ -807,9 +806,6 @@ impl<'cmd> Parser<'cmd> {
|
|||
}
|
||||
} else if let Some(sc_name) = self.possible_long_flag_subcommand(long_arg) {
|
||||
Ok(ParseResult::FlagSubCommand(sc_name.to_string()))
|
||||
} else if self.cmd.is_allow_hyphen_values_set() {
|
||||
debug!("Parser::parse_long_arg: contains non-long flag");
|
||||
Ok(ParseResult::MaybeHyphenValue)
|
||||
} else if self
|
||||
.cmd
|
||||
.get_keymap()
|
||||
|
@ -850,13 +846,6 @@ impl<'cmd> Parser<'cmd> {
|
|||
} else if self.cmd.is_allow_negative_numbers_set() && short_arg.is_number() {
|
||||
debug!("Parser::parse_short_arg: negative number");
|
||||
return Ok(ParseResult::MaybeHyphenValue);
|
||||
} else if self.cmd.is_allow_hyphen_values_set()
|
||||
&& short_arg
|
||||
.clone()
|
||||
.any(|c| !c.map(|c| self.cmd.contains_short(c)).unwrap_or_default())
|
||||
{
|
||||
debug!("Parser::parse_short_args: contains non-short flag");
|
||||
return Ok(ParseResult::MaybeHyphenValue);
|
||||
} else if self
|
||||
.cmd
|
||||
.get_keymap()
|
||||
|
|
|
@ -862,7 +862,7 @@ fn issue_1066_allow_leading_hyphen_and_unknown_args_option() {
|
|||
let res = Command::new("prog")
|
||||
.allow_hyphen_values(true)
|
||||
.arg(arg!(--"some-argument" <val>))
|
||||
.try_get_matches_from(vec!["prog", "-hello"]);
|
||||
.try_get_matches_from(vec!["prog", "-fish"]);
|
||||
|
||||
assert!(res.is_err());
|
||||
assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
|
||||
|
|
Loading…
Reference in a new issue