diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/clap_builder/src/builder/command.rs | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.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 | 71 |
1 files changed, 56 insertions, 15 deletions
diff --git a/vendor/clap_builder/src/builder/command.rs b/vendor/clap_builder/src/builder/command.rs index 34c04b425..799623581 100644 --- a/vendor/clap_builder/src/builder/command.rs +++ b/vendor/clap_builder/src/builder/command.rs @@ -11,11 +11,13 @@ use std::path::Path; // Internal use crate::builder::app_settings::{AppFlags, AppSettings}; use crate::builder::arg_settings::ArgSettings; +use crate::builder::ext::Extensions; use crate::builder::ArgAction; use crate::builder::IntoResettable; use crate::builder::PossibleValue; use crate::builder::Str; use crate::builder::StyledStr; +use crate::builder::Styles; use crate::builder::{Arg, ArgGroup, ArgPredicate}; use crate::error::ErrorKind; use crate::error::Result as ClapResult; @@ -90,8 +92,6 @@ pub struct Command { usage_name: Option<String>, help_str: Option<StyledStr>, disp_ord: Option<usize>, - term_w: Option<usize>, - max_w: Option<usize>, #[cfg(feature = "help")] template: Option<StyledStr>, settings: AppFlags, @@ -105,6 +105,7 @@ pub struct Command { subcommand_heading: Option<Str>, external_value_parser: Option<super::ValueParser>, long_help_exists: bool, + app_ext: Extensions, } /// # Basic API @@ -1080,6 +1081,30 @@ impl Command { } } + /// Sets the [`Styles`] for terminal output + /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// + /// **NOTE:** Default behaviour is [`Styles::default`]. + /// + /// # Examples + /// + /// ```no_run + /// # use clap_builder as clap; + /// # use clap::{Command, ColorChoice, builder::Styles}; + /// Command::new("myprog") + /// .styles(Styles::styled().usage(Default::default())) + /// .get_matches(); + /// ``` + #[cfg(feature = "color")] + #[inline] + #[must_use] + #[cfg(feature = "unstable-styles")] + pub fn styles(mut self, styles: Styles) -> Self { + self.app_ext.set(styles); + self + } + /// Sets the terminal width at which to wrap help messages. /// /// Using `0` will ignore terminal widths and use source formatting. @@ -1104,7 +1129,7 @@ impl Command { #[must_use] #[cfg(any(not(feature = "unstable-v5"), feature = "wrap_help"))] pub fn term_width(mut self, width: usize) -> Self { - self.term_w = Some(width); + self.app_ext.set(TermWidth(width)); self } @@ -1131,8 +1156,8 @@ impl Command { #[inline] #[must_use] #[cfg(any(not(feature = "unstable-v5"), feature = "wrap_help"))] - pub fn max_term_width(mut self, w: usize) -> Self { - self.max_w = Some(w); + pub fn max_term_width(mut self, width: usize) -> Self { + self.app_ext.set(MaxTermWidth(width)); self } @@ -1912,7 +1937,7 @@ impl Command { self } - /// Change the starting value for assigning future display orders for ags. + /// Change the starting value for assigning future display orders for args. /// /// This will be used for any arg that hasn't had [`Arg::display_order`] called. #[inline] @@ -3338,6 +3363,12 @@ impl Command { } } + /// Return the current `Styles` for the `Command` + #[inline] + pub fn get_styles(&self) -> &Styles { + self.app_ext.get().unwrap_or_default() + } + /// Iterate through the set of subcommands, getting a reference to each. #[inline] pub fn get_subcommands(&self) -> impl Iterator<Item = &Command> { @@ -3720,12 +3751,12 @@ impl Command { #[cfg(feature = "help")] pub(crate) fn get_term_width(&self) -> Option<usize> { - self.term_w + self.app_ext.get::<TermWidth>().map(|e| e.0) } #[cfg(feature = "help")] pub(crate) fn get_max_term_width(&self) -> Option<usize> { - self.max_w + self.app_ext.get::<MaxTermWidth>().map(|e| e.0) } pub(crate) fn get_keymap(&self) -> &MKeyMap { @@ -4190,8 +4221,7 @@ impl Command { sc.settings = sc.settings | self.g_settings; sc.g_settings = sc.g_settings | self.g_settings; - sc.term_w = self.term_w; - sc.max_w = self.max_w; + sc.app_ext.update(&self.app_ext); } } @@ -4322,9 +4352,9 @@ impl Command { .collect::<Vec<_>>() .join("|"); let mut styled = StyledStr::new(); - styled.none("<"); - styled.none(g_string); - styled.none(">"); + styled.push_str("<"); + styled.push_string(g_string); + styled.push_str(">"); styled } } @@ -4612,8 +4642,6 @@ impl Default for Command { usage_name: Default::default(), help_str: Default::default(), disp_ord: Default::default(), - term_w: Default::default(), - max_w: Default::default(), #[cfg(feature = "help")] template: Default::default(), settings: Default::default(), @@ -4627,6 +4655,7 @@ impl Default for Command { subcommand_heading: Default::default(), external_value_parser: Default::default(), long_help_exists: false, + app_ext: Default::default(), } } } @@ -4651,6 +4680,18 @@ impl fmt::Display for Command { } } +pub(crate) trait AppTag: crate::builder::ext::Extension {} + +#[derive(Default, Copy, Clone, Debug)] +struct TermWidth(usize); + +impl AppTag for TermWidth {} + +#[derive(Default, Copy, Clone, Debug)] +struct MaxTermWidth(usize); + +impl AppTag for MaxTermWidth {} + fn two_elements_of<I, T>(mut iter: I) -> Option<(T, T)> where I: Iterator<Item = T>, |