diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:26:03 +0000 |
commit | 9918693037dce8aa4bb6f08741b6812923486c18 (patch) | |
tree | 21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/clap_builder/src/builder | |
parent | Releasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff) | |
download | rustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/clap_builder/src/builder')
-rw-r--r-- | vendor/clap_builder/src/builder/app_settings.rs | 1 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/arg.rs | 4 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/command.rs | 84 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/styled_str.rs | 4 |
4 files changed, 85 insertions, 8 deletions
diff --git a/vendor/clap_builder/src/builder/app_settings.rs b/vendor/clap_builder/src/builder/app_settings.rs index 4fce4b4a2..f9a87dadc 100644 --- a/vendor/clap_builder/src/builder/app_settings.rs +++ b/vendor/clap_builder/src/builder/app_settings.rs @@ -57,6 +57,7 @@ pub(crate) enum AppSettings { SubcommandsNegateReqs, ArgsNegateSubcommands, SubcommandPrecedenceOverArg, + FlattenHelp, ArgRequiredElseHelp, NextLineHelp, DisableColoredHelp, diff --git a/vendor/clap_builder/src/builder/arg.rs b/vendor/clap_builder/src/builder/arg.rs index 8e247c176..f83b4642c 100644 --- a/vendor/clap_builder/src/builder/arg.rs +++ b/vendor/clap_builder/src/builder/arg.rs @@ -875,7 +875,7 @@ impl Arg { impl Arg { /// Specify how to react to an argument when parsing it. /// - /// [ArgAction][crate::ArgAction] controls things like + /// [ArgAction] controls things like /// - Overwriting previous values with new ones /// - Appending new values to all previous ones /// - Counting how many times a flag occurs @@ -1260,7 +1260,7 @@ impl Arg { /// Provide the shell a hint about how to complete this argument. /// - /// See [`ValueHint`][crate::ValueHint] for more information. + /// See [`ValueHint`] for more information. /// /// **NOTE:** implicitly sets [`Arg::action(ArgAction::Set)`]. /// diff --git a/vendor/clap_builder/src/builder/command.rs b/vendor/clap_builder/src/builder/command.rs index edcbace76..6e56b1834 100644 --- a/vendor/clap_builder/src/builder/command.rs +++ b/vendor/clap_builder/src/builder/command.rs @@ -298,6 +298,45 @@ impl Command { self } + /// Allows one to mutate an [`ArgGroup`] after it's been added to a [`Command`]. + /// + /// # Panics + /// + /// If the argument is undefined + /// + /// # Examples + /// + /// ```rust + /// # use clap_builder as clap; + /// # use clap::{Command, arg, ArgGroup}; + /// + /// Command::new("foo") + /// .arg(arg!(--"set-ver" <ver> "set the version manually").required(false)) + /// .arg(arg!(--major "auto increase major")) + /// .arg(arg!(--minor "auto increase minor")) + /// .arg(arg!(--patch "auto increase patch")) + /// .group(ArgGroup::new("vers") + /// .args(["set-ver", "major", "minor","patch"]) + /// .required(true)) + /// .mut_group("vers", |a| a.required(false)); + /// ``` + #[must_use] + #[cfg_attr(debug_assertions, track_caller)] + pub fn mut_group<F>(mut self, arg_id: impl AsRef<str>, f: F) -> Self + where + F: FnOnce(ArgGroup) -> ArgGroup, + { + let id = arg_id.as_ref(); + let index = self + .groups + .iter() + .position(|g| g.get_id() == id) + .unwrap_or_else(|| panic!("Group `{id}` is undefined")); + let a = self.groups.remove(index); + + self.groups.push(f(a)); + 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 @@ -1070,7 +1109,7 @@ impl Command { /// Replace prior occurrences of arguments rather than error /// /// For any argument that would conflict with itself by default (e.g. - /// [`ArgAction::Set`][ArgAction::Set], it will now override itself. + /// [`ArgAction::Set`], it will now override itself. /// /// This is the equivalent to saying the `foo` arg using [`Arg::overrides_with("foo")`] for all /// defined arguments. @@ -1359,7 +1398,7 @@ impl Command { /// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument); /// ``` /// - /// You can create a custom version flag with [`ArgAction::Help`], [`ArgAction::HelpShort`], or + /// You can create a custom help flag with [`ArgAction::Help`], [`ArgAction::HelpShort`], or /// [`ArgAction::HelpLong`] /// ```rust /// # use clap_builder as clap; @@ -2049,6 +2088,21 @@ impl Command { self } + /// Flatten subcommand help into the current command's help + /// + /// This shows a summary of subcommands within the usage and help for the current command, similar to + /// `git stash --help` showing information on `push`, `pop`, etc. + /// To see more information, a user can still pass `--help` to the individual subcommands. + #[inline] + #[must_use] + pub fn flatten_help(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::FlattenHelp) + } else { + self.unset_setting(AppSettings::FlattenHelp) + } + } + /// Set the default section heading for future args. /// /// This will be used for any arg that hasn't had [`Arg::help_heading`] called. @@ -3335,6 +3389,20 @@ impl Command { self.usage_name.as_deref() } + #[inline] + #[cfg(feature = "usage")] + pub(crate) fn get_usage_name_fallback(&self) -> &str { + self.get_usage_name() + .unwrap_or_else(|| self.get_bin_name_fallback()) + } + + #[inline] + #[cfg(not(feature = "usage"))] + #[allow(dead_code)] + pub(crate) fn get_usage_name_fallback(&self) -> &str { + self.get_bin_name_fallback() + } + /// Get the name of the binary. #[inline] pub fn get_display_name(&self) -> Option<&str> { @@ -3347,6 +3415,12 @@ impl Command { self.bin_name.as_deref() } + /// Get the name of the binary. + #[inline] + pub(crate) fn get_bin_name_fallback(&self) -> &str { + self.bin_name.as_deref().unwrap_or_else(|| self.get_name()) + } + /// Set binary name. Uses `&mut self` instead of `self`. pub fn set_bin_name(&mut self, name: impl Into<String>) { self.bin_name = Some(name.into()); @@ -3410,6 +3484,12 @@ impl Command { self.long_about.as_ref() } + /// Get the custom section heading specified via [`Command::flatten_help`]. + #[inline] + pub fn is_flatten_help_set(&self) -> bool { + self.is_set(AppSettings::FlattenHelp) + } + /// Get the custom section heading specified via [`Command::next_help_heading`]. /// /// [`Command::help_heading`]: Command::help_heading() diff --git a/vendor/clap_builder/src/builder/styled_str.rs b/vendor/clap_builder/src/builder/styled_str.rs index df0f1b03b..e06ddbc9e 100644 --- a/vendor/clap_builder/src/builder/styled_str.rs +++ b/vendor/clap_builder/src/builder/styled_str.rs @@ -45,10 +45,6 @@ impl StyledStr { self.0.push_str(msg); } - pub(crate) fn trim(&mut self) { - self.0 = self.0.trim().to_owned() - } - pub(crate) fn trim_start_lines(&mut self) { if let Some(pos) = self.0.find('\n') { let (leading, help) = self.0.split_at(pos + 1); |