fix!: Remove rest of deprecated APIs

Fixes #4009
This commit is contained in:
Ed Page 2022-08-01 09:02:52 -05:00
parent 9037e93c72
commit 76bff6f34e
49 changed files with 172 additions and 354 deletions

View file

@ -68,7 +68,7 @@ pub mod bash {
}
/// Process the completion request
pub fn try_complete(&self, cmd: &mut clap::Command) -> clap::Result<()> {
pub fn try_complete(&self, cmd: &mut clap::Command) -> clap::error::Result<()> {
debug!("CompleteCommand::try_complete: {:?}", self);
let CompleteCommand::Complete(args) = self;
if let Some(out_path) = args.register.as_deref() {
@ -231,13 +231,13 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
Self::Menu,
]
}
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::PossibleValue<'a>> {
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::builder::PossibleValue<'a>> {
match self {
Self::Normal => {
let value = "9";
debug_assert_eq!(b'\t'.to_string(), value);
Some(
clap::PossibleValue::new(value)
clap::builder::PossibleValue::new(value)
.alias("normal")
.help("Normal completion"),
)
@ -246,7 +246,7 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
let value = "63";
debug_assert_eq!(b'?'.to_string(), value);
Some(
clap::PossibleValue::new(value)
clap::builder::PossibleValue::new(value)
.alias("successive")
.help("List completions after successive tabs"),
)
@ -255,7 +255,7 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
let value = "33";
debug_assert_eq!(b'!'.to_string(), value);
Some(
clap::PossibleValue::new(value)
clap::builder::PossibleValue::new(value)
.alias("alternatives")
.help("List alternatives on partial word completion"),
)
@ -264,7 +264,7 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
let value = "64";
debug_assert_eq!(b'@'.to_string(), value);
Some(
clap::PossibleValue::new(value)
clap::builder::PossibleValue::new(value)
.alias("unmodified")
.help("List completions if the word is not unmodified"),
)
@ -273,7 +273,7 @@ complete OPTIONS -F _clap_complete_NAME EXECUTABLES
let value = "37";
debug_assert_eq!(b'%'.to_string(), value);
Some(
clap::PossibleValue::new(value)
clap::builder::PossibleValue::new(value)
.alias("menu")
.help("Menu completion"),
)

View file

@ -127,7 +127,7 @@ pub fn flags<'help>(p: &Command<'help>) -> Vec<Arg<'help>> {
}
/// Get the possible values for completion
pub fn possible_values<'help>(a: &Arg<'help>) -> Option<Vec<clap::PossibleValue<'help>>> {
pub fn possible_values<'help>(a: &Arg<'help>) -> Option<Vec<clap::builder::PossibleValue<'help>>> {
if !a.is_takes_value_set() {
None
} else {

View file

@ -1,5 +1,6 @@
use std::{fmt::Write as _, io::Write};
use clap::builder::PossibleValue;
use clap::*;
use crate::generator::{utils, Generator};

View file

@ -1,7 +1,8 @@
use std::fmt::Display;
use std::str::FromStr;
use clap::{PossibleValue, ValueEnum};
use clap::builder::PossibleValue;
use clap::ValueEnum;
use crate::shells;
use crate::Generator;

View file

@ -1,5 +1,6 @@
use std::io::Write;
use clap::builder::PossibleValue;
use clap::*;
use crate::generator::{utils, Generator};

View file

@ -154,7 +154,9 @@ pub fn sub_subcommands_command(name: &'static str) -> clap::Command<'static> {
clap::Arg::new("config")
.long("config")
.action(clap::ArgAction::Set)
.value_parser([clap::PossibleValue::new("Lest quotes aren't escaped.")])
.value_parser([clap::builder::PossibleValue::new(
"Lest quotes aren't escaped.",
)])
.help("the other case to test"),
),
),

View file

@ -154,7 +154,9 @@ pub fn sub_subcommands_command(name: &'static str) -> clap::Command<'static> {
clap::Arg::new("config")
.long("config")
.action(clap::ArgAction::Set)
.value_parser([clap::PossibleValue::new("Lest quotes aren't escaped.")])
.value_parser([clap::builder::PossibleValue::new(
"Lest quotes aren't escaped.",
)])
.help("the other case to test"),
),
),

View file

@ -549,7 +549,7 @@ fn gen_parsers(
quote_spanned! { ty.span()=>
#arg_matches.#get_one(#id)
.map(#deref)
.ok_or_else(|| clap::Error::raw(clap::ErrorKind::MissingRequiredArgument, format!("The following required argument was not provided: {}", #id)))
.ok_or_else(|| clap::Error::raw(clap::error::ErrorKind::MissingRequiredArgument, format!("The following required argument was not provided: {}", #id)))
.and_then(#parse)?
}
}

View file

@ -523,7 +523,7 @@ fn gen_from_arg_matches(
},
None => quote! {
::std::result::Result::Err(clap::Error::raw(clap::ErrorKind::InvalidSubcommand, format!("The subcommand '{}' wasn't recognized", #subcommand_name_var)))
::std::result::Result::Err(clap::Error::raw(clap::error::ErrorKind::InvalidSubcommand, format!("The subcommand '{}' wasn't recognized", #subcommand_name_var)))
},
};
@ -540,7 +540,7 @@ fn gen_from_arg_matches(
#wildcard
} else {
::std::result::Result::Err(clap::Error::raw(clap::ErrorKind::MissingSubcommand, "A subcommand is required but one was not provided."))
::std::result::Result::Err(clap::Error::raw(clap::error::ErrorKind::MissingSubcommand, "A subcommand is required but one was not provided."))
}
}
}

View file

@ -90,7 +90,7 @@ fn lits(
let name = attrs.cased_name();
Some((
quote_spanned! { variant.span()=>
clap::PossibleValue::new(#name)
clap::builder::PossibleValue::new(#name)
#fields
},
variant.ident.clone(),
@ -114,7 +114,7 @@ fn gen_to_possible_value(lits: &[(TokenStream, Ident)]) -> TokenStream {
let (lit, variant): (Vec<TokenStream>, Vec<Ident>) = lits.iter().cloned().unzip();
quote! {
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::PossibleValue<'a>> {
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::builder::PossibleValue<'a>> {
match self {
#(Self::#variant => Some(#lit),)*
_ => None

View file

@ -82,7 +82,7 @@ pub fn value_enum(name: &Ident) {
fn from_str(_input: &str, _ignore_case: bool) -> ::std::result::Result<Self, String> {
unimplemented!()
}
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::PossibleValue<'a>>{
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::builder::PossibleValue<'a>>{
unimplemented!()
}
}

View file

@ -36,14 +36,6 @@ pub fn value_enum(input: TokenStream) -> TokenStream {
derives::derive_value_enum(&input).into()
}
/// Generates the `ValueEnum` impl.
#[proc_macro_derive(ArgEnum, attributes(clap))]
#[proc_macro_error]
pub fn arg_enum(input: TokenStream) -> TokenStream {
let input: DeriveInput = parse_macro_input!(input);
derives::derive_value_enum(&input).into()
}
/// Generates the `Parser` implementation.
///
/// This is far less verbose than defining the `clap::Command` struct manually,

View file

@ -150,7 +150,9 @@ pub fn sub_subcommands_command(name: &'static str) -> clap::Command<'static> {
clap::Arg::new("config")
.long("config")
.action(clap::ArgAction::Set)
.value_parser([clap::PossibleValue::new("Lest quotes aren't escaped.")])
.value_parser([clap::builder::PossibleValue::new(
"Lest quotes aren't escaped.",
)])
.help("the other case to test"),
),
),

View file

@ -1,6 +1,7 @@
use std::path::PathBuf;
use clap::{arg, command, value_parser, ArgAction, ErrorKind};
use clap::error::ErrorKind;
use clap::{arg, command, value_parser, ArgAction};
fn main() {
// Create application like normal

View file

@ -1,4 +1,4 @@
use clap::{ArgEnum, Parser};
use clap::{Parser, ValueEnum};
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]
@ -8,7 +8,7 @@ struct Cli {
mode: Mode,
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ArgEnum)]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
enum Mode {
Fast,
Slow,

View file

@ -1,4 +1,5 @@
use clap::{CommandFactory, ErrorKind, Parser};
use clap::error::ErrorKind;
use clap::{CommandFactory, Parser};
#[derive(Parser)]
#[clap(author, version, about, long_about = None)]

View file

@ -5,7 +5,7 @@
//! 1. [Terminology](#terminology)
//! 2. [Command Attributes](#command-attributes)
//! 3. [Arg Attributes](#arg-attributes)
//! 4. [Arg Enum Attributes](#arg-enum-attributes)
//! 4. [ValueEnum Attributes](#valueenum-attributes)
//! 5. [Possible Value Attributes](#possible-value-attributes)
//! 3. [Arg Types](#arg-types)
//! 4. [Doc Comments](#doc-comments)
@ -98,7 +98,7 @@
//! ### Terminology
//!
//! **Raw attributes** are forwarded directly to the underlying [`clap` builder][crate::builder]. Any
//! [`Command`][crate::Command], [`Arg`][crate::Arg], or [`PossibleValue`][crate::PossibleValue] method can be used as an attribute.
//! [`Command`][crate::Command], [`Arg`][crate::Arg], or [`PossibleValue`][crate::builder::PossibleValue] method can be used as an attribute.
//!
//! Raw attributes come in two different syntaxes:
//! ```rust,ignore
@ -233,23 +233,23 @@
//! - Requires field arg to be of type `Vec<T>` and `T` to implement `std::convert::Into<OsString>` or `#[clap(value_enum)]`
//! - `<expr>` must implement `IntoIterator<T>`
//!
//! ### Value Enum Attributes
//! ### ValueEnum Attributes
//!
//! - `rename_all = <string_literal>`: Override default field / variant name case conversion for [`PossibleValue::new`][crate::PossibleValue]
//! - `rename_all = <string_literal>`: Override default field / variant name case conversion for [`PossibleValue::new`][crate::builder::PossibleValue]
//! - When not present: `"kebab-case"`
//! - Available values: `"camelCase"`, `"kebab-case"`, `"PascalCase"`, `"SCREAMING_SNAKE_CASE"`, `"snake_case"`, `"lower"`, `"UPPER"`, `"verbatim"`
//!
//! ### Possible Value Attributes
//!
//! These correspond to a [`PossibleValue`][crate::PossibleValue].
//! These correspond to a [`PossibleValue`][crate::builder::PossibleValue].
//!
//! **Raw attributes:** Any [`PossibleValue` method][crate::PossibleValue] can also be used as an attribute, see [Terminology](#terminology) for syntax.
//! **Raw attributes:** Any [`PossibleValue` method][crate::builder::PossibleValue] can also be used as an attribute, see [Terminology](#terminology) for syntax.
//! - e.g. `#[clap(alias("foo"))]` would translate to `pv.alias("foo")`
//!
//! **Magic attributes**:
//! - `name = <expr>`: [`PossibleValue::new`][crate::PossibleValue::new]
//! - `name = <expr>`: [`PossibleValue::new`][crate::builder::PossibleValue::new]
//! - When not present: case-converted field name is used
//! - `help = <expr>`: [`PossibleValue::help`][crate::PossibleValue::help]
//! - `help = <expr>`: [`PossibleValue::help`][crate::builder::PossibleValue::help]
//! - When not present: [Doc comment summary](#doc-comments)
//!
//! ## Arg Types

View file

@ -40,7 +40,6 @@ pub enum ArgAction {
///
/// let matches = cmd.try_get_matches_from(["mycmd", "--flag", "value"]).unwrap();
/// assert!(matches.contains_id("flag"));
/// assert_eq!(matches.occurrences_of("flag"), 0);
/// assert_eq!(
/// matches.get_many::<String>("flag").unwrap_or_default().map(|v| v.as_str()).collect::<Vec<_>>(),
/// vec!["value"]
@ -63,7 +62,6 @@ pub enum ArgAction {
///
/// let matches = cmd.try_get_matches_from(["mycmd", "--flag", "value1", "--flag", "value2"]).unwrap();
/// assert!(matches.contains_id("flag"));
/// assert_eq!(matches.occurrences_of("flag"), 0);
/// assert_eq!(
/// matches.get_many::<String>("flag").unwrap_or_default().map(|v| v.as_str()).collect::<Vec<_>>(),
/// vec!["value1", "value2"]
@ -91,7 +89,6 @@ pub enum ArgAction {
///
/// let matches = cmd.clone().try_get_matches_from(["mycmd", "--flag", "--flag"]).unwrap();
/// assert!(matches.contains_id("flag"));
/// assert_eq!(matches.occurrences_of("flag"), 0);
/// assert_eq!(
/// matches.get_one::<bool>("flag").copied(),
/// Some(true)
@ -99,7 +96,6 @@ pub enum ArgAction {
///
/// let matches = cmd.try_get_matches_from(["mycmd"]).unwrap();
/// assert!(matches.contains_id("flag"));
/// assert_eq!(matches.occurrences_of("flag"), 0);
/// assert_eq!(
/// matches.get_one::<bool>("flag").copied(),
/// Some(false)
@ -127,7 +123,6 @@ pub enum ArgAction {
///
/// let matches = cmd.clone().try_get_matches_from(["mycmd", "--flag", "--flag"]).unwrap();
/// assert!(matches.contains_id("flag"));
/// assert_eq!(matches.occurrences_of("flag"), 0);
/// assert_eq!(
/// matches.get_one::<bool>("flag").copied(),
/// Some(false)
@ -135,7 +130,6 @@ pub enum ArgAction {
///
/// let matches = cmd.try_get_matches_from(["mycmd"]).unwrap();
/// assert!(matches.contains_id("flag"));
/// assert_eq!(matches.occurrences_of("flag"), 0);
/// assert_eq!(
/// matches.get_one::<bool>("flag").copied(),
/// Some(true)
@ -163,7 +157,6 @@ pub enum ArgAction {
///
/// let matches = cmd.clone().try_get_matches_from(["mycmd", "--flag", "--flag"]).unwrap();
/// assert!(matches.contains_id("flag"));
/// assert_eq!(matches.occurrences_of("flag"), 0);
/// assert_eq!(
/// matches.get_one::<u8>("flag").copied(),
/// Some(2)
@ -171,7 +164,6 @@ pub enum ArgAction {
///
/// let matches = cmd.try_get_matches_from(["mycmd"]).unwrap();
/// assert!(matches.contains_id("flag"));
/// assert_eq!(matches.occurrences_of("flag"), 0);
/// assert_eq!(
/// matches.get_one::<u8>("flag").copied(),
/// Some(0)

View file

@ -1,5 +1,3 @@
#![allow(deprecated)]
// Std
use std::ops::BitOr;

View file

@ -1,5 +1,3 @@
#![allow(deprecated)]
// Std
use std::{
borrow::Cow,
@ -14,10 +12,10 @@ use std::{env, ffi::OsString};
// Internal
use super::{ArgFlags, ArgSettings};
use crate::builder::ArgPredicate;
use crate::builder::PossibleValue;
use crate::builder::ValuesRange;
use crate::util::{Id, Key};
use crate::ArgAction;
use crate::PossibleValue;
use crate::ValueHint;
use crate::INTERNAL_ERROR_MSG;
@ -519,7 +517,7 @@ impl<'help> Arg<'help> {
/// failing to use the `--` syntax results in an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("first"))
/// .arg(Arg::new("second"))
@ -534,7 +532,7 @@ impl<'help> Arg<'help> {
/// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument);
/// ```
/// [index]: Arg::index()
/// [`UnknownArgument`]: crate::ErrorKind::UnknownArgument
/// [`UnknownArgument`]: crate::error::ErrorKind::UnknownArgument
#[inline]
#[must_use]
pub fn last(self, yes: bool) -> Self {
@ -585,7 +583,7 @@ impl<'help> Arg<'help> {
/// Setting required and then *not* supplying that argument at runtime is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .required(true)
@ -645,7 +643,7 @@ impl<'help> Arg<'help> {
/// Setting [`Arg::requires(name)`] and *not* supplying that argument is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .action(ArgAction::Set)
@ -683,7 +681,7 @@ impl<'help> Arg<'help> {
/// is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("exclusive")
/// .action(ArgAction::Set)
@ -837,7 +835,6 @@ impl<'help> Arg<'help> {
///
/// let matches = cmd.try_get_matches_from(["mycmd", "--flag", "value"]).unwrap();
/// assert!(matches.contains_id("flag"));
/// assert_eq!(matches.occurrences_of("flag"), 0);
/// assert_eq!(
/// matches.get_many::<String>("flag").unwrap_or_default().map(|v| v.as_str()).collect::<Vec<_>>(),
/// vec!["value"]
@ -984,7 +981,7 @@ impl<'help> Arg<'help> {
/// Although `multiple_values` has been specified, the last argument still wins
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let m = Command::new("prog")
/// .arg(Arg::new("file")
/// .action(ArgAction::Set)
@ -1048,7 +1045,7 @@ impl<'help> Arg<'help> {
/// As a final example, let's fix the above error and get a pretty message to the user :)
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("file")
/// .action(ArgAction::Set)
@ -1127,7 +1124,7 @@ impl<'help> Arg<'help> {
///
/// Flag/option hybrid (see also [default_missing_value][Arg::default_missing_value])
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let cmd = Command::new("prog")
/// .arg(Arg::new("mode")
/// .long("mode")
@ -1156,7 +1153,7 @@ impl<'help> Arg<'help> {
///
/// Tuples
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let cmd = Command::new("prog")
/// .arg(Arg::new("file")
/// .action(ArgAction::Set)
@ -1475,7 +1472,7 @@ impl<'help> Arg<'help> {
/// hyphen is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("pat")
/// .action(ArgAction::Set)
@ -1527,7 +1524,7 @@ impl<'help> Arg<'help> {
/// error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .action(ArgAction::Set)
@ -1681,7 +1678,7 @@ impl<'help> Arg<'help> {
/// In this next example, we will *not* use a delimiter. Notice it's now an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("opt")
/// .short('o')
@ -1814,10 +1811,6 @@ impl<'help> Arg<'help> {
/// Value for the argument when not present.
///
/// **NOTE:** If the user *does not* use this argument at runtime, [`ArgMatches::occurrences_of`]
/// will return `0` even though the [`ArgMatches::get_one`][crate::ArgMatches::get_one] will
/// return the default specified.
///
/// **NOTE:** If the user *does not* use this argument at runtime [`ArgMatches::contains_id`] will
/// still return `true`. If you wish to determine whether the argument was used at runtime or
/// not, consider [`ArgMatches::value_source`][crate::ArgMatches::value_source].
@ -1837,7 +1830,7 @@ impl<'help> Arg<'help> {
/// First we use the default value without providing any value at runtime.
///
/// ```rust
/// # use clap::{Command, Arg, ValueSource};
/// # use clap::{Command, Arg, parser::ValueSource};
/// let m = Command::new("prog")
/// .arg(Arg::new("opt")
/// .long("myopt")
@ -1854,7 +1847,7 @@ impl<'help> Arg<'help> {
/// Next we provide a value at runtime to override the default.
///
/// ```rust
/// # use clap::{Command, Arg, ValueSource};
/// # use clap::{Command, Arg, parser::ValueSource};
/// let m = Command::new("prog")
/// .arg(Arg::new("opt")
/// .long("myopt")
@ -1867,7 +1860,6 @@ impl<'help> Arg<'help> {
/// assert!(m.contains_id("opt"));
/// assert_eq!(m.value_source("opt"), Some(ValueSource::CommandLine));
/// ```
/// [`ArgMatches::occurrences_of`]: crate::ArgMatches::occurrences_of()
/// [`Arg::action(ArgAction::Set)`]: Arg::takes_value()
/// [`ArgMatches::contains_id`]: crate::ArgMatches::contains_id()
/// [`Arg::default_value_if`]: Arg::default_value_if()
@ -1930,7 +1922,7 @@ impl<'help> Arg<'help> {
///
/// For POSIX style `--color`:
/// ```rust
/// # use clap::{Command, Arg, ValueSource};
/// # use clap::{Command, Arg, parser::ValueSource};
/// fn cli() -> Command<'static> {
/// Command::new("prog")
/// .arg(Arg::new("color").long("color")
@ -1968,7 +1960,7 @@ impl<'help> Arg<'help> {
///
/// For bool literals:
/// ```rust
/// # use clap::{Command, Arg, ValueSource, value_parser};
/// # use clap::{Command, Arg, parser::ValueSource, value_parser};
/// fn cli() -> Command<'static> {
/// Command::new("prog")
/// .arg(Arg::new("create").long("create")
@ -3130,7 +3122,7 @@ impl<'help> Arg<'help> {
/// Setting `Arg::required_unless_present(name)` and *not* supplying `name` or this arg is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .required_unless_present("dbg")
@ -3197,7 +3189,7 @@ impl<'help> Arg<'help> {
/// either *all* of `unless` args or the `self` arg is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .required_unless_present_all(&["dbg", "infile"])
@ -3276,7 +3268,7 @@ impl<'help> Arg<'help> {
/// or this arg is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .required_unless_present_any(&["dbg", "infile"])
@ -3321,7 +3313,7 @@ impl<'help> Arg<'help> {
/// ```
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .action(ArgAction::Set)
@ -3441,7 +3433,7 @@ impl<'help> Arg<'help> {
/// value of `val` but *not* using this arg is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .required_if_eq_any(&[
@ -3521,7 +3513,7 @@ impl<'help> Arg<'help> {
/// value of `val` but *not* using this arg is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .required_if_eq_all(&[
@ -3589,7 +3581,7 @@ impl<'help> Arg<'help> {
/// `arg` is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .action(ArgAction::Set)
@ -3634,7 +3626,7 @@ impl<'help> Arg<'help> {
/// than `val`, `arg` isn't required.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .action(ArgAction::Set)
@ -3706,7 +3698,7 @@ impl<'help> Arg<'help> {
/// error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .action(ArgAction::Set)
@ -3756,7 +3748,7 @@ impl<'help> Arg<'help> {
/// Setting conflicting argument, and having both arguments present at runtime is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .action(ArgAction::Set)
@ -3806,7 +3798,7 @@ impl<'help> Arg<'help> {
/// conflicting argument is an error.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("cfg")
/// .action(ArgAction::Set)

View file

@ -34,7 +34,7 @@ use crate::util::{Id, Key};
/// the arguments from the specified group is present at runtime.
///
/// ```rust
/// # use clap::{Command, arg, ArgGroup, ErrorKind};
/// # use clap::{Command, arg, ArgGroup, error::ErrorKind};
/// let result = Command::new("cmd")
/// .arg(arg!(--"set-ver" <ver> "set the version manually").required(false))
/// .arg(arg!(--major "auto increase major"))
@ -211,7 +211,7 @@ impl<'help> ArgGroup<'help> {
/// an error if more than one of the args in the group was used.
///
/// ```rust
/// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, ArgGroup, error::ErrorKind, ArgAction};
/// let result = Command::new("myprog")
/// .arg(Arg::new("flag")
/// .short('f')
@ -252,7 +252,7 @@ impl<'help> ArgGroup<'help> {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, ArgGroup, error::ErrorKind, ArgAction};
/// let result = Command::new("myprog")
/// .arg(Arg::new("flag")
/// .short('f')
@ -291,7 +291,7 @@ impl<'help> ArgGroup<'help> {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, ArgGroup, error::ErrorKind, ArgAction};
/// let result = Command::new("myprog")
/// .arg(Arg::new("flag")
/// .short('f')
@ -331,7 +331,7 @@ impl<'help> ArgGroup<'help> {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, ArgGroup, error::ErrorKind, ArgAction};
/// let result = Command::new("myprog")
/// .arg(Arg::new("flag")
/// .short('f')
@ -376,7 +376,7 @@ impl<'help> ArgGroup<'help> {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, ArgGroup, error::ErrorKind, ArgAction};
/// let result = Command::new("myprog")
/// .arg(Arg::new("flag")
/// .short('f')
@ -413,7 +413,7 @@ impl<'help> ArgGroup<'help> {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ArgGroup, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, ArgGroup, error::ErrorKind, ArgAction};
/// let result = Command::new("myprog")
/// .arg(Arg::new("flag")
/// .short('f')

View file

@ -1,5 +1,3 @@
#![allow(deprecated)]
// Std
use std::ops::BitOr;

View file

@ -1,5 +1,3 @@
#![allow(deprecated)]
// Std
use std::collections::HashMap;
use std::env;
@ -13,6 +11,7 @@ use std::path::Path;
use crate::builder::app_settings::{AppFlags, AppSettings};
use crate::builder::arg_settings::ArgSettings;
use crate::builder::ArgAction;
use crate::builder::PossibleValue;
use crate::builder::{arg::ArgProvider, Arg, ArgGroup, ArgPredicate};
use crate::error::ErrorKind;
use crate::error::Result as ClapResult;
@ -22,7 +21,6 @@ use crate::output::{fmt::Colorizer, Help, HelpWriter, Usage};
use crate::parser::{ArgMatcher, ArgMatches, Parser};
use crate::util::ChildGraph;
use crate::util::{color::ColorChoice, Id, Key};
use crate::PossibleValue;
use crate::{Error, INTERNAL_ERROR_MSG};
#[cfg(debug_assertions)]
@ -495,7 +493,7 @@ impl<'help> Command<'help> {
/// # Examples
///
/// ```rust
/// # use clap::{Command, ErrorKind};
/// # use clap::{Command, error::ErrorKind};
/// let mut cmd = Command::new("myprog");
/// let err = cmd.error(ErrorKind::InvalidValue, "Some failure case");
/// ```
@ -574,8 +572,8 @@ impl<'help> Command<'help> {
/// [`clap::Result`]: Result
/// [`clap::Error`]: crate::Error
/// [`kind`]: crate::Error
/// [`ErrorKind::DisplayHelp`]: crate::ErrorKind::DisplayHelp
/// [`ErrorKind::DisplayVersion`]: crate::ErrorKind::DisplayVersion
/// [`ErrorKind::DisplayHelp`]: crate::error::ErrorKind::DisplayHelp
/// [`ErrorKind::DisplayVersion`]: crate::error::ErrorKind::DisplayVersion
#[inline]
pub fn try_get_matches(self) -> ClapResult<ArgMatches> {
// Start the parsing
@ -647,8 +645,8 @@ impl<'help> Command<'help> {
/// [`clap::Error`]: crate::Error
/// [`Error::exit`]: crate::Error::exit()
/// [`kind`]: crate::Error
/// [`ErrorKind::DisplayHelp`]: crate::ErrorKind::DisplayHelp
/// [`ErrorKind::DisplayVersion`]: crate::ErrorKind::DisplayVersion
/// [`ErrorKind::DisplayHelp`]: crate::error::ErrorKind::DisplayHelp
/// [`ErrorKind::DisplayVersion`]: crate::error::ErrorKind::DisplayVersion
/// [`clap::Result`]: Result
pub fn try_get_matches_from<I, T>(mut self, itr: I) -> ClapResult<ArgMatches>
where
@ -958,7 +956,7 @@ impl<'help> Command<'help> {
/// assert!(r.is_ok(), "unexpected error: {:?}", r);
/// let m = r.unwrap();
/// assert_eq!(m.get_one::<String>("config").unwrap(), "file");
/// assert!(m.is_present("f"));
/// assert!(*m.get_one::<bool>("f").expect("defaulted"));
/// assert_eq!(m.get_one::<String>("stuff"), None);
/// ```
#[inline]
@ -1081,7 +1079,7 @@ impl<'help> Command<'help> {
/// # Examples
///
/// ```rust
/// # use clap::{Command, ErrorKind};
/// # use clap::{Command, error::ErrorKind};
/// let res = Command::new("myprog")
/// .disable_version_flag(true)
/// .try_get_matches_from(vec![
@ -1159,7 +1157,7 @@ impl<'help> Command<'help> {
/// # Examples
///
/// ```rust
/// # use clap::{Command, ErrorKind};
/// # use clap::{Command, error::ErrorKind};
/// let res = Command::new("myprog")
/// .disable_help_flag(true)
/// .try_get_matches_from(vec![
@ -1182,7 +1180,7 @@ impl<'help> Command<'help> {
/// # Examples
///
/// ```rust
/// # use clap::{Command, ErrorKind};
/// # use clap::{Command, error::ErrorKind};
/// let res = Command::new("myprog")
/// .disable_help_subcommand(true)
/// // Normally, creating a subcommand causes a `help` subcommand to automatically
@ -2642,7 +2640,7 @@ impl<'help> Command<'help> {
/// # Examples
///
/// ```rust
/// # use clap::{Command, ErrorKind};
/// # use clap::{Command, error::ErrorKind};
/// let err = Command::new("myprog")
/// .subcommand_required(true)
/// .subcommand(Command::new("test"))
@ -2701,7 +2699,7 @@ impl<'help> Command<'help> {
///
/// [`subcommand`]: crate::Command::subcommand()
/// [`ArgMatches`]: crate::ArgMatches
/// [`ErrorKind::UnknownArgument`]: crate::ErrorKind::UnknownArgument
/// [`ErrorKind::UnknownArgument`]: crate::error::ErrorKind::UnknownArgument
pub fn allow_external_subcommands(self, yes: bool) -> Self {
if yes {
self.setting(AppSettings::AllowExternalSubcommands)
@ -2880,7 +2878,7 @@ impl<'help> Command<'help> {
/// This first example shows that it is an error to not use a required argument
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind};
/// # use clap::{Command, Arg, error::ErrorKind};
/// let err = Command::new("myprog")
/// .subcommand_negates_reqs(true)
/// .arg(Arg::new("opt").required(true))
@ -2897,7 +2895,7 @@ impl<'help> Command<'help> {
/// valid subcommand is used.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind};
/// # use clap::{Command, Arg, error::ErrorKind};
/// let noerr = Command::new("myprog")
/// .subcommand_negates_reqs(true)
/// .arg(Arg::new("opt").required(true))
@ -2981,7 +2979,7 @@ impl<'help> Command<'help> {
/// This does not allow the subcommand to be passed as the first non-path argument.
///
/// ```rust
/// # use clap::{Command, ErrorKind};
/// # use clap::{Command, error::ErrorKind};
/// let mut cmd = Command::new("hostname")
/// .multicall(true)
/// .subcommand(Command::new("hostname"))

View file

@ -12,7 +12,7 @@ use crate::util::eq_ignore_case;
/// # Examples
///
/// ```rust
/// # use clap::{Arg, PossibleValue, ArgAction};
/// # use clap::{Arg, builder::PossibleValue, ArgAction};
/// let cfg = Arg::new("config")
/// .action(ArgAction::Set)
/// .value_name("FILE")
@ -45,7 +45,7 @@ impl<'help> PossibleValue<'help> {
/// # Examples
///
/// ```rust
/// # use clap::PossibleValue;
/// # use clap::builder::PossibleValue;
/// PossibleValue::new("fast")
/// # ;
/// ```
@ -67,7 +67,7 @@ impl<'help> PossibleValue<'help> {
/// # Examples
///
/// ```rust
/// # use clap::PossibleValue;
/// # use clap::builder::PossibleValue;
/// PossibleValue::new("slow")
/// .help("not fast")
/// # ;
@ -87,7 +87,7 @@ impl<'help> PossibleValue<'help> {
/// # Examples
///
/// ```rust
/// # use clap::PossibleValue;
/// # use clap::builder::PossibleValue;
/// PossibleValue::new("secret")
/// .hide(true)
/// # ;
@ -105,7 +105,7 @@ impl<'help> PossibleValue<'help> {
/// # Examples
///
/// ```rust
/// # use clap::PossibleValue;
/// # use clap::builder::PossibleValue;
/// PossibleValue::new("slow")
/// .alias("not-fast")
/// # ;
@ -121,7 +121,7 @@ impl<'help> PossibleValue<'help> {
/// # Examples
///
/// ```rust
/// # use clap::PossibleValue;
/// # use clap::builder::PossibleValue;
/// PossibleValue::new("slow")
/// .aliases(["not-fast", "snake-like"])
/// # ;
@ -200,7 +200,7 @@ impl<'help> PossibleValue<'help> {
/// # Examples
///
/// ```rust
/// # use clap::PossibleValue;
/// # use clap::builder::PossibleValue;
/// let arg_value = PossibleValue::new("fast").alias("not-slow");
///
/// assert!(arg_value.matches("fast", false));

View file

@ -244,7 +244,7 @@ impl ValueParser {
/// applications like errors and completion.
pub fn possible_values(
&self,
) -> Option<Box<dyn Iterator<Item = crate::PossibleValue<'static>> + '_>> {
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
self.any_value_parser().possible_values()
}
@ -480,7 +480,7 @@ impl From<std::ops::RangeFull> for ValueParser {
/// Create a [`ValueParser`] with [`PossibleValuesParser`]
///
/// See [`PossibleValuesParser`] for more flexibility in creating the
/// [`PossibleValue`][crate::PossibleValue]s.
/// [`PossibleValue`][crate::builder::PossibleValue]s.
///
/// # Examples
///
@ -556,7 +556,7 @@ trait AnyValueParser: Send + Sync + 'static {
fn possible_values(
&self,
) -> Option<Box<dyn Iterator<Item = crate::PossibleValue<'static>> + '_>>;
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>>;
fn clone_any(&self) -> Box<dyn AnyValueParser>;
}
@ -592,7 +592,7 @@ where
fn possible_values(
&self,
) -> Option<Box<dyn Iterator<Item = crate::PossibleValue<'static>> + '_>> {
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
P::possible_values(self)
}
@ -634,7 +634,7 @@ pub trait TypedValueParser: Clone + Send + Sync + 'static {
/// applications like errors and completion.
fn possible_values(
&self,
) -> Option<Box<dyn Iterator<Item = crate::PossibleValue<'static>> + '_>> {
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
None
}
}
@ -833,11 +833,11 @@ impl Default for PathBufValueParser {
/// &[Self::Always, Self::Auto, Self::Never]
/// }
///
/// fn to_possible_value<'a>(&self) -> Option<clap::PossibleValue<'a>> {
/// fn to_possible_value<'a>(&self) -> Option<clap::builder::PossibleValue<'a>> {
/// match self {
/// Self::Always => Some(clap::PossibleValue::new("always")),
/// Self::Auto => Some(clap::PossibleValue::new("auto")),
/// Self::Never => Some(clap::PossibleValue::new("never")),
/// Self::Always => Some(clap::builder::PossibleValue::new("always")),
/// Self::Auto => Some(clap::builder::PossibleValue::new("auto")),
/// Self::Never => Some(clap::builder::PossibleValue::new("never")),
/// }
/// }
/// }
@ -928,7 +928,7 @@ impl<E: crate::ValueEnum + Clone + Send + Sync + 'static> TypedValueParser for E
fn possible_values(
&self,
) -> Option<Box<dyn Iterator<Item = crate::PossibleValue<'static>> + '_>> {
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
Some(Box::new(
E::value_variants()
.iter()
@ -943,7 +943,7 @@ impl<E: crate::ValueEnum + Clone + Send + Sync + 'static> Default for EnumValueP
}
}
/// Verify the value is from an enumerated set of [`PossibleValue`][crate::PossibleValue].
/// Verify the value is from an enumerated set of [`PossibleValue`][crate::builder::PossibleValue].
///
/// See also:
/// - [`EnumValueParser`]
@ -982,7 +982,7 @@ impl<E: crate::ValueEnum + Clone + Send + Sync + 'static> Default for EnumValueP
pub struct PossibleValuesParser(Vec<super::PossibleValue<'static>>);
impl PossibleValuesParser {
/// Verify the value is from an enumerated set pf [`PossibleValue`][crate::PossibleValue].
/// Verify the value is from an enumerated set pf [`PossibleValue`][crate::builder::PossibleValue].
pub fn new(values: impl Into<PossibleValuesParser>) -> Self {
values.into()
}
@ -1036,7 +1036,7 @@ impl TypedValueParser for PossibleValuesParser {
fn possible_values(
&self,
) -> Option<Box<dyn Iterator<Item = crate::PossibleValue<'static>> + '_>> {
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
Some(Box::new(self.0.iter().cloned()))
}
}
@ -1458,11 +1458,11 @@ impl BoolValueParser {
Self {}
}
fn possible_values() -> impl Iterator<Item = crate::PossibleValue<'static>> {
fn possible_values() -> impl Iterator<Item = crate::builder::PossibleValue<'static>> {
["true", "false"]
.iter()
.copied()
.map(crate::PossibleValue::new)
.map(crate::builder::PossibleValue::new)
}
}
@ -1498,7 +1498,7 @@ impl TypedValueParser for BoolValueParser {
fn possible_values(
&self,
) -> Option<Box<dyn Iterator<Item = crate::PossibleValue<'static>> + '_>> {
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
Some(Box::new(Self::possible_values()))
}
}
@ -1557,12 +1557,12 @@ impl FalseyValueParser {
Self {}
}
fn possible_values() -> impl Iterator<Item = crate::PossibleValue<'static>> {
fn possible_values() -> impl Iterator<Item = crate::builder::PossibleValue<'static>> {
crate::util::TRUE_LITERALS
.iter()
.chain(crate::util::FALSE_LITERALS.iter())
.copied()
.map(|l| crate::PossibleValue::new(l).hide(l != "true" && l != "false"))
.map(|l| crate::builder::PossibleValue::new(l).hide(l != "true" && l != "false"))
}
}
@ -1591,7 +1591,7 @@ impl TypedValueParser for FalseyValueParser {
fn possible_values(
&self,
) -> Option<Box<dyn Iterator<Item = crate::PossibleValue<'static>> + '_>> {
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
Some(Box::new(Self::possible_values()))
}
}
@ -1654,12 +1654,12 @@ impl BoolishValueParser {
Self {}
}
fn possible_values() -> impl Iterator<Item = crate::PossibleValue<'static>> {
fn possible_values() -> impl Iterator<Item = crate::builder::PossibleValue<'static>> {
crate::util::TRUE_LITERALS
.iter()
.chain(crate::util::FALSE_LITERALS.iter())
.copied()
.map(|l| crate::PossibleValue::new(l).hide(l != "true" && l != "false"))
.map(|l| crate::builder::PossibleValue::new(l).hide(l != "true" && l != "false"))
}
}
@ -1690,7 +1690,7 @@ impl TypedValueParser for BoolishValueParser {
fn possible_values(
&self,
) -> Option<Box<dyn Iterator<Item = crate::PossibleValue<'static>> + '_>> {
) -> Option<Box<dyn Iterator<Item = crate::builder::PossibleValue<'static>> + '_>> {
Some(Box::new(Self::possible_values()))
}
}
@ -2028,11 +2028,11 @@ pub mod via_prelude {
/// # fn value_variants<'a>() -> &'a [Self] {
/// # &[Self::Always, Self::Auto, Self::Never]
/// # }
/// # fn to_possible_value<'a>(&self) -> Option<clap::PossibleValue<'a>> {
/// # fn to_possible_value<'a>(&self) -> Option<clap::builder::PossibleValue<'a>> {
/// # match self {
/// # Self::Always => Some(clap::PossibleValue::new("always")),
/// # Self::Auto => Some(clap::PossibleValue::new("auto")),
/// # Self::Never => Some(clap::PossibleValue::new("never")),
/// # Self::Always => Some(clap::builder::PossibleValue::new("always")),
/// # Self::Auto => Some(clap::builder::PossibleValue::new("auto")),
/// # Self::Never => Some(clap::builder::PossibleValue::new("never")),
/// # }
/// # }
/// }

View file

@ -1,7 +1,8 @@
//! This module contains traits that are usable with the `#[derive(...)].`
//! macros in [`clap_derive`].
use crate::{ArgMatches, Command, Error, PossibleValue};
use crate::builder::PossibleValue;
use crate::{ArgMatches, Command, Error};
use std::ffi::OsString;

View file

@ -8,7 +8,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind};
/// # use clap::{Command, Arg, error::ErrorKind};
/// let result = Command::new("prog")
/// .arg(Arg::new("speed")
/// .value_parser(["fast", "slow"]))
@ -23,7 +23,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, arg, ErrorKind};
/// # use clap::{Command, arg, error::ErrorKind};
/// let result = Command::new("prog")
/// .arg(arg!(--flag "some flag"))
/// .try_get_matches_from(vec!["prog", "--other"]);
@ -41,7 +41,7 @@ pub enum ErrorKind {
///
#[cfg_attr(not(feature = "suggestions"), doc = " ```no_run")]
#[cfg_attr(feature = "suggestions", doc = " ```")]
/// # use clap::{Command, Arg, ErrorKind, };
/// # use clap::{Command, Arg, error::ErrorKind, };
/// let result = Command::new("prog")
/// .subcommand(Command::new("config")
/// .about("Used for configuration")
@ -60,7 +60,7 @@ pub enum ErrorKind {
/// sign to provide values.
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let res = Command::new("prog")
/// .arg(Arg::new("color")
/// .action(ArgAction::Set)
@ -78,7 +78,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, value_parser};
/// # use clap::{Command, Arg, error::ErrorKind, value_parser};
/// fn is_numeric(val: &str) -> Result<(), String> {
/// match val.parse::<i64>() {
/// Ok(..) => Ok(()),
@ -101,7 +101,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind};
/// # use clap::{Command, Arg, error::ErrorKind};
/// let result = Command::new("prog")
/// .arg(Arg::new("arg")
/// .number_of_values(1..=2)
@ -120,7 +120,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind};
/// # use clap::{Command, Arg, error::ErrorKind};
/// let result = Command::new("prog")
/// .arg(Arg::new("some_opt")
/// .long("opt")
@ -139,7 +139,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let result = Command::new("prog")
/// .arg(Arg::new("some_opt")
/// .long("opt")
@ -160,7 +160,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// let result = Command::new("prog")
/// .arg(Arg::new("debug")
/// .long("debug")
@ -180,7 +180,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind};
/// # use clap::{Command, Arg, error::ErrorKind};
/// let result = Command::new("prog")
/// .arg(Arg::new("debug")
/// .required(true))
@ -196,7 +196,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, ErrorKind};
/// # use clap::{Command, error::ErrorKind};
/// let err = Command::new("prog")
/// .subcommand_required(true)
/// .subcommand(Command::new("test"))
@ -226,7 +226,7 @@ pub enum ErrorKind {
///
#[cfg_attr(not(unix), doc = " ```ignore")]
#[cfg_attr(unix, doc = " ```")]
/// # use clap::{Command, Arg, ErrorKind, ArgAction};
/// # use clap::{Command, Arg, error::ErrorKind, ArgAction};
/// # use std::os::unix::ffi::OsStringExt;
/// # use std::ffi::OsString;
/// let result = Command::new("prog")
@ -253,7 +253,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind};
/// # use clap::{Command, Arg, error::ErrorKind};
/// let result = Command::new("prog")
/// .try_get_matches_from(vec!["prog", "--help"]);
/// assert!(result.is_err());
@ -268,7 +268,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind, };
/// # use clap::{Command, Arg, error::ErrorKind, };
/// let result = Command::new("prog")
/// .arg_required_else_help(true)
/// .subcommand(Command::new("config")
@ -290,7 +290,7 @@ pub enum ErrorKind {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ErrorKind};
/// # use clap::{Command, Arg, error::ErrorKind};
/// let result = Command::new("prog")
/// .version("3.0")
/// .try_get_matches_from(vec!["prog", "--version"]);

View file

@ -99,6 +99,7 @@ compile_error!("`std` feature is currently required to build `clap`");
pub use crate::builder::ArgAction;
pub use crate::builder::Command;
pub use crate::builder::ValueHint;
pub use crate::builder::{Arg, ArgGroup};
pub use crate::error::Error;
pub use crate::parser::ArgMatches;
@ -110,12 +111,6 @@ pub(crate) use crate::util::color::ColorChoice;
pub use crate::derive::{Args, CommandFactory, FromArgMatches, Parser, Subcommand, ValueEnum};
#[allow(deprecated)]
pub use crate::builder::{PossibleValue, ValueHint};
pub use crate::error::{ErrorKind, Result};
#[allow(deprecated)]
pub use crate::parser::{Indices, ValueSource};
#[cfg(feature = "derive")]
#[doc(hidden)]
pub use clap_derive::{self, *};

View file

@ -562,7 +562,6 @@ macro_rules! impl_settings {
#[allow(dead_code)]
pub(crate) fn set(&mut self, s: $settings) {
#[allow(deprecated)] // some Settings might be deprecated
match s {
$(
$(#[$inner $($args)*])*
@ -573,7 +572,6 @@ macro_rules! impl_settings {
#[allow(dead_code)]
pub(crate) fn unset(&mut self, s: $settings) {
#[allow(deprecated)] // some Settings might be deprecated
match s {
$(
$(#[$inner $($args)*])*
@ -584,7 +582,6 @@ macro_rules! impl_settings {
#[allow(dead_code)]
pub(crate) fn is_set(&self, s: $settings) -> bool {
#[allow(deprecated)] // some Settings might be deprecated
match s {
$(
$(#[$inner $($args)*])*

View file

@ -6,10 +6,10 @@ use std::io::{self, Write};
use std::usize;
// Internal
use crate::builder::PossibleValue;
use crate::builder::{render_arg_val, Arg, Command};
use crate::output::{fmt::Colorizer, Usage};
use crate::ArgAction;
use crate::PossibleValue;
// Third party
use indexmap::IndexSet;

View file

@ -128,7 +128,6 @@ impl<'help, 'cmd> Usage<'help, 'cmd> {
|| self.cmd.is_allow_external_subcommands_set()
{
let placeholder = self.cmd.get_subcommand_value_name().unwrap_or("SUBCOMMAND");
#[allow(deprecated)]
if self.cmd.is_subcommand_negates_reqs_set()
|| self.cmd.is_args_conflicts_with_subcommands_set()
{

View file

@ -159,8 +159,6 @@ impl ArgMatcher {
let ma = self.entry(id).or_insert(MatchedArg::new_arg(arg));
debug_assert_eq!(ma.type_id(), Some(arg.get_value_parser().type_id()));
ma.set_source(ValueSource::CommandLine);
#[allow(deprecated)]
ma.inc_occurrences();
ma.new_val_group();
}
@ -169,8 +167,6 @@ impl ArgMatcher {
let ma = self.entry(id).or_insert(MatchedArg::new_group());
debug_assert_eq!(ma.type_id(), None);
ma.set_source(ValueSource::CommandLine);
#[allow(deprecated)]
ma.inc_occurrences();
ma.new_val_group();
}
@ -187,8 +183,6 @@ impl ArgMatcher {
)
);
ma.set_source(ValueSource::CommandLine);
#[allow(deprecated)]
ma.inc_occurrences();
ma.new_val_group();
}

View file

@ -26,7 +26,8 @@ use crate::INTERNAL_ERROR_MSG;
/// # Examples
///
/// ```no_run
/// # use clap::{Command, Arg, ValueSource, ArgAction};
/// # use clap::{Command, Arg, ArgAction};
/// # use clap::parser::ValueSource;
/// let matches = Command::new("MyApp")
/// .arg(Arg::new("out")
/// .long("output")
@ -381,25 +382,6 @@ impl ArgMatches {
Some(v)
}
/// Deprecated, replaced with [`ArgAction::SetTrue`][crate::ArgAction] or
/// [`ArgMatches::contains_id`].
#[cfg_attr(
feature = "deprecated",
deprecated(
since = "3.2.0",
note = "Replaced with either `ArgAction::SetTrue` or `ArgMatches::contains_id(...)`"
)
)]
#[cfg_attr(debug_assertions, track_caller)]
pub fn is_present<T: Key>(&self, id: T) -> bool {
let id = Id::from(id);
#[cfg(debug_assertions)]
self.get_arg(&id);
self.args.contains_key(&id)
}
/// Report where argument value came from
///
/// # Panics
@ -409,7 +391,8 @@ impl ArgMatches {
/// # Examples
///
/// ```rust
/// # use clap::{Command, Arg, ValueSource, ArgAction};
/// # use clap::{Command, Arg, ArgAction};
/// # use clap::parser::ValueSource;
/// let m = Command::new("myprog")
/// .arg(Arg::new("debug")
/// .short('d')
@ -431,22 +414,6 @@ impl ArgMatches {
value.and_then(MatchedArg::source)
}
/// Deprecated, replaced with [`ArgAction::Count`][crate::ArgAction],
/// [`ArgMatches::get_many`]`.len()`, or [`ArgMatches::value_source`].
#[cfg_attr(
feature = "deprecated",
deprecated(
since = "3.2.0",
note = "Replaced with either `ArgAction::Count`, `ArgMatches::get_many(...).len()`, or `ArgMatches::value_source`"
)
)]
#[cfg_attr(debug_assertions, track_caller)]
pub fn occurrences_of<T: Key>(&self, id: T) -> u64 {
#![allow(deprecated)]
self.get_arg(&Id::from(id))
.map_or(0, |a| a.get_occurrences())
}
/// The first index of that an argument showed up.
///
/// Indices are similar to argv indices, but are not exactly 1:1.
@ -1344,7 +1311,6 @@ impl<'a> ExactSizeIterator for GroupedValues<'a> {}
/// Creates an empty iterator. Used for `unwrap_or_default()`.
impl<'a> Default for GroupedValues<'a> {
fn default() -> Self {
#![allow(deprecated)]
static EMPTY: [Vec<AnyValue>; 0] = [];
GroupedValues {
iter: EMPTY[..].iter().map(|_| unreachable!()),

View file

@ -14,7 +14,6 @@ use crate::INTERNAL_ERROR_MSG;
#[derive(Debug, Clone)]
pub(crate) struct MatchedArg {
occurs: u64,
source: Option<ValueSource>,
indices: Vec<usize>,
type_id: Option<AnyValueId>,
@ -27,7 +26,6 @@ impl MatchedArg {
pub(crate) fn new_arg(arg: &crate::Arg) -> Self {
let ignore_case = arg.is_ignore_case_set();
Self {
occurs: 0,
source: None,
indices: Vec::new(),
type_id: Some(arg.get_value_parser().type_id()),
@ -40,7 +38,6 @@ impl MatchedArg {
pub(crate) fn new_group() -> Self {
let ignore_case = false;
Self {
occurs: 0,
source: None,
indices: Vec::new(),
type_id: None,
@ -53,7 +50,6 @@ impl MatchedArg {
pub(crate) fn new_external(cmd: &crate::Command) -> Self {
let ignore_case = false;
Self {
occurs: 0,
source: None,
indices: Vec::new(),
type_id: Some(
@ -67,16 +63,6 @@ impl MatchedArg {
}
}
#[cfg_attr(feature = "deprecated", deprecated(since = "3.2.0"))]
pub(crate) fn inc_occurrences(&mut self) {
self.occurs += 1;
}
#[cfg_attr(feature = "deprecated", deprecated(since = "3.2.0"))]
pub(crate) fn get_occurrences(&self) -> u64 {
self.occurs
}
pub(crate) fn indices(&self) -> Cloned<Iter<'_, usize>> {
self.indices.iter().cloned()
}
@ -190,7 +176,6 @@ impl MatchedArg {
impl PartialEq for MatchedArg {
fn eq(&self, other: &MatchedArg) -> bool {
let MatchedArg {
occurs: self_occurs,
source: self_source,
indices: self_indices,
type_id: self_type_id,
@ -199,7 +184,6 @@ impl PartialEq for MatchedArg {
ignore_case: self_ignore_case,
} = self;
let MatchedArg {
occurs: other_occurs,
source: other_source,
indices: other_indices,
type_id: other_type_id,
@ -207,8 +191,7 @@ impl PartialEq for MatchedArg {
raw_vals: other_raw_vals,
ignore_case: other_ignore_case,
} = other;
self_occurs == other_occurs
&& self_source == other_source
self_source == other_source
&& self_indices == other_indices
&& self_type_id == other_type_id
&& self_raw_vals == other_raw_vals

View file

@ -11,10 +11,6 @@ fn set() {
let matches = cmd.clone().try_get_matches_from(["test"]).unwrap();
assert_eq!(matches.get_one::<String>("mammal"), None);
assert_eq!(matches.contains_id("mammal"), false);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), None);
let matches = cmd
@ -23,10 +19,6 @@ fn set() {
.unwrap();
assert_eq!(matches.get_one::<String>("mammal").unwrap(), "dog");
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(2));
let matches = cmd
@ -35,10 +27,6 @@ fn set() {
.unwrap();
assert_eq!(matches.get_one::<String>("mammal").unwrap(), "cat");
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(4));
}
@ -49,10 +37,6 @@ fn append() {
let matches = cmd.clone().try_get_matches_from(["test"]).unwrap();
assert_eq!(matches.get_one::<String>("mammal"), None);
assert_eq!(matches.contains_id("mammal"), false);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), None);
let matches = cmd
@ -61,10 +45,6 @@ fn append() {
.unwrap();
assert_eq!(matches.get_one::<String>("mammal").unwrap(), "dog");
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(
matches.indices_of("mammal").unwrap().collect::<Vec<_>>(),
vec![2]
@ -83,10 +63,6 @@ fn append() {
vec!["dog", "cat"]
);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(
matches.indices_of("mammal").unwrap().collect::<Vec<_>>(),
vec![2, 4]
@ -101,10 +77,6 @@ fn set_true() {
let matches = cmd.clone().try_get_matches_from(["test"]).unwrap();
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), false);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
let matches = cmd
@ -113,10 +85,6 @@ fn set_true() {
.unwrap();
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), true);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
let matches = cmd
@ -125,10 +93,6 @@ fn set_true() {
.unwrap();
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), true);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(2));
}
@ -147,19 +111,11 @@ fn set_true_with_explicit_default_value() {
.unwrap();
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), true);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
let matches = cmd.clone().try_get_matches_from(["test"]).unwrap();
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), false);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
}
@ -258,10 +214,6 @@ fn set_false() {
let matches = cmd.clone().try_get_matches_from(["test"]).unwrap();
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), true);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
let matches = cmd
@ -270,10 +222,6 @@ fn set_false() {
.unwrap();
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), false);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
let matches = cmd
@ -282,10 +230,6 @@ fn set_false() {
.unwrap();
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), false);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(2));
}
@ -304,19 +248,11 @@ fn set_false_with_explicit_default_value() {
.unwrap();
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), false);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
let matches = cmd.clone().try_get_matches_from(["test"]).unwrap();
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), true);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
}
@ -381,10 +317,6 @@ fn count() {
let matches = cmd.clone().try_get_matches_from(["test"]).unwrap();
assert_eq!(*matches.get_one::<u8>("mammal").unwrap(), 0);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
let matches = cmd
@ -393,10 +325,6 @@ fn count() {
.unwrap();
assert_eq!(*matches.get_one::<u8>("mammal").unwrap(), 1);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
let matches = cmd
@ -405,10 +333,6 @@ fn count() {
.unwrap();
assert_eq!(*matches.get_one::<u8>("mammal").unwrap(), 2);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(2));
}
@ -427,19 +351,11 @@ fn count_with_explicit_default_value() {
.unwrap();
assert_eq!(*matches.get_one::<u8>("mammal").unwrap(), 1);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
let matches = cmd.clone().try_get_matches_from(["test"]).unwrap();
assert_eq!(*matches.get_one::<u8>("mammal").unwrap(), 10);
assert_eq!(matches.contains_id("mammal"), true);
#[allow(deprecated)]
{
assert_eq!(matches.occurrences_of("mammal"), 0);
}
assert_eq!(matches.index_of("mammal"), Some(1));
}

View file

@ -1218,7 +1218,6 @@ fn aaos_pos_mult() {
#[test]
fn aaos_option_use_delim_false() {
#![allow(deprecated)]
let m = Command::new("posix")
.arg(
arg!(--opt <val> "some option")

View file

@ -21,7 +21,7 @@ fn opt_missing() {
);
assert_eq!(
m.value_source("color").unwrap(),
clap::ValueSource::DefaultValue
clap::parser::ValueSource::DefaultValue
);
assert_eq!(m.index_of("color"), Some(1));
}
@ -47,7 +47,7 @@ fn opt_present_with_missing_value() {
);
assert_eq!(
m.value_source("color").unwrap(),
clap::ValueSource::CommandLine
clap::parser::ValueSource::CommandLine
);
assert_eq!(m.index_of("color"), Some(2));
}
@ -73,7 +73,7 @@ fn opt_present_with_value() {
);
assert_eq!(
m.value_source("color").unwrap(),
clap::ValueSource::CommandLine
clap::parser::ValueSource::CommandLine
);
assert_eq!(m.index_of("color"), Some(2));
}
@ -98,7 +98,7 @@ fn opt_present_with_empty_value() {
);
assert_eq!(
m.value_source("color").unwrap(),
clap::ValueSource::CommandLine
clap::parser::ValueSource::CommandLine
);
assert_eq!(m.index_of("color"), Some(2));
}
@ -183,7 +183,7 @@ fn default_missing_value_flag_value() {
);
assert_eq!(
m.value_source("flag").unwrap(),
clap::ValueSource::DefaultValue
clap::parser::ValueSource::DefaultValue
);
let m = cmd
@ -197,7 +197,7 @@ fn default_missing_value_flag_value() {
);
assert_eq!(
m.value_source("flag").unwrap(),
clap::ValueSource::CommandLine
clap::parser::ValueSource::CommandLine
);
let m = cmd
@ -211,7 +211,7 @@ fn default_missing_value_flag_value() {
);
assert_eq!(
m.value_source("flag").unwrap(),
clap::ValueSource::CommandLine
clap::parser::ValueSource::CommandLine
);
let m = cmd.try_get_matches_from(&["test", "--flag=false"]).unwrap();
@ -222,7 +222,7 @@ fn default_missing_value_flag_value() {
);
assert_eq!(
m.value_source("flag").unwrap(),
clap::ValueSource::CommandLine
clap::parser::ValueSource::CommandLine
);
}
@ -308,7 +308,7 @@ fn valid_index() {
);
assert_eq!(
m.value_source("color").unwrap(),
clap::ValueSource::CommandLine
clap::parser::ValueSource::CommandLine
);
// Make sure the index reflects `--color`s position and not something else

View file

@ -1,6 +1,6 @@
use super::utils;
use clap::{arg, error::ErrorKind, Arg, ArgAction, ArgGroup, Command, PossibleValue};
use clap::{arg, builder::PossibleValue, error::ErrorKind, Arg, ArgAction, ArgGroup, Command};
fn setup() -> Command<'static> {
Command::new("test")

View file

@ -1,6 +1,6 @@
use super::utils;
use clap::{error::ErrorKind, Arg, ArgAction, Command, PossibleValue};
use clap::{builder::PossibleValue, error::ErrorKind, Arg, ArgAction, Command};
#[cfg(feature = "suggestions")]
static PV_ERROR: &str = "error: \"slo\" isn't a valid value for '-O <option>'

View file

@ -306,7 +306,6 @@ fn allow_invalid_utf8_subcommand_args_with_allow_external_subcommands() {
#[test]
fn allow_validated_utf8_value_of() {
#![allow(deprecated)]
let a = Command::new("test").arg(arg!(--name <NAME>));
let m = a.try_get_matches_from(["test", "--name", "me"]).unwrap();
let _ = m.get_one::<String>("name").map(|v| v.as_str());

View file

@ -114,7 +114,7 @@ fn vec_type_is_multiple_values() {
Opt::try_parse_from(&["test", "24", "42"]).unwrap()
);
assert_eq!(
clap::ErrorKind::ValueValidation,
clap::error::ErrorKind::ValueValidation,
Opt::try_parse_from(&["test", "NOPE"]).err().unwrap().kind()
);
}

View file

@ -12,8 +12,6 @@
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
// MIT/Apache 2.0 license.
#![allow(deprecated)]
use clap::Parser;
use std::num::ParseIntError;

View file

@ -12,8 +12,6 @@
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
// MIT/Apache 2.0 license.
#![allow(deprecated)]
use clap::Parser;
#[test]

View file

@ -12,7 +12,8 @@
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
// MIT/Apache 2.0 license.
use clap::{ErrorKind, Parser};
use clap::error::ErrorKind;
use clap::Parser;
use std::num::ParseIntError;
pub const DISPLAY_ORDER: usize = 2;

View file

@ -549,7 +549,10 @@ fn skip_subcommand() {
);
let res = Opt::try_parse_from(&["test", "skip"]);
assert_eq!(res.unwrap_err().kind(), clap::ErrorKind::UnknownArgument,);
assert_eq!(
res.unwrap_err().kind(),
clap::error::ErrorKind::UnknownArgument,
);
}
#[test]

View file

@ -1,5 +1,4 @@
//! Regression test to ensure that type aliases do not cause compilation failures.
#![allow(deprecated)]
use clap::{Parser, Subcommand, ValueEnum};

View file

@ -1,6 +1,7 @@
#![cfg(not(windows))]
use clap::{ErrorKind, Parser};
use clap::error::ErrorKind;
use clap::Parser;
use std::ffi::OsString;
use std::os::unix::ffi::OsStringExt;

View file

@ -410,8 +410,8 @@ fn skip_variant() {
.map(Option::unwrap)
.collect::<Vec<_>>(),
vec![
clap::PossibleValue::new("foo"),
clap::PossibleValue::new("bar")
clap::builder::PossibleValue::new("foo"),
clap::builder::PossibleValue::new("bar")
]
);
@ -441,8 +441,8 @@ fn skip_non_unit_variant() {
.map(Option::unwrap)
.collect::<Vec<_>>(),
vec![
clap::PossibleValue::new("foo"),
clap::PossibleValue::new("bar")
clap::builder::PossibleValue::new("foo"),
clap::builder::PossibleValue::new("bar")
]
);

View file

@ -275,10 +275,6 @@ mod arg_impl {
.arg(arg)
.try_get_matches_from(vec!["", "some-val"])
.unwrap();
#[allow(deprecated)]
{
assert!(m.is_present("some-arg"));
}
assert_eq!(m.get_one::<String>("some-arg").unwrap(), "some-val");
}
@ -299,10 +295,6 @@ mod arg_impl {
.arg(arg)
.try_get_matches_from(vec!["", "-a", "val"])
.unwrap();
#[allow(deprecated)]
{
assert!(m.is_present("some-val"));
}
assert_eq!(m.get_one::<String>("some-val").unwrap(), "val");
}
@ -323,10 +315,6 @@ mod arg_impl {
.arg(arg)
.try_get_matches_from(vec!["", "--arg", "some-val"])
.unwrap();
#[allow(deprecated)]
{
assert!(m.is_present("arg"));
}
assert_eq!(m.get_one::<String>("arg").unwrap(), "some-val");
}
}