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 e43620b
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/builder/arg_group.rs
Expand Up @@ -240,6 +240,21 @@ impl ArgGroup {
self
}

/// Return true if the group allows more than one of the arguments
/// 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 +553,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!(!grp_not_multiple.is_multiple());
}
}

0 comments on commit e43620b

Please sign in to comment.