fix: Rename to Arg::ignore_case like ArgSettings

Fixes #32
This commit is contained in:
Ed Page 2021-11-29 10:34:42 -06:00
parent 8fc12586bb
commit 57e5fc2b07
12 changed files with 44 additions and 37 deletions

View file

@ -837,8 +837,8 @@ impl Attrs {
self.is_enum
}
pub fn case_insensitive(&self) -> TokenStream {
let method = self.find_method("case_insensitive");
pub fn ignore_case(&self) -> TokenStream {
let method = self.find_method("ignore_case");
if let Some(method) = method {
method.args.clone()

View file

@ -558,7 +558,7 @@ fn gen_parsers(
FromFlag => (quote!(), quote!(), func.clone()),
};
if attrs.is_enum() {
let ci = attrs.case_insensitive();
let ci = attrs.ignore_case();
parse = quote_spanned! { convert_type.span()=>
|s| <#convert_type as clap::ArgEnum>::from_str(s, #ci).map_err(|err| clap::Error::raw(clap::ErrorKind::ValueValidation, format!("Invalid value for {}: {}", #name, err)))

View file

@ -79,7 +79,7 @@ pub fn arg_enum(name: &Ident) {
fn value_variants<'a>() -> &'a [Self]{
unimplemented!()
}
fn from_str(_input: &str, _case_insensitive: bool) -> Result<Self, String> {
fn from_str(_input: &str, _ignore_case: bool) -> Result<Self, String> {
unimplemented!()
}
fn to_possible_value<'a>(&self) -> Option<clap::PossibleValue<'a>>{

View file

@ -186,7 +186,7 @@ fn casing_propagation_is_overridden() {
}
#[test]
fn case_insensitive() {
fn ignore_case() {
#[derive(ArgEnum, PartialEq, Debug, Clone)]
enum ArgChoice {
Foo,
@ -194,7 +194,7 @@ fn case_insensitive() {
#[derive(Parser, PartialEq, Debug)]
struct Opt {
#[clap(arg_enum, case_insensitive(true))]
#[clap(arg_enum, ignore_case(true))]
arg: ArgChoice,
}
@ -213,7 +213,7 @@ fn case_insensitive() {
}
#[test]
fn case_insensitive_set_to_false() {
fn ignore_case_set_to_false() {
#[derive(ArgEnum, PartialEq, Debug, Clone)]
enum ArgChoice {
Foo,
@ -221,7 +221,7 @@ fn case_insensitive_set_to_false() {
#[derive(Parser, PartialEq, Debug)]
struct Opt {
#[clap(arg_enum, case_insensitive(false))]
#[clap(arg_enum, ignore_case(false))]
arg: ArgChoice,
}
@ -244,7 +244,7 @@ fn alias() {
#[derive(Parser, PartialEq, Debug)]
struct Opt {
#[clap(arg_enum, case_insensitive(false))]
#[clap(arg_enum, ignore_case(false))]
arg: ArgChoice,
}
@ -272,7 +272,7 @@ fn multiple_alias() {
#[derive(Parser, PartialEq, Debug)]
struct Opt {
#[clap(arg_enum, case_insensitive(false))]
#[clap(arg_enum, ignore_case(false))]
arg: ArgChoice,
}

View file

@ -10,7 +10,7 @@ use clap::Parser;
#[derive(Parser, Debug)]
struct Opt {
#[clap(raw(case_insensitive = "true"))]
#[clap(raw(ignore_case = "true"))]
s: String,
}

View file

@ -1,11 +1,11 @@
error: `#[clap(raw(...))` attributes are removed, they are replaced with raw methods
= help: if you meant to call `clap::Arg::raw()` method you should use bool literal, like `raw(true)` or `raw(false)`
= note: if you need to call `clap::Arg/App::case_insensitive` method you can do it like this: #[clap(case_insensitive = true)]
= note: if you need to call `clap::Arg/App::ignore_case` method you can do it like this: #[clap(ignore_case = true)]
--> $DIR/raw.rs:13:12
|
13 | #[clap(raw(case_insensitive = "true"))]
13 | #[clap(raw(ignore_case = "true"))]
| ^^^
error: `#[clap(raw(...))` attributes are removed, they are replaced with raw methods

View file

@ -434,7 +434,7 @@ impl<'help> Arg<'help> {
"overrides_with_all" => yaml_vec_or_str!(a, v, overrides_with),
"possible_value" => yaml_to_str!(a, v, possible_value),
"possible_values" => yaml_vec_or_str!(a, v, possible_value),
"case_insensitive" => yaml_to_bool!(a, v, case_insensitive),
"ignore_case" => yaml_to_bool!(a, v, ignore_case),
"required_unless_present_any" => yaml_vec!(a, v, required_unless_present_any),
"required_unless_present_all" => yaml_vec!(a, v, required_unless_present_all),
"visible_alias" => yaml_to_str!(a, v, visible_alias),
@ -1642,7 +1642,7 @@ impl<'help> Arg<'help> {
/// .long("config"))
/// .arg(Arg::new("other")
/// .long("other")
/// .case_insensitive(true)
/// .ignore_case(true)
/// .takes_value(true))
/// .try_get_matches_from(vec![
/// "prog", "--other", "SPECIAL"
@ -4004,7 +4004,7 @@ impl<'help> Arg<'help> {
/// .arg(Arg::new("option")
/// .long("--option")
/// .takes_value(true)
/// .case_insensitive(true)
/// .ignore_case(true)
/// .possible_value("test123"))
/// .get_matches_from(vec![
/// "pv", "--option", "TeSt123",
@ -4022,7 +4022,7 @@ impl<'help> Arg<'help> {
/// .short('o')
/// .long("--option")
/// .takes_value(true)
/// .case_insensitive(true)
/// .ignore_case(true)
/// .multiple_values(true)
/// .possible_values(&["test123", "test321"]))
/// .get_matches_from(vec![
@ -4033,7 +4033,7 @@ impl<'help> Arg<'help> {
/// assert_eq!(&*matched_vals, &["TeSt123", "teST123", "tESt321"]);
/// ```
#[inline]
pub fn case_insensitive(self, ci: bool) -> Self {
pub fn ignore_case(self, ci: bool) -> Self {
if ci {
self.setting(ArgSettings::IgnoreCase)
} else {
@ -4041,6 +4041,13 @@ impl<'help> Arg<'help> {
}
}
/// Deprecated, replaced with [`Arg::ignore_case`]
#[deprecated(since = "3.0.0", note = "Replaced with `Arg::ignore_case`")]
#[inline]
pub fn case_insensitive(self, ci: bool) -> Self {
self.ignore_case(ci)
}
/// Specifies that an argument should allow grouping of multiple values via a
/// delimiter.
///

View file

@ -313,13 +313,13 @@ pub trait ArgEnum: Sized + Clone {
fn value_variants<'a>() -> &'a [Self];
/// Parse an argument into `Self`.
fn from_str(input: &str, case_insensitive: bool) -> Result<Self, String> {
fn from_str(input: &str, ignore_case: bool) -> Result<Self, String> {
Self::value_variants()
.iter()
.find(|v| {
v.to_possible_value()
.expect("ArgEnum::value_variants contains only values with a corresponding ArgEnum::to_possible_value")
.matches(input, case_insensitive)
.matches(input, ignore_case)
})
.cloned()
.ok_or_else(|| format!("Invalid variant: {}", input))

View file

@ -115,11 +115,11 @@ args:
long: exclusive
help: Tests 3 exclusive
exclusive: true
- case_insensitive:
- ignore_case:
index: 4
help: Test case_insensitive
help: Test ignore case
possible_values: [test123, test321]
case_insensitive: true
ignore_case: true
- value_hint:
long: value-hint
help: Test value_hint

View file

@ -275,7 +275,7 @@ fn alias() {
.takes_value(true)
.possible_value(PossibleValue::new("test123").alias("123"))
.possible_value("test321")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["pv", "--option", "123"]);
@ -293,7 +293,7 @@ fn aliases() {
.takes_value(true)
.possible_value(PossibleValue::new("test123").aliases(["1", "2", "3"]))
.possible_value("test321")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["pv", "--option", "2"]);
@ -302,7 +302,7 @@ fn aliases() {
}
#[test]
fn case_insensitive() {
fn ignore_case() {
let m = App::new("pv")
.arg(
Arg::new("option")
@ -311,7 +311,7 @@ fn case_insensitive() {
.takes_value(true)
.possible_value("test123")
.possible_value("test321")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["pv", "--option", "TeSt123"]);
@ -324,7 +324,7 @@ fn case_insensitive() {
}
#[test]
fn case_insensitive_fail() {
fn ignore_case_fail() {
let m = App::new("pv")
.arg(
Arg::new("option")
@ -341,7 +341,7 @@ fn case_insensitive_fail() {
}
#[test]
fn case_insensitive_multiple() {
fn ignore_case_multiple() {
let m = App::new("pv")
.arg(
Arg::new("option")
@ -351,7 +351,7 @@ fn case_insensitive_multiple() {
.possible_value("test123")
.possible_value("test321")
.multiple_values(true)
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["pv", "--option", "TeSt123", "teST123", "tESt321"]);
@ -363,7 +363,7 @@ fn case_insensitive_multiple() {
}
#[test]
fn case_insensitive_multiple_fail() {
fn ignore_case_multiple_fail() {
let m = App::new("pv")
.arg(
Arg::new("option")

View file

@ -543,7 +543,7 @@ fn required_if_val_present_fail() {
}
#[test]
fn required_if_val_present_case_insensitive_pass() {
fn required_if_val_present_ignore_case_pass() {
let res = App::new("ri")
.arg(
Arg::new("cfg")
@ -555,7 +555,7 @@ fn required_if_val_present_case_insensitive_pass() {
Arg::new("extra")
.takes_value(true)
.long("extra")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["ri", "--extra", "vaL", "--config", "my.cfg"]);
@ -563,7 +563,7 @@ fn required_if_val_present_case_insensitive_pass() {
}
#[test]
fn required_if_val_present_case_insensitive_fail() {
fn required_if_val_present_ignore_case_fail() {
let res = App::new("ri")
.arg(
Arg::new("cfg")
@ -575,7 +575,7 @@ fn required_if_val_present_case_insensitive_fail() {
Arg::new("extra")
.takes_value(true)
.long("extra")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["ri", "--extra", "vaL"]);

View file

@ -1,7 +1,7 @@
#![cfg(feature = "unicode")]
#[test]
fn possible_values_case_insensitive() {
fn possible_values_ignore_case() {
let m = clap::App::new("pv")
.arg(
clap::Arg::new("option")
@ -9,7 +9,7 @@ fn possible_values_case_insensitive() {
.long("--option")
.takes_value(true)
.possible_value("ä")
.case_insensitive(true),
.ignore_case(true),
)
.try_get_matches_from(vec!["pv", "--option", "Ä"]);