diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/clap_builder/src/builder | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+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 | 147 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/arg.rs | 77 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/arg_settings.rs | 114 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/command.rs | 131 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/debug_asserts.rs | 30 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/possible_value.rs | 12 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/value_hint.rs | 9 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/value_parser.rs | 10 |
8 files changed, 193 insertions, 337 deletions
diff --git a/vendor/clap_builder/src/builder/app_settings.rs b/vendor/clap_builder/src/builder/app_settings.rs index 7a9ff8c69..4fce4b4a2 100644 --- a/vendor/clap_builder/src/builder/app_settings.rs +++ b/vendor/clap_builder/src/builder/app_settings.rs @@ -1,21 +1,35 @@ -// Std -use std::ops::BitOr; - #[allow(unused)] use crate::Arg; #[allow(unused)] use crate::Command; -// Third party -use bitflags::bitflags; +#[derive(Default, Copy, Clone, Debug, PartialEq, Eq)] +pub(crate) struct AppFlags(u32); + +impl AppFlags { + pub(crate) fn set(&mut self, setting: AppSettings) { + self.0 |= setting.bit(); + } + + pub(crate) fn unset(&mut self, setting: AppSettings) { + self.0 &= !setting.bit(); + } + + pub(crate) fn is_set(&self, setting: AppSettings) -> bool { + self.0 & setting.bit() != 0 + } + + pub(crate) fn insert(&mut self, other: Self) { + self.0 |= other.0; + } +} -#[doc(hidden)] -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub(crate) struct AppFlags(Flags); +impl std::ops::BitOr for AppFlags { + type Output = Self; -impl Default for AppFlags { - fn default() -> Self { - AppFlags(Flags::COLOR_AUTO) + fn bitor(mut self, rhs: Self) -> Self::Output { + self.insert(rhs); + self } } @@ -26,7 +40,7 @@ impl Default for AppFlags { /// /// [`Command`]: crate::Command #[derive(Debug, PartialEq, Copy, Clone)] -#[non_exhaustive] +#[repr(u8)] pub(crate) enum AppSettings { IgnoreErrors, AllowHyphenValues, @@ -62,111 +76,8 @@ pub(crate) enum AppSettings { BinNameBuilt, } -bitflags! { - struct Flags: u64 { - const SC_NEGATE_REQS = 1; - const SC_REQUIRED = 1 << 1; - const ARG_REQUIRED_ELSE_HELP = 1 << 2; - const PROPAGATE_VERSION = 1 << 3; - const DISABLE_VERSION_FOR_SC = 1 << 4; - const WAIT_ON_ERROR = 1 << 6; - const DISABLE_VERSION_FLAG = 1 << 10; - const HIDDEN = 1 << 11; - const TRAILING_VARARG = 1 << 12; - const NO_BIN_NAME = 1 << 13; - const ALLOW_UNK_SC = 1 << 14; - const LEADING_HYPHEN = 1 << 16; - const NO_POS_VALUES = 1 << 17; - const NEXT_LINE_HELP = 1 << 18; - const DISABLE_COLORED_HELP = 1 << 20; - const COLOR_ALWAYS = 1 << 21; - const COLOR_AUTO = 1 << 22; - const COLOR_NEVER = 1 << 23; - const DONT_DELIM_TRAIL = 1 << 24; - const ALLOW_NEG_NUMS = 1 << 25; - const DISABLE_HELP_SC = 1 << 27; - const ARGS_NEGATE_SCS = 1 << 29; - const PROPAGATE_VALS_DOWN = 1 << 30; - const ALLOW_MISSING_POS = 1 << 31; - const TRAILING_VALUES = 1 << 32; - const BUILT = 1 << 33; - const BIN_NAME_BUILT = 1 << 34; - const VALID_ARG_FOUND = 1 << 35; - const INFER_SUBCOMMANDS = 1 << 36; - const CONTAINS_LAST = 1 << 37; - const ARGS_OVERRIDE_SELF = 1 << 38; - const HELP_REQUIRED = 1 << 39; - const SUBCOMMAND_PRECEDENCE_OVER_ARG = 1 << 40; - const DISABLE_HELP_FLAG = 1 << 41; - const INFER_LONG_ARGS = 1 << 43; - const IGNORE_ERRORS = 1 << 44; - const MULTICALL = 1 << 45; - const EXPAND_HELP_SUBCOMMAND_TREES = 1 << 46; - const NO_OP = 0; +impl AppSettings { + fn bit(self) -> u32 { + 1 << (self as u8) } } - -impl_settings! { AppSettings, AppFlags, - ArgRequiredElseHelp - => Flags::ARG_REQUIRED_ELSE_HELP, - SubcommandPrecedenceOverArg - => Flags::SUBCOMMAND_PRECEDENCE_OVER_ARG, - ArgsNegateSubcommands - => Flags::ARGS_NEGATE_SCS, - AllowExternalSubcommands - => Flags::ALLOW_UNK_SC, - AllowHyphenValues - => Flags::LEADING_HYPHEN, - AllowNegativeNumbers - => Flags::ALLOW_NEG_NUMS, - AllowMissingPositional - => Flags::ALLOW_MISSING_POS, - ColorAlways - => Flags::COLOR_ALWAYS, - ColorAuto - => Flags::COLOR_AUTO, - ColorNever - => Flags::COLOR_NEVER, - DontDelimitTrailingValues - => Flags::DONT_DELIM_TRAIL, - DisableColoredHelp - => Flags::DISABLE_COLORED_HELP, - DisableHelpSubcommand - => Flags::DISABLE_HELP_SC, - DisableHelpFlag - => Flags::DISABLE_HELP_FLAG, - DisableVersionFlag - => Flags::DISABLE_VERSION_FLAG, - PropagateVersion - => Flags::PROPAGATE_VERSION, - HidePossibleValues - => Flags::NO_POS_VALUES, - HelpExpected - => Flags::HELP_REQUIRED, - Hidden - => Flags::HIDDEN, - Multicall - => Flags::MULTICALL, - NoBinaryName - => Flags::NO_BIN_NAME, - SubcommandsNegateReqs - => Flags::SC_NEGATE_REQS, - SubcommandRequired - => Flags::SC_REQUIRED, - TrailingVarArg - => Flags::TRAILING_VARARG, - NextLineHelp - => Flags::NEXT_LINE_HELP, - IgnoreErrors - => Flags::IGNORE_ERRORS, - Built - => Flags::BUILT, - BinNameBuilt - => Flags::BIN_NAME_BUILT, - InferSubcommands - => Flags::INFER_SUBCOMMANDS, - AllArgsOverrideSelf - => Flags::ARGS_OVERRIDE_SELF, - InferLongArgs - => Flags::INFER_LONG_ARGS -} diff --git a/vendor/clap_builder/src/builder/arg.rs b/vendor/clap_builder/src/builder/arg.rs index ce7e02d87..5bfea9ad4 100644 --- a/vendor/clap_builder/src/builder/arg.rs +++ b/vendor/clap_builder/src/builder/arg.rs @@ -858,21 +858,15 @@ impl Arg { #[inline] #[must_use] - pub(crate) fn setting<F>(mut self, setting: F) -> Self - where - F: Into<ArgFlags>, - { - self.settings.insert(setting.into()); + pub(crate) fn setting(mut self, setting: ArgSettings) -> Self { + self.settings.set(setting); self } #[inline] #[must_use] - pub(crate) fn unset_setting<F>(mut self, setting: F) -> Self - where - F: Into<ArgFlags>, - { - self.settings.remove(setting.into()); + pub(crate) fn unset_setting(mut self, setting: ArgSettings) -> Self { + self.settings.unset(setting); self } } @@ -1656,8 +1650,6 @@ impl Arg { /// at runtime, nor were the conditions met for `Arg::default_value_if`, the `Arg::default_value` /// will be applied. /// - /// **NOTE:** This implicitly sets [`Arg::action(ArgAction::Set)`]. - /// /// # Examples /// /// First we use the default value without providing any value at runtime. @@ -2177,12 +2169,15 @@ impl Arg { /// Allows custom ordering of args within the help message. /// - /// Args with a lower value will be displayed first in the help message. This is helpful when - /// one would like to emphasise frequently used args, or prioritize those towards the top of - /// the list. Args with duplicate display orders will be displayed in the order they are - /// defined. + /// `Arg`s with a lower value will be displayed first in the help message. + /// Those with the same display order will be sorted. + /// + /// `Arg`s are automatically assigned a display order based on the order they are added to the + /// [`Command`][crate::Command]. + /// Overriding this is helpful when the order arguments are added in isn't the same as the + /// display order, whether in one-off cases or to automatically sort arguments. /// - /// **NOTE:** The default is 999 for all arguments. + /// To change, see [`Command::next_display_order`][crate::Command::next_display_order]. /// /// **NOTE:** This setting is ignored for [positional arguments] which are always displayed in /// [index] order. @@ -2194,22 +2189,23 @@ impl Arg { /// # use clap_builder as clap; /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") - /// .arg(Arg::new("a") // Typically args are grouped alphabetically by name. - /// // Args without a display_order have a value of 999 and are - /// // displayed alphabetically with all other 999 valued args. - /// .long("long-option") - /// .short('o') + /// .arg(Arg::new("boat") + /// .short('b') + /// .long("boat") /// .action(ArgAction::Set) + /// .display_order(0) // Sort /// .help("Some help and text")) - /// .arg(Arg::new("b") - /// .long("other-option") - /// .short('O') + /// .arg(Arg::new("airplane") + /// .short('a') + /// .long("airplane") /// .action(ArgAction::Set) - /// .display_order(1) // In order to force this arg to appear *first* - /// // all we have to do is give it a value lower than 999. - /// // Any other args with a value of 1 will be displayed - /// // alphabetically with this one...then 2 values, then 3, etc. + /// .display_order(0) // Sort /// .help("I should be first!")) + /// .arg(Arg::new("custom-help") + /// .short('?') + /// .action(ArgAction::Help) + /// .display_order(100) // Don't sort + /// .help("Alt help")) /// .get_matches_from(vec![ /// "prog", "--help" /// ]); @@ -2224,10 +2220,10 @@ impl Arg { /// Usage: cust-ord [OPTIONS] /// /// Options: - /// -h, --help Print help information - /// -V, --version Print version information - /// -O, --other-option <b> I should be first! - /// -o, --long-option <a> Some help and text + /// -a, --airplane <airplane> I should be first! + /// -b, --boat <boar> Some help and text + /// -h, --help Print help information + /// -? Alt help /// ``` /// [positional arguments]: Arg::index() /// [index]: Arg::index() @@ -2738,8 +2734,6 @@ impl Arg { /// and `Arg::default_value_if`, and the user **did not** provide this arg at runtime, nor were /// the conditions met for `Arg::default_value_if`, the `Arg::default_value` will be applied. /// - /// **NOTE:** This implicitly sets [`Arg::action(ArgAction::Set)`]. - /// /// # Examples /// /// First we use the default value only if another arg is present at runtime. @@ -4107,7 +4101,7 @@ impl Arg { /// let value_parser = cmd.get_arguments() /// .find(|a| a.get_id() == "port").unwrap() /// .get_value_parser(); - /// println!("{:?}", value_parser); + /// println!("{value_parser:?}"); /// ``` pub fn get_value_parser(&self) -> &super::ValueParser { if let Some(value_parser) = self.value_parser.as_ref() { @@ -4793,15 +4787,4 @@ mod test { assert_eq!(p.to_string(), "<file1> <file2>"); } - - #[test] - fn positional_display_val_names_req() { - let mut p = Arg::new("pos") - .index(1) - .required(true) - .value_names(["file1", "file2"]); - p._build(); - - assert_eq!(p.to_string(), "<file1> <file2>"); - } } diff --git a/vendor/clap_builder/src/builder/arg_settings.rs b/vendor/clap_builder/src/builder/arg_settings.rs index b8bc069c5..fd4750404 100644 --- a/vendor/clap_builder/src/builder/arg_settings.rs +++ b/vendor/clap_builder/src/builder/arg_settings.rs @@ -1,18 +1,33 @@ -// Std -use std::ops::BitOr; - -// Third party -use bitflags::bitflags; - #[allow(unused)] use crate::Arg; -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub(crate) struct ArgFlags(Flags); +#[derive(Default, Copy, Clone, Debug, PartialEq, Eq)] +pub(crate) struct ArgFlags(u32); + +impl ArgFlags { + pub(crate) fn set(&mut self, setting: ArgSettings) { + self.0 |= setting.bit(); + } + + pub(crate) fn unset(&mut self, setting: ArgSettings) { + self.0 &= !setting.bit(); + } + + pub(crate) fn is_set(&self, setting: ArgSettings) -> bool { + self.0 & setting.bit() != 0 + } -impl Default for ArgFlags { - fn default() -> Self { - Self::empty() + pub(crate) fn insert(&mut self, other: Self) { + self.0 |= other.0; + } +} + +impl std::ops::BitOr for ArgFlags { + type Output = Self; + + fn bitor(mut self, rhs: Self) -> Self::Output { + self.insert(rhs); + self } } @@ -25,7 +40,7 @@ impl Default for ArgFlags { /// [`Arg::unset_setting`]: crate::Arg::unset_setting() /// [`Arg::is_set`]: crate::Arg::is_set() #[derive(Debug, PartialEq, Copy, Clone)] -#[non_exhaustive] +#[repr(u8)] pub(crate) enum ArgSettings { Required, Global, @@ -48,54 +63,12 @@ pub(crate) enum ArgSettings { Exclusive, } -bitflags! { - struct Flags: u32 { - const REQUIRED = 1; - const GLOBAL = 1 << 3; - const HIDDEN = 1 << 4; - const TRAILING_VARARG = 1 << 5; - const ALLOW_NEG_NUMS = 1 << 6; - const NEXT_LINE_HELP = 1 << 7; - const DELIM_NOT_SET = 1 << 10; - const HIDE_POS_VALS = 1 << 11; - const ALLOW_TAC_VALS = 1 << 12; - const REQUIRE_EQUALS = 1 << 13; - const LAST = 1 << 14; - const HIDE_DEFAULT_VAL = 1 << 15; - const CASE_INSENSITIVE = 1 << 16; - #[cfg(feature = "env")] - const HIDE_ENV_VALS = 1 << 17; - const HIDDEN_SHORT_H = 1 << 18; - const HIDDEN_LONG_H = 1 << 19; - #[cfg(feature = "env")] - const HIDE_ENV = 1 << 21; - const EXCLUSIVE = 1 << 23; - const NO_OP = 0; +impl ArgSettings { + fn bit(self) -> u32 { + 1 << (self as u8) } } -impl_settings! { ArgSettings, ArgFlags, - Required => Flags::REQUIRED, - Global => Flags::GLOBAL, - Hidden => Flags::HIDDEN, - NextLineHelp => Flags::NEXT_LINE_HELP, - HidePossibleValues => Flags::HIDE_POS_VALS, - AllowHyphenValues => Flags::ALLOW_TAC_VALS, - AllowNegativeNumbers => Flags::ALLOW_NEG_NUMS, - RequireEquals => Flags::REQUIRE_EQUALS, - Last => Flags::LAST, - TrailingVarArg => Flags::TRAILING_VARARG, - IgnoreCase => Flags::CASE_INSENSITIVE, - #[cfg(feature = "env")] - HideEnv => Flags::HIDE_ENV, - #[cfg(feature = "env")] - HideEnvValues => Flags::HIDE_ENV_VALS, - HideDefaultValue => Flags::HIDE_DEFAULT_VAL, - HiddenShortHelp => Flags::HIDDEN_SHORT_H, - HiddenLongHelp => Flags::HIDDEN_LONG_H, - Exclusive => Flags::EXCLUSIVE -} - #[cfg(test)] mod test { use super::*; @@ -115,31 +88,4 @@ mod test { let m = m.unset_setting(ArgSettings::Required); assert!(!m.is_required_set(), "{m:#?}"); } - - #[test] - fn setting_bitor() { - let m = Arg::new("setting_bitor") - .setting(ArgSettings::Required | ArgSettings::Hidden | ArgSettings::Last); - - assert!(m.is_required_set()); - assert!(m.is_hide_set()); - assert!(m.is_last_set()); - } - - #[test] - fn unset_setting_bitor() { - let m = Arg::new("unset_setting_bitor") - .setting(ArgSettings::Required) - .setting(ArgSettings::Hidden) - .setting(ArgSettings::Last); - - assert!(m.is_required_set()); - assert!(m.is_hide_set()); - assert!(m.is_last_set()); - - let m = m.unset_setting(ArgSettings::Required | ArgSettings::Hidden | ArgSettings::Last); - assert!(!m.is_required_set(), "{m:#?}"); - assert!(!m.is_hide_set(), "{m:#?}"); - assert!(!m.is_last_set(), "{m:#?}"); - } } diff --git a/vendor/clap_builder/src/builder/command.rs b/vendor/clap_builder/src/builder/command.rs index 799623581..2c5eb1989 100644 --- a/vendor/clap_builder/src/builder/command.rs +++ b/vendor/clap_builder/src/builder/command.rs @@ -105,6 +105,7 @@ pub struct Command { subcommand_heading: Option<Str>, external_value_parser: Option<super::ValueParser>, long_help_exists: bool, + deferred: Option<fn(Command) -> Command>, app_ext: Extensions, } @@ -209,8 +210,6 @@ impl Command { /// Allows one to mutate an [`Arg`] after it's been added to a [`Command`]. /// - /// This can be useful for modifying the auto-generated help or version arguments. - /// /// # Panics /// /// If the argument is undefined @@ -430,6 +429,30 @@ impl Command { self } + /// Delay initialization for parts of the `Command` + /// + /// This is useful for large applications to delay definitions of subcommands until they are + /// being invoked. + /// + /// # Examples + /// + /// ```rust + /// # use clap_builder as clap; + /// # use clap::{Command, arg}; + /// Command::new("myprog") + /// .subcommand(Command::new("config") + /// .about("Controls configuration features") + /// .defer(|cmd| { + /// cmd.arg(arg!(<config> "Required configuration file to use")) + /// }) + /// ) + /// # ; + /// ``` + pub fn defer(mut self, deferred: fn(Command) -> Command) -> Self { + self.deferred = Some(deferred); + self + } + /// Catch problems earlier in the development cycle. /// /// Most error states are handled as asserts under the assumption they are programming mistake @@ -686,10 +709,7 @@ impl Command { if let Some(command) = argv0.file_stem().and_then(|f| f.to_str()) { // Stop borrowing command so we can get another mut ref to it. let command = command.to_owned(); - debug!( - "Command::try_get_matches_from_mut: Parsed command {} from argv", - command - ); + debug!("Command::try_get_matches_from_mut: Parsed command {command} from argv"); debug!("Command::try_get_matches_from_mut: Reinserting command into arguments so subcommand parser matches it"); raw_args.insert(&cursor, [&command]); @@ -791,7 +811,7 @@ impl Command { /// let mut cmd = Command::new("myprog"); /// let mut out = io::stdout(); /// let help = cmd.render_help(); - /// println!("{}", help); + /// println!("{help}"); /// ``` /// [`io::Write`]: std::io::Write /// [`-h` (short)]: Arg::help() @@ -818,7 +838,7 @@ impl Command { /// let mut cmd = Command::new("myprog"); /// let mut out = io::stdout(); /// let help = cmd.render_long_help(); - /// println!("{}", help); + /// println!("{help}"); /// ``` /// [`io::Write`]: std::io::Write /// [`-h` (short)]: Arg::help() @@ -986,7 +1006,7 @@ impl Command { /// /// let r = cmd.try_get_matches_from(vec!["cmd", "-c", "file", "-f", "-x"]); /// - /// assert!(r.is_ok(), "unexpected error: {:?}", r); + /// assert!(r.is_ok(), "unexpected error: {r:?}"); /// let m = r.unwrap(); /// assert_eq!(m.get_one::<String>("config").unwrap(), "file"); /// assert!(m.get_flag("f")); @@ -1265,6 +1285,8 @@ impl Command { /// Disables the `help` [`subcommand`]. /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// /// # Examples /// /// ```rust @@ -1885,21 +1907,15 @@ impl Command { #[inline] #[must_use] - pub(crate) fn setting<F>(mut self, setting: F) -> Self - where - F: Into<AppFlags>, - { - self.settings.insert(setting.into()); + pub(crate) fn setting(mut self, setting: AppSettings) -> Self { + self.settings.set(setting); self } #[inline] #[must_use] - pub(crate) fn unset_setting<F>(mut self, setting: F) -> Self - where - F: Into<AppFlags>, - { - self.settings.remove(setting.into()); + pub(crate) fn unset_setting(mut self, setting: AppSettings) -> Self { + self.settings.unset(setting); self } @@ -2576,13 +2592,13 @@ impl Command { /// Set the placement of this subcommand within the help. /// - /// Subcommands with a lower value will be displayed first in the help message. Subcommands - /// with duplicate display orders will be displayed in order they are defined. - /// - /// This is helpful when one would like to emphasize frequently used subcommands, or prioritize - /// those towards the top of the list. + /// Subcommands with a lower value will be displayed first in the help message. + /// Those with the same display order will be sorted. /// - /// **NOTE:** The default is 999 for all subcommands. + /// `Command`s are automatically assigned a display order based on the order they are added to + /// their parent [`Command`]. + /// Overriding this is helpful when the order commands are added in isn't the same as the + /// display order, whether in one-off cases or to automatically sort commands. /// /// # Examples /// @@ -2591,17 +2607,11 @@ impl Command { /// # use clap_builder as clap; /// # use clap::{Command, }; /// let m = Command::new("cust-ord") - /// .subcommand(Command::new("alpha") // typically subcommands are grouped - /// // alphabetically by name. Subcommands - /// // without a display_order have a value of - /// // 999 and are displayed alphabetically with - /// // all other 999 subcommands - /// .about("Some help and text")) /// .subcommand(Command::new("beta") - /// .display_order(1) // In order to force this subcommand to appear *first* - /// // all we have to do is give it a value lower than 999. - /// // Any other subcommands with a value of 1 will be displayed - /// // alphabetically with this one...then 2 values, then 3, etc. + /// .display_order(0) // Sort + /// .about("Some help and text")) + /// .subcommand(Command::new("alpha") + /// .display_order(0) // Sort /// .about("I should be first!")) /// .get_matches_from(vec![ /// "cust-ord", "--help" @@ -2617,8 +2627,9 @@ impl Command { /// Usage: cust-ord [OPTIONS] /// /// Commands: - /// beta I should be first! - /// alpha Some help and text + /// alpha I should be first! + /// beta Some help and text + /// help Print help for the subcommand(s) /// /// Options: /// -h, --help Print help @@ -3697,7 +3708,7 @@ impl Command { /// let cmd = clap::Command::new("raw") /// .external_subcommand_value_parser(clap::value_parser!(String)); /// let value_parser = cmd.get_external_subcommand_value_parser(); - /// println!("{:?}", value_parser); + /// println!("{value_parser:?}"); /// ``` pub fn get_external_subcommand_value_parser(&self) -> Option<&super::ValueParser> { if !self.is_allow_external_subcommands_set() { @@ -3793,8 +3804,8 @@ impl Command { // do the real parsing let mut parser = Parser::new(self); if let Err(error) = parser.get_matches_with(&mut matcher, raw_args, args_cursor) { - if self.is_set(AppSettings::IgnoreErrors) { - debug!("Command::_do_parse: ignoring error: {}", error); + if self.is_set(AppSettings::IgnoreErrors) && error.use_stderr() { + debug!("Command::_do_parse: ignoring error: {error}"); } else { return Err(error); } @@ -3827,30 +3838,30 @@ impl Command { pub(crate) fn _build_self(&mut self, expand_help_tree: bool) { debug!("Command::_build: name={:?}", self.get_name()); if !self.settings.is_set(AppSettings::Built) { + if let Some(deferred) = self.deferred.take() { + *self = (deferred)(std::mem::take(self)); + } + // Make sure all the globally set flags apply to us as well self.settings = self.settings | self.g_settings; if self.is_multicall_set() { - self.settings.insert(AppSettings::SubcommandRequired.into()); - self.settings.insert(AppSettings::DisableHelpFlag.into()); - self.settings.insert(AppSettings::DisableVersionFlag.into()); + self.settings.set(AppSettings::SubcommandRequired); + self.settings.set(AppSettings::DisableHelpFlag); + self.settings.set(AppSettings::DisableVersionFlag); } if !cfg!(feature = "help") && self.get_override_help().is_none() { - self.settings.insert(AppSettings::DisableHelpFlag.into()); - self.settings - .insert(AppSettings::DisableHelpSubcommand.into()); + self.settings.set(AppSettings::DisableHelpFlag); + self.settings.set(AppSettings::DisableHelpSubcommand); } if self.is_set(AppSettings::ArgsNegateSubcommands) { - self.settings - .insert(AppSettings::SubcommandsNegateReqs.into()); + self.settings.set(AppSettings::SubcommandsNegateReqs); } if self.external_value_parser.is_some() { - self.settings - .insert(AppSettings::AllowExternalSubcommands.into()); + self.settings.set(AppSettings::AllowExternalSubcommands); } if !self.has_subcommands() { - self.settings - .insert(AppSettings::DisableHelpSubcommand.into()); + self.settings.set(AppSettings::DisableHelpSubcommand); } self._propagate(); @@ -3903,14 +3914,13 @@ impl Command { let is_allow_negative_numbers_set = self.is_allow_negative_numbers_set(); for arg in self.args.args_mut() { if is_allow_hyphen_values_set && arg.is_takes_value_set() { - arg.settings.insert(ArgSettings::AllowHyphenValues.into()); + arg.settings.set(ArgSettings::AllowHyphenValues); } if is_allow_negative_numbers_set && arg.is_takes_value_set() { - arg.settings - .insert(ArgSettings::AllowNegativeNumbers.into()); + arg.settings.set(ArgSettings::AllowNegativeNumbers); } if is_trailing_var_arg_set && arg.get_index() == Some(highest_idx) { - arg.settings.insert(ArgSettings::TrailingVarArg.into()); + arg.settings.set(ArgSettings::TrailingVarArg); } } } @@ -4033,7 +4043,7 @@ impl Command { } .to_owned(); - for mut sc in &mut self.subcommands { + for sc in &mut self.subcommands { debug!("Command::_build_bin_names:iter: bin_name set..."); if sc.usage_name.is_none() { @@ -4438,7 +4448,7 @@ impl Command { /// Iterate through the groups this arg is member of. pub(crate) fn groups_for_arg<'a>(&'a self, arg: &Id) -> impl Iterator<Item = Id> + 'a { - debug!("Command::groups_for_arg: id={:?}", arg); + debug!("Command::groups_for_arg: id={arg:?}"); let arg = arg.clone(); self.groups .iter() @@ -4478,7 +4488,7 @@ impl Command { } pub(crate) fn unroll_args_in_group(&self, group: &Id) -> Vec<Id> { - debug!("Command::unroll_args_in_group: group={:?}", group); + debug!("Command::unroll_args_in_group: group={group:?}"); let mut g_vec = vec![group]; let mut args = vec![]; @@ -4491,7 +4501,7 @@ impl Command { .args .iter() { - debug!("Command::unroll_args_in_group:iter: entity={:?}", n); + debug!("Command::unroll_args_in_group:iter: entity={n:?}"); if !args.contains(n) { if self.find(n).is_some() { debug!("Command::unroll_args_in_group:iter: this is an arg"); @@ -4655,6 +4665,7 @@ impl Default for Command { subcommand_heading: Default::default(), external_value_parser: Default::default(), long_help_exists: false, + deferred: None, app_ext: Default::default(), } } diff --git a/vendor/clap_builder/src/builder/debug_asserts.rs b/vendor/clap_builder/src/builder/debug_asserts.rs index 7a7fd6ae1..ef970cdaa 100644 --- a/vendor/clap_builder/src/builder/debug_asserts.rs +++ b/vendor/clap_builder/src/builder/debug_asserts.rs @@ -300,6 +300,28 @@ pub(crate) fn assert_app(cmd: &Command) { arg ); } + + for arg in &group.requires { + // Args listed inside groups should exist + assert!( + cmd.id_exists(arg), + "Command {}: Argument group '{}' requires non-existent '{}' id", + cmd.get_name(), + group.get_id(), + arg + ); + } + + for arg in &group.conflicts { + // Args listed inside groups should exist + assert!( + cmd.id_exists(arg), + "Command {}: Argument group '{}' conflicts with non-existent '{}' id", + cmd.get_name(), + group.get_id(), + arg + ); + } } // Conflicts between flags and subcommands @@ -460,7 +482,7 @@ fn assert_app_flags(cmd: &Command) { )+ if !s.is_empty() { - panic!("{}", s) + panic!("{s}") } } }; @@ -564,9 +586,8 @@ fn _verify_positionals(cmd: &Command) -> bool { || last.is_last_set(); assert!( ok, - "When using a positional argument with `.num_args(1..)` that is *not the \ - last* positional argument, the last positional argument (i.e. the one \ - with the highest index) *must* have .required(true) or .last(true) set." + "Positional argument `{last}` *must* have `required(true)` or `last(true)` set \ + because a prior positional argument (`{second_to_last}`) has `num_args(1..)`" ); // We make sure if the second to last is Multiple the last is ArgSettings::Last @@ -582,6 +603,7 @@ fn _verify_positionals(cmd: &Command) -> bool { .get_positionals() .filter(|p| { p.is_multiple_values_set() + && p.get_value_terminator().is_none() && !p.get_num_args().expect(INTERNAL_ERROR_MSG).is_fixed() }) .count(); diff --git a/vendor/clap_builder/src/builder/possible_value.rs b/vendor/clap_builder/src/builder/possible_value.rs index b0282e593..de7e543fe 100644 --- a/vendor/clap_builder/src/builder/possible_value.rs +++ b/vendor/clap_builder/src/builder/possible_value.rs @@ -162,18 +162,6 @@ impl PossibleValue { self.help.as_ref() } - /// Get the help specified for this argument, if any and the argument - /// value is not hidden - #[inline] - #[cfg(feature = "help")] - pub(crate) fn get_visible_help(&self) -> Option<&StyledStr> { - if !self.hide { - self.get_help() - } else { - None - } - } - /// Report if [`PossibleValue::hide`] is set #[inline] pub fn is_hide_set(&self) -> bool { diff --git a/vendor/clap_builder/src/builder/value_hint.rs b/vendor/clap_builder/src/builder/value_hint.rs index ee286b194..38fa862c1 100644 --- a/vendor/clap_builder/src/builder/value_hint.rs +++ b/vendor/clap_builder/src/builder/value_hint.rs @@ -24,11 +24,12 @@ use std::str::FromStr; /// /// [^1]: fish completions currently only support named arguments (e.g. -o or --opt), not /// positional arguments. -#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)] +#[derive(Debug, Default, PartialEq, Eq, Hash, Copy, Clone)] #[non_exhaustive] pub enum ValueHint { /// Default value if hint is not specified. Follows shell default behavior, which is usually /// auto-completing filenames. + #[default] Unknown, /// None of the hints below apply. Disables shell completion for this argument. Other, @@ -66,12 +67,6 @@ pub enum ValueHint { EmailAddress, } -impl Default for ValueHint { - fn default() -> Self { - ValueHint::Unknown - } -} - impl FromStr for ValueHint { type Err = String; fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> { diff --git a/vendor/clap_builder/src/builder/value_parser.rs b/vendor/clap_builder/src/builder/value_parser.rs index 24631ce7c..4b0955789 100644 --- a/vendor/clap_builder/src/builder/value_parser.rs +++ b/vendor/clap_builder/src/builder/value_parser.rs @@ -1162,7 +1162,7 @@ impl<E: crate::ValueEnum + Clone + Send + Sync + 'static> Default for EnumValueP pub struct PossibleValuesParser(Vec<super::PossibleValue>); impl PossibleValuesParser { - /// Verify the value is from an enumerated set pf [`PossibleValue`][crate::builder::PossibleValue]. + /// Verify the value is from an enumerated set of [`PossibleValue`][crate::builder::PossibleValue]. pub fn new(values: impl Into<PossibleValuesParser>) -> Self { values.into() } @@ -2382,17 +2382,17 @@ pub mod via_prelude { /// # use clap::ColorChoice; /// // Built-in types /// let parser = clap::value_parser!(String); -/// assert_eq!(format!("{:?}", parser), "ValueParser::string"); +/// assert_eq!(format!("{parser:?}"), "ValueParser::string"); /// let parser = clap::value_parser!(std::ffi::OsString); -/// assert_eq!(format!("{:?}", parser), "ValueParser::os_string"); +/// assert_eq!(format!("{parser:?}"), "ValueParser::os_string"); /// let parser = clap::value_parser!(std::path::PathBuf); -/// assert_eq!(format!("{:?}", parser), "ValueParser::path_buf"); +/// assert_eq!(format!("{parser:?}"), "ValueParser::path_buf"); /// clap::value_parser!(u16).range(3000..); /// clap::value_parser!(u64).range(3000..); /// /// // FromStr types /// let parser = clap::value_parser!(usize); -/// assert_eq!(format!("{:?}", parser), "_AnonymousValueParser(ValueParser::other(usize))"); +/// assert_eq!(format!("{parser:?}"), "_AnonymousValueParser(ValueParser::other(usize))"); /// /// // ValueEnum types /// clap::value_parser!(ColorChoice); |