Skip to content

Commit

Permalink
feat: expose is_multiple API for ArgGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-go committed Oct 3, 2022
1 parent f1fe570 commit 47925fd
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/builder/arg_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,22 @@ impl ArgGroup {
self
}

/// Return true if the group allows more than one of the [`Arg`]s
/// in this group to be used. (Default: `false`)
///
/// ```rust
/// # use clap::{ArgGroup};
/// let mut group = ArgGroup::new("myprog")
/// .args(["f", "c"])
/// .multiple(true);
///
/// assert!(group.is_multiple());
/// # ;
/// ```
pub fn is_multiple(&mut self) -> bool {
self.multiple
}

/// Require an argument from the group to be present when parsing.
///
/// This is unless conflicting with another argument. A required group will be displayed in
Expand Down Expand Up @@ -538,4 +554,15 @@ mod test {
fn foo<T: Send + Sync>(_: T) {}
foo(ArgGroup::new("test"))
}

#[test]
fn arg_group_expose_is_multiple_helper() {
let args: Vec<Id> = vec!["a1".into(), "a4".into()];

let mut grp_multiple = ArgGroup::new("test_multiple").args(&args).multiple(true);
assert!(grp_multiple.is_multiple());

let mut grp_not_multiple = ArgGroup::new("test_multiple").args(&args).multiple(false);
assert_eq!(grp_not_multiple.is_multiple(), false);
}
}

0 comments on commit 47925fd

Please sign in to comment.