From e43620b1365cb01be40887459c9f16e755ca9ca2 Mon Sep 17 00:00:00 2001 From: Tony Gorez Date: Mon, 3 Oct 2022 05:40:21 +0100 Subject: [PATCH] feat: Expose is_multiple API for ArgGroup --- src/builder/arg_group.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/builder/arg_group.rs b/src/builder/arg_group.rs index 459cc7f5337..9242c7f1ec5 100644 --- a/src/builder/arg_group.rs +++ b/src/builder/arg_group.rs @@ -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 @@ -538,4 +553,15 @@ mod test { fn foo(_: T) {} foo(ArgGroup::new("test")) } + + #[test] + fn arg_group_expose_is_multiple_helper() { + let args: Vec = 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()); + } }