summaryrefslogtreecommitdiffstats
path: root/vendor/clap_builder/src/builder
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/clap_builder/src/builder')
-rw-r--r--vendor/clap_builder/src/builder/arg.rs2
-rw-r--r--vendor/clap_builder/src/builder/command.rs60
-rw-r--r--vendor/clap_builder/src/builder/debug_asserts.rs16
-rw-r--r--vendor/clap_builder/src/builder/os_str.rs2
-rw-r--r--vendor/clap_builder/src/builder/str.rs2
5 files changed, 70 insertions, 12 deletions
diff --git a/vendor/clap_builder/src/builder/arg.rs b/vendor/clap_builder/src/builder/arg.rs
index 5634078c5..8e247c176 100644
--- a/vendor/clap_builder/src/builder/arg.rs
+++ b/vendor/clap_builder/src/builder/arg.rs
@@ -1617,7 +1617,7 @@ impl Arg {
/// ```
///
/// Will result in everything after `--` to be considered one raw argument. This behavior
- /// may not be exactly what you are expecting and using [`crate::Command::trailing_var_arg`]
+ /// may not be exactly what you are expecting and using [`Arg::trailing_var_arg`]
/// may be more appropriate.
///
/// **NOTE:** Implicitly sets [`Arg::action(ArgAction::Set)`] [`Arg::num_args(1..)`],
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 {
diff --git a/vendor/clap_builder/src/builder/debug_asserts.rs b/vendor/clap_builder/src/builder/debug_asserts.rs
index afc181c54..2b633849f 100644
--- a/vendor/clap_builder/src/builder/debug_asserts.rs
+++ b/vendor/clap_builder/src/builder/debug_asserts.rs
@@ -405,6 +405,12 @@ impl PartialEq for Flag<'_> {
impl PartialOrd for Flag<'_> {
fn partial_cmp(&self, other: &Flag) -> Option<Ordering> {
+ Some(self.cmp(other))
+ }
+}
+
+impl Ord for Flag<'_> {
+ fn cmp(&self, other: &Self) -> Ordering {
use Flag::*;
match (self, other) {
@@ -413,21 +419,15 @@ impl PartialOrd for Flag<'_> {
| (Command(s1, _), Arg(s2, _))
| (Arg(s1, _), Command(s2, _)) => {
if s1 == s2 {
- Some(Ordering::Equal)
+ Ordering::Equal
} else {
- s1.partial_cmp(s2)
+ s1.cmp(s2)
}
}
}
}
}
-impl Ord for Flag<'_> {
- fn cmp(&self, other: &Self) -> Ordering {
- self.partial_cmp(other).unwrap()
- }
-}
-
fn detect_duplicate_flags(flags: &[Flag], short_or_long: &str) {
use Flag::*;
diff --git a/vendor/clap_builder/src/builder/os_str.rs b/vendor/clap_builder/src/builder/os_str.rs
index 6bd9282ec..fe8928e09 100644
--- a/vendor/clap_builder/src/builder/os_str.rs
+++ b/vendor/clap_builder/src/builder/os_str.rs
@@ -316,7 +316,7 @@ impl PartialEq for Inner {
impl PartialOrd for Inner {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
- self.as_os_str().partial_cmp(other.as_os_str())
+ Some(self.cmp(other))
}
}
diff --git a/vendor/clap_builder/src/builder/str.rs b/vendor/clap_builder/src/builder/str.rs
index 9bded8147..cf876910a 100644
--- a/vendor/clap_builder/src/builder/str.rs
+++ b/vendor/clap_builder/src/builder/str.rs
@@ -290,7 +290,7 @@ impl PartialEq for Inner {
impl PartialOrd for Inner {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
- self.as_str().partial_cmp(other.as_str())
+ Some(self.cmp(other))
}
}