diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:36 +0000 |
commit | e02c5b5930c2c9ba3e5423fe12e2ef0155017297 (patch) | |
tree | fd60ebbbb5299e16e5fca8c773ddb74f764760db /vendor/clap_builder/src/builder/command.rs | |
parent | Adding debian version 1.73.0+dfsg1-1. (diff) | |
download | rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.tar.xz rustc-e02c5b5930c2c9ba3e5423fe12e2ef0155017297.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/clap_builder/src/builder/command.rs')
-rw-r--r-- | vendor/clap_builder/src/builder/command.rs | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/vendor/clap_builder/src/builder/command.rs b/vendor/clap_builder/src/builder/command.rs index b2efdbc7e..b1623cf8c 100644 --- a/vendor/clap_builder/src/builder/command.rs +++ b/vendor/clap_builder/src/builder/command.rs @@ -252,6 +252,52 @@ impl Command { self } + /// Allows one to mutate all [`Arg`]s after they've been added to a [`Command`]. + /// + /// This does not affect the built-in `--help` or `--version` arguments. + /// + /// # Examples + /// + #[cfg_attr(feature = "string", doc = "```")] + #[cfg_attr(not(feature = "string"), doc = "```ignore")] + /// # use clap_builder as clap; + /// # use clap::{Command, Arg, ArgAction}; + /// + /// let mut cmd = Command::new("foo") + /// .arg(Arg::new("bar") + /// .long("bar") + /// .action(ArgAction::SetTrue)) + /// .arg(Arg::new("baz") + /// .long("baz") + /// .action(ArgAction::SetTrue)) + /// .mut_args(|a| { + /// if let Some(l) = a.get_long().map(|l| format!("prefix-{l}")) { + /// a.long(l) + /// } else { + /// a + /// } + /// }); + /// + /// let res = cmd.try_get_matches_from_mut(vec!["foo", "--bar"]); + /// + /// // Since we changed `bar`'s long to "prefix-bar" this should err as there + /// // is no `--bar` anymore, only `--prefix-bar`. + /// + /// assert!(res.is_err()); + /// + /// let res = cmd.try_get_matches_from_mut(vec!["foo", "--prefix-bar"]); + /// assert!(res.is_ok()); + /// ``` + #[must_use] + #[cfg_attr(debug_assertions, track_caller)] + pub fn mut_args<F>(mut self, f: F) -> Self + where + F: FnMut(Arg) -> Arg, + { + self.args.mut_args(f); + self + } + /// Allows one to mutate a [`Command`] after it's been added as a subcommand. /// /// This can be useful for modifying auto-generated arguments of nested subcommands with @@ -507,7 +553,7 @@ impl Command { /// /// # Panics /// - /// If contradictory arguments or settings exist. + /// If contradictory arguments or settings exist (debug builds). /// /// # Examples /// @@ -531,7 +577,7 @@ impl Command { /// /// # Panics /// - /// If contradictory arguments or settings exist. + /// If contradictory arguments or settings exist (debug builds). /// /// # Examples /// @@ -559,7 +605,7 @@ impl Command { /// /// # Panics /// - /// If contradictory arguments or settings exist. + /// If contradictory arguments or settings exist (debug builds). /// /// # Examples /// @@ -592,7 +638,7 @@ impl Command { /// /// # Panics /// - /// If contradictory arguments or settings exist. + /// If contradictory arguments or settings exist (debug builds). /// /// # Examples /// @@ -631,7 +677,7 @@ impl Command { /// /// # Panics /// - /// If contradictory arguments or settings exist. + /// If contradictory arguments or settings exist (debug builds). /// /// # Examples /// @@ -677,7 +723,7 @@ impl Command { /// /// # Panics /// - /// If contradictory arguments or settings exist. + /// If contradictory arguments or settings exist (debug builds). /// /// # Examples /// @@ -1124,7 +1170,6 @@ impl Command { #[cfg(feature = "color")] #[inline] #[must_use] - #[cfg(feature = "unstable-styles")] pub fn styles(mut self, styles: Styles) -> Self { self.app_ext.set(styles); self @@ -1369,6 +1414,7 @@ impl Command { /// /// # Panics /// + /// On debug builds: /// ```rust,no_run /// # use clap_builder as clap; /// # use clap::{Command, Arg}; |