@@ -298,6 +298,45 @@ impl Command {
298
298
self
299
299
}
300
300
301
+ /// Allows one to mutate an [`ArgGroup`] after it's been added to a [`Command`].
302
+ ///
303
+ /// # Panics
304
+ ///
305
+ /// If the argument is undefined
306
+ ///
307
+ /// # Examples
308
+ ///
309
+ /// ```rust
310
+ /// # use clap_builder as clap;
311
+ /// # use clap::{Command, arg, ArgGroup};
312
+ ///
313
+ /// Command::new("foo")
314
+ /// .arg(arg!(--"set-ver" <ver> "set the version manually").required(false))
315
+ /// .arg(arg!(--major "auto increase major"))
316
+ /// .arg(arg!(--minor "auto increase minor"))
317
+ /// .arg(arg!(--patch "auto increase patch"))
318
+ /// .group(ArgGroup::new("vers")
319
+ /// .args(["set-ver", "major", "minor","patch"])
320
+ /// .required(true))
321
+ /// .mut_group("vers", |a| a.required(false));
322
+ /// ```
323
+ #[ must_use]
324
+ #[ cfg_attr( debug_assertions, track_caller) ]
325
+ pub fn mut_group < F > ( mut self , arg_id : impl AsRef < str > , f : F ) -> Self
326
+ where
327
+ F : FnOnce ( ArgGroup ) -> ArgGroup ,
328
+ {
329
+ let id = arg_id. as_ref ( ) ;
330
+ let index = self
331
+ . groups
332
+ . iter ( )
333
+ . position ( |g| g. get_id ( ) == id)
334
+ . unwrap_or_else ( || panic ! ( "Group `{id}` is undefined" ) ) ;
335
+ let a = self . groups . remove ( index) ;
336
+
337
+ self . groups . push ( f ( a) ) ;
338
+ self
339
+ }
301
340
/// Allows one to mutate a [`Command`] after it's been added as a subcommand.
302
341
///
303
342
/// This can be useful for modifying auto-generated arguments of nested subcommands with
0 commit comments