mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
Merge pull request #5037 from epage/term
fix(parser): Value terminator has higher precedence than later multiple values
This commit is contained in:
commit
5540d20286
2 changed files with 34 additions and 1 deletions
|
@ -302,6 +302,13 @@ impl<'cmd> Parser<'cmd> {
|
|||
.map(|p_name| !p_name.is_last_set())
|
||||
.unwrap_or_default();
|
||||
|
||||
let is_terminated = self
|
||||
.cmd
|
||||
.get_keymap()
|
||||
.get(&pos_counter)
|
||||
.map(|a| a.get_value_terminator().is_some())
|
||||
.unwrap_or_default();
|
||||
|
||||
let missing_pos = self.cmd.is_allow_missing_positional_set()
|
||||
&& is_second_to_last
|
||||
&& !trailing_values;
|
||||
|
@ -309,7 +316,7 @@ impl<'cmd> Parser<'cmd> {
|
|||
debug!("Parser::get_matches_with: Positional counter...{pos_counter}");
|
||||
debug!("Parser::get_matches_with: Low index multiples...{low_index_mults:?}");
|
||||
|
||||
if low_index_mults || missing_pos {
|
||||
if (low_index_mults || missing_pos) && !is_terminated {
|
||||
let skip_current = if let Some(n) = raw_args.peek(&args_cursor) {
|
||||
if let Some(arg) = self
|
||||
.cmd
|
||||
|
|
|
@ -1375,6 +1375,32 @@ fn multiple_value_terminator_option_other_arg() {
|
|||
assert!(*m.get_one::<bool>("flag").expect("defaulted by clap"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_multiple_value_terminator() {
|
||||
let m = Command::new("lip")
|
||||
.arg(
|
||||
Arg::new("files")
|
||||
.value_terminator(";")
|
||||
.action(ArgAction::Set)
|
||||
.num_args(0..),
|
||||
)
|
||||
.arg(Arg::new("other").num_args(0..))
|
||||
.try_get_matches_from(vec!["test", "value", ";"]);
|
||||
|
||||
assert!(m.is_ok(), "{:?}", m.unwrap_err().kind());
|
||||
let m = m.unwrap();
|
||||
|
||||
assert!(m.contains_id("files"));
|
||||
assert!(!m.contains_id("other"));
|
||||
assert_eq!(
|
||||
m.get_many::<String>("files")
|
||||
.unwrap()
|
||||
.map(|v| v.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
["value".to_owned()],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_vals_with_hyphen() {
|
||||
let res = Command::new("do")
|
||||
|
|
Loading…
Reference in a new issue