@@ -188,6 +188,23 @@ impl ArgGroup {
188
188
self
189
189
}
190
190
191
+ /// Getters for all args. It will return a vector of `Id`
192
+ ///
193
+ /// # Example
194
+ ///
195
+ /// ```rust
196
+ /// # use clap::{ArgGroup};
197
+ /// let args: Vec<&str> = vec!["a1".into(), "a4".into()];
198
+ /// let grp = ArgGroup::new("program").args(&args);
199
+ ///
200
+ /// for (pos, arg) in grp.get_args().enumerate() {
201
+ /// assert_eq!(*arg, args[pos]);
202
+ /// }
203
+ /// ```
204
+ pub fn get_args ( & self ) -> impl Iterator < Item = & Id > {
205
+ self . args . iter ( )
206
+ }
207
+
191
208
/// Allows more than one of the [`Arg`]s in this group to be used. (Default: `false`)
192
209
///
193
210
/// # Examples
@@ -240,6 +257,23 @@ impl ArgGroup {
240
257
self
241
258
}
242
259
260
+ /// Return true if the group allows more than one of the arguments
261
+ /// in this group to be used. (Default: `false`)
262
+ ///
263
+ /// # Example
264
+ ///
265
+ /// ```rust
266
+ /// # use clap::{ArgGroup};
267
+ /// let mut group = ArgGroup::new("myprog")
268
+ /// .args(["f", "c"])
269
+ /// .multiple(true);
270
+ ///
271
+ /// assert!(group.is_multiple());
272
+ /// ```
273
+ pub fn is_multiple ( & mut self ) -> bool {
274
+ self . multiple
275
+ }
276
+
243
277
/// Require an argument from the group to be present when parsing.
244
278
///
245
279
/// This is unless conflicting with another argument. A required group will be displayed in
@@ -538,4 +572,25 @@ mod test {
538
572
fn foo < T : Send + Sync > ( _: T ) { }
539
573
foo ( ArgGroup :: new ( "test" ) )
540
574
}
575
+
576
+ #[ test]
577
+ fn arg_group_expose_is_multiple_helper ( ) {
578
+ let args: Vec < Id > = vec ! [ "a1" . into( ) , "a4" . into( ) ] ;
579
+
580
+ let mut grp_multiple = ArgGroup :: new ( "test_multiple" ) . args ( & args) . multiple ( true ) ;
581
+ assert ! ( grp_multiple. is_multiple( ) ) ;
582
+
583
+ let mut grp_not_multiple = ArgGroup :: new ( "test_multiple" ) . args ( & args) . multiple ( false ) ;
584
+ assert ! ( !grp_not_multiple. is_multiple( ) ) ;
585
+ }
586
+
587
+ #[ test]
588
+ fn arg_group_expose_get_args_helper ( ) {
589
+ let args: Vec < Id > = vec ! [ "a1" . into( ) , "a4" . into( ) ] ;
590
+ let grp = ArgGroup :: new ( "program" ) . args ( & args) ;
591
+
592
+ for ( pos, arg) in grp. get_args ( ) . enumerate ( ) {
593
+ assert_eq ! ( * arg, args[ pos] ) ;
594
+ }
595
+ }
541
596
}
0 commit comments