diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/clap_builder/src/builder/command.rs | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+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, 59 insertions, 1 deletions
diff --git a/vendor/clap_builder/src/builder/command.rs b/vendor/clap_builder/src/builder/command.rs index b1623cf8c..edcbace76 100644 --- a/vendor/clap_builder/src/builder/command.rs +++ b/vendor/clap_builder/src/builder/command.rs @@ -746,7 +746,7 @@ impl Command { I: IntoIterator<Item = T>, T: Into<OsString> + Clone, { - let mut raw_args = clap_lex::RawArgs::new(itr.into_iter()); + let mut raw_args = clap_lex::RawArgs::new(itr); let mut cursor = raw_args.cursor(); if self.settings.is_set(AppSettings::Multicall) { @@ -1244,12 +1244,41 @@ impl Command { /// # use clap_builder as clap; /// # use clap::{Command, error::ErrorKind}; /// let res = Command::new("myprog") + /// .version("1.0.0") /// .disable_version_flag(true) /// .try_get_matches_from(vec![ + /// "myprog", "--version" + /// ]); + /// assert!(res.is_err()); + /// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument); + /// ``` + /// + /// You can create a custom version flag with [`ArgAction::Version`] + /// ```rust + /// # use clap_builder as clap; + /// # use clap::{Command, Arg, ArgAction, error::ErrorKind}; + /// let mut cmd = Command::new("myprog") + /// .version("1.0.0") + /// // Remove the `-V` short flag + /// .disable_version_flag(true) + /// .arg( + /// Arg::new("version") + /// .long("version") + /// .action(ArgAction::Version) + /// .help("Print version") + /// ); + /// + /// let res = cmd.try_get_matches_from_mut(vec![ /// "myprog", "-V" /// ]); /// assert!(res.is_err()); /// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument); + /// + /// let res = cmd.try_get_matches_from_mut(vec![ + /// "myprog", "--version" + /// ]); + /// assert!(res.is_err()); + /// assert_eq!(res.unwrap_err().kind(), ErrorKind::DisplayVersion); /// ``` #[inline] pub fn disable_version_flag(self, yes: bool) -> Self { @@ -1329,6 +1358,35 @@ impl Command { /// assert!(res.is_err()); /// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument); /// ``` + /// + /// You can create a custom version flag with [`ArgAction::Help`], [`ArgAction::HelpShort`], or + /// [`ArgAction::HelpLong`] + /// ```rust + /// # use clap_builder as clap; + /// # use clap::{Command, Arg, ArgAction, error::ErrorKind}; + /// let mut cmd = Command::new("myprog") + /// // Change help short flag to `?` + /// .disable_help_flag(true) + /// .arg( + /// Arg::new("help") + /// .short('?') + /// .long("help") + /// .action(ArgAction::Help) + /// .help("Print help") + /// ); + /// + /// let res = cmd.try_get_matches_from_mut(vec![ + /// "myprog", "-h" + /// ]); + /// assert!(res.is_err()); + /// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument); + /// + /// let res = cmd.try_get_matches_from_mut(vec![ + /// "myprog", "-?" + /// ]); + /// assert!(res.is_err()); + /// assert_eq!(res.unwrap_err().kind(), ErrorKind::DisplayHelp); + /// ``` #[inline] pub fn disable_help_flag(self, yes: bool) -> Self { if yes { |