diff --git a/clap_derive/src/attrs.rs b/clap_derive/src/attrs.rs index 5960b8ac387..ae784b519e3 100644 --- a/clap_derive/src/attrs.rs +++ b/clap_derive/src/attrs.rs @@ -784,9 +784,18 @@ impl Attrs { .unwrap_or_else(|| { if let Some(action) = self.action.as_ref() { let inner_type = inner_type(field_type); - default_value_parser(inner_type, action.span()) - } else { + let span = action.span(); + default_value_parser(inner_type, span) + } else if !self.ignore_parser() || cfg!(not(feature = "unstable-v4")) { self.parser(field_type).value_parser() + } else { + let inner_type = inner_type(field_type); + let span = self + .action + .as_ref() + .map(|a| a.span()) + .unwrap_or_else(|| self.kind.span()); + default_value_parser(inner_type, span) } }) } @@ -797,13 +806,27 @@ impl Attrs { .map(|p| p.resolve(field_type)) .unwrap_or_else(|| { if let Some(value_parser) = self.value_parser.as_ref() { - default_action(field_type, value_parser.span()) - } else { + let span = value_parser.span(); + default_action(field_type, span) + } else if !self.ignore_parser() || cfg!(not(feature = "unstable-v4")) { self.parser(field_type).action() + } else { + let span = self + .value_parser + .as_ref() + .map(|a| a.span()) + .unwrap_or_else(|| self.kind.span()); + default_action(field_type, span) } }) } + #[cfg(feature = "unstable-v4")] + pub fn ignore_parser(&self) -> bool { + self.parser.is_none() + } + + #[cfg(not(feature = "unstable-v4"))] pub fn ignore_parser(&self) -> bool { self.value_parser.is_some() || self.action.is_some() } diff --git a/tests/derive/next/arguments.rs b/tests/derive/next/arguments.rs index 0d3f0b1e262..57c5866d4ee 100644 --- a/tests/derive/next/arguments.rs +++ b/tests/derive/next/arguments.rs @@ -19,7 +19,6 @@ use clap::Parser; fn required_argument() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_parser)] arg: i32, } assert_eq!( @@ -34,7 +33,7 @@ fn required_argument() { fn argument_with_default() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_parser, default_value = "42")] + #[clap(default_value = "42")] arg: i32, } assert_eq!( @@ -49,7 +48,6 @@ fn argument_with_default() { fn auto_value_name() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_parser)] my_special_arg: i32, } @@ -69,7 +67,7 @@ fn auto_value_name() { fn explicit_value_name() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_parser, value_name = "BROWNIE_POINTS")] + #[clap(value_name = "BROWNIE_POINTS")] my_special_arg: i32, } @@ -90,7 +88,6 @@ fn explicit_value_name() { fn option_type_is_optional() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_parser)] arg: Option, } assert_eq!( @@ -105,7 +102,6 @@ fn option_type_is_optional() { fn vec_type_is_multiple_values() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_parser)] arg: Vec, } assert_eq!( diff --git a/tests/derive/next/basic.rs b/tests/derive/next/basic.rs index f32d17791ae..d2e1ca9001a 100644 --- a/tests/derive/next/basic.rs +++ b/tests/derive/next/basic.rs @@ -18,7 +18,7 @@ use clap::Parser; fn basic() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short = 'a', long = "arg", value_parser)] + #[clap(short = 'a', long = "arg")] arg: i32, } assert_eq!( @@ -31,7 +31,7 @@ fn basic() { fn update_basic() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short = 'a', long = "arg", value_parser)] + #[clap(short = 'a', long = "arg")] single_value: i32, } diff --git a/tests/derive/next/boxed.rs b/tests/derive/next/boxed.rs index 0af81f6fcfd..03efbe9c551 100644 --- a/tests/derive/next/boxed.rs +++ b/tests/derive/next/boxed.rs @@ -16,7 +16,6 @@ enum Sub { #[derive(Args, PartialEq, Debug)] struct Ext { - #[clap(value_parser)] arg: u32, } diff --git a/tests/derive/next/custom_string_parsers.rs b/tests/derive/next/custom_string_parsers.rs index ef7f0e88a6b..e0ce4ac9965 100644 --- a/tests/derive/next/custom_string_parsers.rs +++ b/tests/derive/next/custom_string_parsers.rs @@ -22,19 +22,19 @@ use std::path::PathBuf; #[derive(Parser, PartialEq, Debug)] struct PathOpt { - #[clap(short, long, value_parser)] + #[clap(short, long)] path: PathBuf, - #[clap(short, default_value = "../", value_parser)] + #[clap(short, default_value = "../")] default_path: PathBuf, - #[clap(short, value_parser, multiple_occurrences(true))] + #[clap(short, multiple_occurrences(true))] vector_path: Vec, - #[clap(short, value_parser)] + #[clap(short)] option_path_1: Option, - #[clap(short = 'q', value_parser)] + #[clap(short = 'q')] option_path_2: Option, } @@ -135,10 +135,10 @@ struct DefaultedOpt { #[clap(short, parse(from_str))] bytes: Bytes, - #[clap(short, value_parser)] + #[clap(short)] integer: u64, - #[clap(short, value_parser)] + #[clap(short)] path: PathBuf, } diff --git a/tests/derive/next/default_value.rs b/tests/derive/next/default_value.rs index fc07e4c1128..db2b7838014 100644 --- a/tests/derive/next/default_value.rs +++ b/tests/derive/next/default_value.rs @@ -6,7 +6,7 @@ use crate::utils; fn default_value() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_parser, default_value = "3")] + #[clap(default_value = "3")] arg: i32, } assert_eq!(Opt { arg: 3 }, Opt::try_parse_from(&["test"]).unwrap()); @@ -20,7 +20,7 @@ fn default_value() { fn default_value_t() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_parser, default_value_t = 3)] + #[clap(default_value_t = 3)] arg: i32, } assert_eq!(Opt { arg: 3 }, Opt::try_parse_from(&["test"]).unwrap()); @@ -34,7 +34,7 @@ fn default_value_t() { fn auto_default_value_t() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_parser, default_value_t)] + #[clap(default_value_t)] arg: i32, } assert_eq!(Opt { arg: 0 }, Opt::try_parse_from(&["test"]).unwrap()); @@ -50,7 +50,7 @@ fn detect_os_variant() { #[derive(clap::Parser)] pub struct Options { - #[clap(value_parser, default_value_os = ("123".as_ref()))] + #[clap(default_value_os = ("123".as_ref()))] x: String, } Options::command().debug_assert(); diff --git a/tests/derive/next/doc_comments_help.rs b/tests/derive/next/doc_comments_help.rs index e6aab515ce8..bfe152a6102 100644 --- a/tests/derive/next/doc_comments_help.rs +++ b/tests/derive/next/doc_comments_help.rs @@ -23,7 +23,7 @@ fn doc_comments() { struct LoremIpsum { /// Fooify a bar /// and a baz - #[clap(short, long, action)] + #[clap(short, long)] foo: bool, } @@ -39,12 +39,7 @@ fn help_is_better_than_comments() { #[clap(name = "lorem-ipsum", about = "Dolor sit amet")] struct LoremIpsum { /// Fooify a bar - #[clap( - short, - long, - help = "DO NOT PASS A BAR UNDER ANY CIRCUMSTANCES", - action - )] + #[clap(short, long, help = "DO NOT PASS A BAR UNDER ANY CIRCUMSTANCES")] foo: bool, } @@ -76,11 +71,11 @@ fn field_long_doc_comment_both_help_long_help() { /// Dot is removed from multiline comments. /// /// Long help - #[clap(long, action)] + #[clap(long)] foo: bool, /// Dot is removed from one short comment. - #[clap(long, action)] + #[clap(long)] bar: bool, } @@ -111,7 +106,7 @@ fn top_long_doc_comment_both_help_long_help() { /// /// Or something else Foo { - #[clap(value_parser, help = "foo")] + #[clap(help = "foo")] bars: String, }, } @@ -146,7 +141,7 @@ fn verbatim_doc_comment() { #[derive(Parser, Debug)] #[clap(verbatim_doc_comment)] struct SeeFigure1 { - #[clap(long, action)] + #[clap(long)] foo: bool, } @@ -176,10 +171,10 @@ fn verbatim_doc_comment_field() { #[derive(Parser, Debug)] struct Command { /// This help ends in a period. - #[clap(long, verbatim_doc_comment, action)] + #[clap(long, verbatim_doc_comment)] foo: bool, /// This help does not end in a period. - #[clap(long, action)] + #[clap(long)] bar: bool, } @@ -196,7 +191,7 @@ fn multiline_separates_default() { /// Multiline /// /// Doc comment - #[clap(long, default_value = "x", value_parser)] + #[clap(long, default_value = "x")] x: String, } @@ -234,10 +229,7 @@ fn doc_comment_about_handles_both_abouts() { /// Sub doc comment body #[derive(Parser, PartialEq, Eq, Debug)] pub enum Sub { - Compress { - #[clap(value_parser)] - output: String, - }, + Compress { output: String }, } let cmd = Opts::command(); diff --git a/tests/derive/next/explicit_name_no_renaming.rs b/tests/derive/next/explicit_name_no_renaming.rs index 15402e85ab4..dcdbc3820c7 100644 --- a/tests/derive/next/explicit_name_no_renaming.rs +++ b/tests/derive/next/explicit_name_no_renaming.rs @@ -6,7 +6,7 @@ use clap::Parser; fn explicit_short_long_no_rename() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short = '.', long = ".foo", value_parser)] + #[clap(short = '.', long = ".foo")] foo: String, } @@ -27,7 +27,7 @@ fn explicit_short_long_no_rename() { fn explicit_name_no_rename() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(name = ".options", value_parser)] + #[clap(name = ".options")] foo: String, } diff --git a/tests/derive/next/flags.rs b/tests/derive/next/flags.rs index d8e55290d0a..02bcc45b478 100644 --- a/tests/derive/next/flags.rs +++ b/tests/derive/next/flags.rs @@ -20,7 +20,7 @@ use clap::Parser; fn bool_type_is_flag() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, long, action)] + #[clap(short, long)] alice: bool, } @@ -113,7 +113,7 @@ fn non_bool_type_flag() { fn mixed_type_flags() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, long, action)] + #[clap(short, long)] alice: bool, #[clap(short, long, action = clap::ArgAction::Count)] bob: u8, @@ -181,7 +181,6 @@ fn ignore_qualified_bool_type() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(action)] arg: inner::bool, } diff --git a/tests/derive/next/flatten.rs b/tests/derive/next/flatten.rs index df451265baa..77561997bd6 100644 --- a/tests/derive/next/flatten.rs +++ b/tests/derive/next/flatten.rs @@ -20,7 +20,6 @@ use clap::{Args, Parser, Subcommand}; fn flatten() { #[derive(Args, PartialEq, Debug)] struct Common { - #[clap(value_parser)] arg: i32, } @@ -45,7 +44,6 @@ fn flatten() { fn flatten_twice() { #[derive(Args, PartialEq, Debug)] struct Common { - #[clap(value_parser)] arg: i32, } @@ -64,13 +62,12 @@ fn flatten_twice() { fn flatten_in_subcommand() { #[derive(Args, PartialEq, Debug)] struct Common { - #[clap(value_parser)] arg: i32, } #[derive(Args, PartialEq, Debug)] struct Add { - #[clap(short, action)] + #[clap(short)] interactive: bool, #[clap(flatten)] common: Common, @@ -79,7 +76,7 @@ fn flatten_in_subcommand() { #[derive(Parser, PartialEq, Debug)] enum Opt { Fetch { - #[clap(short, action)] + #[clap(short)] all: bool, #[clap(flatten)] common: Common, @@ -108,7 +105,6 @@ fn flatten_in_subcommand() { fn update_args_with_flatten() { #[derive(Args, PartialEq, Debug)] struct Common { - #[clap(value_parser)] arg: i32, } @@ -138,15 +134,13 @@ enum BaseCli { #[derive(Args, PartialEq, Debug)] struct Command1 { - #[clap(value_parser)] arg1: i32, - #[clap(value_parser)] + arg2: i32, } #[derive(Args, PartialEq, Debug)] struct Command2 { - #[clap(value_parser)] arg2: i32, } @@ -199,7 +193,6 @@ fn flatten_with_doc_comment() { #[derive(Args, PartialEq, Debug)] struct Common { /// This is an arg. Arg means "argument". Command line argument. - #[clap(value_parser)] arg: i32, } @@ -227,7 +220,7 @@ fn docstrings_ordering_with_multiple_clap() { /// This is the docstring for Flattened #[derive(Args)] struct Flattened { - #[clap(long, action)] + #[clap(long)] foo: bool, } @@ -248,7 +241,7 @@ fn docstrings_ordering_with_multiple_clap_partial() { /// This is the docstring for Flattened #[derive(Args)] struct Flattened { - #[clap(long, action)] + #[clap(long)] foo: bool, } diff --git a/tests/derive/next/generic.rs b/tests/derive/next/generic.rs index cea94729083..5d484295148 100644 --- a/tests/derive/next/generic.rs +++ b/tests/derive/next/generic.rs @@ -4,7 +4,6 @@ use clap::{Args, Parser}; fn generic_struct_flatten() { #[derive(Args, PartialEq, Debug)] struct Inner { - #[clap(value_parser)] pub answer: isize, } @@ -26,7 +25,6 @@ fn generic_struct_flatten() { fn generic_struct_flatten_w_where_clause() { #[derive(Args, PartialEq, Debug)] struct Inner { - #[clap(value_parser)] pub answer: isize, } @@ -51,7 +49,6 @@ fn generic_struct_flatten_w_where_clause() { fn generic_enum() { #[derive(Args, PartialEq, Debug)] struct Inner { - #[clap(value_parser)] pub answer: isize, } @@ -71,7 +68,6 @@ fn generic_enum() { fn generic_enum_w_where_clause() { #[derive(Args, PartialEq, Debug)] struct Inner { - #[clap(value_parser)] pub answer: isize, } @@ -100,7 +96,6 @@ fn generic_w_fromstr_trait_bound() { T: FromStr + Send + Sync + Clone + 'static, ::Err: std::error::Error + Sync + Send + 'static, { - #[clap(value_parser)] answer: T, } @@ -116,7 +111,6 @@ fn generic_wo_trait_bound() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_parser)] answer: isize, #[clap(skip)] took: Option, @@ -141,7 +135,6 @@ fn generic_where_clause_w_trailing_comma() { T: FromStr + Send + Sync + Clone + 'static, ::Err: std::error::Error + Sync + Send + 'static, { - #[clap(value_parser)] pub answer: T, } diff --git a/tests/derive/next/help.rs b/tests/derive/next/help.rs index 8496248949b..14b6a876d77 100644 --- a/tests/derive/next/help.rs +++ b/tests/derive/next/help.rs @@ -4,11 +4,11 @@ use clap::{AppSettings, Args, CommandFactory, Parser, Subcommand}; fn arg_help_heading_applied() { #[derive(Debug, Clone, Parser)] struct CliOptions { - #[clap(long, value_parser)] + #[clap(long)] #[clap(help_heading = Some("HEADING A"))] should_be_in_section_a: u32, - #[clap(long, value_parser)] + #[clap(long)] no_section: u32, } @@ -42,11 +42,11 @@ fn app_help_heading_applied() { #[derive(Debug, Clone, Parser)] #[clap(next_help_heading = "DEFAULT")] struct CliOptions { - #[clap(long, value_parser)] + #[clap(long)] #[clap(help_heading = Some("HEADING A"))] should_be_in_section_a: u32, - #[clap(long, value_parser)] + #[clap(long)] should_be_in_default_section: u32, } @@ -94,21 +94,21 @@ fn app_help_heading_flattened() { #[clap(subcommand)] sub_a: SubA, - #[clap(long, value_parser)] + #[clap(long)] should_be_in_default_section: u32, } #[derive(Debug, Clone, Args)] #[clap(next_help_heading = "HEADING A")] struct OptionsA { - #[clap(long, value_parser)] + #[clap(long)] should_be_in_section_a: u32, } #[derive(Debug, Clone, Args)] #[clap(next_help_heading = "HEADING B")] struct OptionsB { - #[clap(long, value_parser)] + #[clap(long)] should_be_in_section_b: u32, } @@ -121,7 +121,6 @@ fn app_help_heading_flattened() { SubAOne, #[clap(next_help_heading = "SUB A")] SubATwo { - #[clap(value_parser)] should_be_in_sub_a: u32, }, } @@ -129,19 +128,13 @@ fn app_help_heading_flattened() { #[derive(Debug, Clone, Subcommand)] enum SubB { #[clap(next_help_heading = "SUB B")] - SubBOne { - #[clap(value_parser)] - should_be_in_sub_b: u32, - }, + SubBOne { should_be_in_sub_b: u32 }, } #[derive(Debug, Clone, Subcommand)] enum SubC { #[clap(next_help_heading = "SUB C")] - SubCOne { - #[clap(value_parser)] - should_be_in_sub_c: u32, - }, + SubCOne { should_be_in_sub_c: u32 }, } let cmd = CliOptions::command(); @@ -237,7 +230,7 @@ fn flatten_field_with_help_heading() { #[derive(Debug, Clone, Args)] struct OptionsA { - #[clap(long, value_parser)] + #[clap(long)] should_be_in_section_a: u32, } @@ -264,7 +257,7 @@ fn derive_generated_error_has_full_context() { #[derive(Debug, Parser)] #[clap(subcommand_negates_reqs = true)] struct Opts { - #[clap(long, value_parser)] + #[clap(long)] req_str: String, #[clap(subcommand)] @@ -339,10 +332,10 @@ OPTIONS: #[clap(next_display_order = 10000)] struct A { /// second flag - #[clap(long, action)] + #[clap(long)] flag_a: bool, /// second option - #[clap(long, value_parser)] + #[clap(long)] option_a: Option, } @@ -350,10 +343,10 @@ OPTIONS: #[clap(next_display_order = 10)] struct B { /// first flag - #[clap(long, action)] + #[clap(long)] flag_b: bool, /// first option - #[clap(long, value_parser)] + #[clap(long)] option_b: Option, } @@ -397,20 +390,20 @@ OPTIONS: #[derive(Args, Debug)] struct A { /// second flag - #[clap(long, action)] + #[clap(long)] flag_a: bool, /// second option - #[clap(long, value_parser)] + #[clap(long)] option_a: Option, } #[derive(Args, Debug)] struct B { /// first flag - #[clap(long, action)] + #[clap(long)] flag_b: bool, /// first option - #[clap(long, value_parser)] + #[clap(long)] option_b: Option, } @@ -453,20 +446,20 @@ OPTIONS: #[derive(Args, Debug)] struct A { /// first flag - #[clap(long, action)] + #[clap(long)] flag_a: bool, /// first option - #[clap(long, value_parser)] + #[clap(long)] option_a: Option, } #[derive(Args, Debug)] struct B { /// second flag - #[clap(long, action)] + #[clap(long)] flag_b: bool, /// second option - #[clap(long, value_parser)] + #[clap(long)] option_b: Option, } @@ -505,7 +498,7 @@ OPTIONS: #[derive(Parser, PartialEq, Debug)] struct Args { /// Argument help - #[clap(value_enum, value_parser)] + #[clap(value_enum)] arg: ArgChoice, } diff --git a/tests/derive/next/issues.rs b/tests/derive/next/issues.rs index 22c93c87172..d2c01363b14 100644 --- a/tests/derive/next/issues.rs +++ b/tests/derive/next/issues.rs @@ -9,9 +9,9 @@ fn issue_151_groups_within_subcommands() { #[derive(Args, Debug)] #[clap(group = ArgGroup::new("verb").required(true).multiple(true))] struct Opt { - #[clap(long, group = "verb", value_parser)] + #[clap(long, group = "verb")] foo: Option, - #[clap(long, group = "verb", value_parser)] + #[clap(long, group = "verb")] bar: Option, } @@ -89,7 +89,6 @@ fn issue_418() { #[clap(visible_alias = "ret")] Reticulate { /// How many splines - #[clap(value_parser)] num_splines: u8, }, /// Frobnicate the rest @@ -122,9 +121,8 @@ fn issue_490() { #[derive(Parser, Debug)] struct Opt { - #[clap(value_parser)] opt_vec: Vec, - #[clap(long, value_parser)] + #[clap(long)] opt_opt_vec: Option>, } diff --git a/tests/derive/next/macros.rs b/tests/derive/next/macros.rs index 5dbec71a39c..a2e671b4abc 100644 --- a/tests/derive/next/macros.rs +++ b/tests/derive/next/macros.rs @@ -22,7 +22,7 @@ fn use_option() { ($name:ident: $ty:ty) => { #[derive(Parser)] struct Outer { - #[clap(short, long, value_parser)] + #[clap(short, long)] #[allow(dead_code)] $name: $ty, } diff --git a/tests/derive/next/naming.rs b/tests/derive/next/naming.rs index d0b897f7e89..e3018a02f7c 100644 --- a/tests/derive/next/naming.rs +++ b/tests/derive/next/naming.rs @@ -5,7 +5,7 @@ fn test_standalone_long_generates_kebab_case() { #[derive(Parser, Debug, PartialEq)] #[allow(non_snake_case)] struct Opt { - #[clap(long, action)] + #[clap(long)] FOO_OPTION: bool, } @@ -19,7 +19,7 @@ fn test_standalone_long_generates_kebab_case() { fn test_custom_long_overwrites_default_name() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(long = "foo", action)] + #[clap(long = "foo")] foo_option: bool, } @@ -33,7 +33,7 @@ fn test_custom_long_overwrites_default_name() { fn test_standalone_long_uses_previous_defined_custom_name() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(name = "foo", long, action)] + #[clap(name = "foo", long)] foo_option: bool, } @@ -47,7 +47,7 @@ fn test_standalone_long_uses_previous_defined_custom_name() { fn test_standalone_long_ignores_afterwards_defined_custom_name() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(long, name = "foo", action)] + #[clap(long, name = "foo")] foo_option: bool, } @@ -62,7 +62,7 @@ fn test_standalone_short_generates_kebab_case() { #[derive(Parser, Debug, PartialEq)] #[allow(non_snake_case)] struct Opt { - #[clap(short, action)] + #[clap(short)] FOO_OPTION: bool, } @@ -76,7 +76,7 @@ fn test_standalone_short_generates_kebab_case() { fn test_custom_short_overwrites_default_name() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(short = 'o', action)] + #[clap(short = 'o')] foo_option: bool, } @@ -90,7 +90,7 @@ fn test_custom_short_overwrites_default_name() { fn test_standalone_short_uses_previous_defined_custom_name() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(name = "option", short, action)] + #[clap(name = "option", short)] foo_option: bool, } @@ -104,7 +104,7 @@ fn test_standalone_short_uses_previous_defined_custom_name() { fn test_standalone_short_ignores_afterwards_defined_custom_name() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(short, name = "option", action)] + #[clap(short, name = "option")] foo_option: bool, } @@ -118,7 +118,7 @@ fn test_standalone_short_ignores_afterwards_defined_custom_name() { fn test_standalone_long_uses_previous_defined_casing() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(rename_all = "screaming_snake", long, action)] + #[clap(rename_all = "screaming_snake", long)] foo_option: bool, } @@ -132,7 +132,7 @@ fn test_standalone_long_uses_previous_defined_casing() { fn test_standalone_short_uses_previous_defined_casing() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(rename_all = "screaming_snake", short, action)] + #[clap(rename_all = "screaming_snake", short)] foo_option: bool, } @@ -147,7 +147,7 @@ fn test_standalone_long_works_with_verbatim_casing() { #[derive(Parser, Debug, PartialEq)] #[allow(non_snake_case)] struct Opt { - #[clap(rename_all = "verbatim", long, action)] + #[clap(rename_all = "verbatim", long)] _fOO_oPtiON: bool, } @@ -161,7 +161,7 @@ fn test_standalone_long_works_with_verbatim_casing() { fn test_standalone_short_works_with_verbatim_casing() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(rename_all = "verbatim", short, action)] + #[clap(rename_all = "verbatim", short)] _foo: bool, } @@ -176,7 +176,7 @@ fn test_rename_all_is_propagated_from_struct_to_fields() { #[derive(Parser, Debug, PartialEq)] #[clap(rename_all = "screaming_snake")] struct Opt { - #[clap(long, action)] + #[clap(long)] foo: bool, } @@ -197,7 +197,7 @@ fn test_rename_all_is_not_propagated_from_struct_into_flattened() { #[derive(Parser, Debug, PartialEq)] struct Foo { - #[clap(long, action)] + #[clap(long)] foo: bool, } @@ -213,7 +213,7 @@ fn test_rename_all_is_not_propagated_from_struct_into_flattened() { fn test_lower_is_renamed() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(rename_all = "lower", long, action)] + #[clap(rename_all = "lower", long)] foo_option: bool, } @@ -227,7 +227,7 @@ fn test_lower_is_renamed() { fn test_upper_is_renamed() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(rename_all = "upper", long, action)] + #[clap(rename_all = "upper", long)] foo_option: bool, } @@ -241,10 +241,7 @@ fn test_upper_is_renamed() { fn test_single_word_enum_variant_is_default_renamed_into_kebab_case() { #[derive(Parser, Debug, PartialEq)] enum Opt { - Command { - #[clap(value_parser)] - foo: u32, - }, + Command { foo: u32 }, } assert_eq!( @@ -257,10 +254,7 @@ fn test_single_word_enum_variant_is_default_renamed_into_kebab_case() { fn test_multi_word_enum_variant_is_renamed() { #[derive(Parser, Debug, PartialEq)] enum Opt { - FirstCommand { - #[clap(value_parser)] - foo: u32, - }, + FirstCommand { foo: u32 }, } assert_eq!( @@ -281,7 +275,7 @@ fn test_rename_all_is_not_propagated_from_struct_into_subcommand() { #[derive(Parser, Debug, PartialEq)] enum Foo { Command { - #[clap(long, action)] + #[clap(long)] foo: bool, }, } @@ -301,7 +295,7 @@ fn test_rename_all_is_propagated_from_enum_to_variants() { enum Opt { FirstVariant, SecondVariant { - #[clap(long, value_parser)] + #[clap(long)] foo: String, }, } @@ -319,7 +313,7 @@ fn test_rename_all_is_propagated_from_enum_to_variant_fields() { enum Opt { FirstVariant, SecondVariant { - #[clap(long, value_parser)] + #[clap(long)] foo: String, }, } @@ -339,11 +333,11 @@ fn test_rename_all_is_propagation_can_be_overridden() { enum Opt { #[clap(rename_all = "kebab_case")] FirstVariant { - #[clap(long, action)] + #[clap(long)] foo_option: bool, }, SecondVariant { - #[clap(rename_all = "kebab_case", long, action)] + #[clap(rename_all = "kebab_case", long)] foo_option: bool, }, } diff --git a/tests/derive/next/nested_subcommands.rs b/tests/derive/next/nested_subcommands.rs index 59a5ad57053..e5e32bfff7a 100644 --- a/tests/derive/next/nested_subcommands.rs +++ b/tests/derive/next/nested_subcommands.rs @@ -16,7 +16,7 @@ use clap::{Parser, Subcommand}; #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, long, action)] + #[clap(short, long)] force: bool, #[clap(short, long, action = clap::ArgAction::Count)] verbose: u8, @@ -32,7 +32,7 @@ enum Sub { #[derive(Parser, PartialEq, Debug)] struct Opt2 { - #[clap(short, long, action)] + #[clap(short, long)] force: bool, #[clap(short, long, action = clap::ArgAction::Count)] verbose: u8, @@ -109,7 +109,7 @@ fn test_badinput() { #[derive(Parser, PartialEq, Debug)] struct Opt3 { - #[clap(short, long, action)] + #[clap(short, long)] all: bool, #[clap(subcommand)] cmd: Sub2, @@ -118,7 +118,6 @@ struct Opt3 { #[derive(Subcommand, PartialEq, Debug)] enum Sub2 { Foo { - #[clap(value_parser)] file: String, #[clap(subcommand)] cmd: Sub3, @@ -159,16 +158,8 @@ enum SubSubCmdWithOption { } #[derive(Subcommand, PartialEq, Debug)] enum Remote { - Add { - #[clap(value_parser)] - name: String, - #[clap(value_parser)] - url: String, - }, - Remove { - #[clap(value_parser)] - name: String, - }, + Add { name: String, url: String }, + Remove { name: String }, } #[derive(Subcommand, PartialEq, Debug)] diff --git a/tests/derive/next/non_literal_attributes.rs b/tests/derive/next/non_literal_attributes.rs index bf950fb7baa..97879994418 100644 --- a/tests/derive/next/non_literal_attributes.rs +++ b/tests/derive/next/non_literal_attributes.rs @@ -27,17 +27,16 @@ struct Opt { next_line_help = true, default_value = "0", require_equals = true, - value_parser )] x: i32, - #[clap(short = 'l', long = "level", value_parser, aliases = &["set-level", "lvl"])] + #[clap(short = 'l', long = "level", aliases = &["set-level", "lvl"])] level: String, - #[clap(long("values"), value_parser)] + #[clap(long("values"))] values: Vec, - #[clap(name = "FILE", value_parser, requires_if("FILE", "values"))] + #[clap(name = "FILE", requires_if("FILE", "values"))] files: Vec, } diff --git a/tests/derive/next/options.rs b/tests/derive/next/options.rs index f55dd8805e9..c15cf95057c 100644 --- a/tests/derive/next/options.rs +++ b/tests/derive/next/options.rs @@ -22,7 +22,7 @@ use clap::{Parser, Subcommand}; fn required_option() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, long, value_parser)] + #[clap(short, long)] arg: i32, } assert_eq!( @@ -48,7 +48,7 @@ fn required_option() { fn option_with_default() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, value_parser, default_value = "42")] + #[clap(short, default_value = "42")] arg: i32, } assert_eq!( @@ -66,7 +66,7 @@ fn option_with_default() { fn option_with_raw_default() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, value_parser, default_value = "42")] + #[clap(short, default_value = "42")] arg: i32, } assert_eq!( @@ -95,7 +95,6 @@ fn option_from_str() { #[derive(Debug, Parser, PartialEq)] struct Opt { - #[clap(value_parser)] a: Option, } @@ -121,7 +120,6 @@ fn vec_from_str() { #[derive(Debug, Parser, PartialEq)] struct Opt { - #[clap(value_parser)] a: Vec, } @@ -150,7 +148,7 @@ fn option_vec_from_str() { #[derive(Debug, Parser, PartialEq)] struct Opt { - #[clap(short, value_parser)] + #[clap(short)] a: Option>, } @@ -165,7 +163,7 @@ fn option_vec_from_str() { fn option_type_is_optional() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, value_parser)] + #[clap(short)] arg: Option, } assert_eq!( @@ -184,7 +182,7 @@ fn required_with_option_type() { #[derive(Debug, PartialEq, Eq, Parser)] #[clap(subcommand_negates_reqs = true)] struct Opt { - #[clap(value_parser, required = true)] + #[clap(required = true)] req_str: Option, #[clap(subcommand)] @@ -242,7 +240,7 @@ fn ignore_qualified_option_type() { fn option_option_type_is_optional_value() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, value_parser)] + #[clap(short)] #[allow(clippy::option_option)] arg: Option>, } @@ -269,7 +267,7 @@ fn option_option_type_is_optional_value() { fn option_option_type_help() { #[derive(Parser, Debug)] struct Opt { - #[clap(long, value_name = "val", value_parser)] + #[clap(long, value_name = "val")] arg: Option>, } let help = utils::get_help::(); @@ -281,10 +279,10 @@ fn option_option_type_help() { fn two_option_option_types() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, value_parser)] + #[clap(short)] arg: Option>, - #[clap(long, value_parser)] + #[clap(long)] field: Option>, } assert_eq!( @@ -335,7 +333,7 @@ fn two_option_option_types() { fn vec_type_is_multiple_occurrences() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, long, value_parser)] + #[clap(short, long)] arg: Vec, } assert_eq!( @@ -353,7 +351,7 @@ fn vec_type_is_multiple_occurrences() { fn vec_type_with_required() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, long, required = true, value_parser)] + #[clap(short, long, required = true)] arg: Vec, } assert_eq!( @@ -371,7 +369,7 @@ fn vec_type_with_required() { fn vec_type_with_multiple_values_only() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, long, multiple_values(true), value_parser)] + #[clap(short, long, multiple_values(true))] arg: Vec, } assert_eq!( @@ -409,7 +407,7 @@ fn ignore_qualified_vec_type() { fn option_vec_type() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, value_parser)] + #[clap(short)] arg: Option>, } assert_eq!( @@ -431,7 +429,7 @@ fn option_vec_type() { fn option_vec_type_structopt_behavior() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, long, multiple_values(true), min_values(0), value_parser)] + #[clap(short, long, multiple_values(true), min_values(0))] arg: Option>, } assert_eq!( @@ -458,10 +456,10 @@ fn option_vec_type_structopt_behavior() { fn two_option_vec_types() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(short, value_parser)] + #[clap(short)] arg: Option>, - #[clap(short, value_parser)] + #[clap(short)] b: Option>, } @@ -512,7 +510,7 @@ fn explicit_value_parser() { fn implicit_value_parser() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(long, value_parser)] + #[clap(long)] arg: i32, } assert_eq!( diff --git a/tests/derive/next/privacy.rs b/tests/derive/next/privacy.rs index 224a23a4cc1..c8f66127b2d 100644 --- a/tests/derive/next/privacy.rs +++ b/tests/derive/next/privacy.rs @@ -30,7 +30,6 @@ mod subcommands { /// foo Foo { /// foo - #[clap(value_parser)] bars: String, }, } diff --git a/tests/derive/next/raw_bool_literal.rs b/tests/derive/next/raw_bool_literal.rs index 7dd3618a7d0..0e572aa8c67 100644 --- a/tests/derive/next/raw_bool_literal.rs +++ b/tests/derive/next/raw_bool_literal.rs @@ -13,9 +13,9 @@ fn raw_bool_literal() { #[derive(Parser, Debug, PartialEq)] #[clap(name = "raw_bool")] struct Opt { - #[clap(raw(false), value_parser)] + #[clap(raw(false))] a: String, - #[clap(raw(true), value_parser)] + #[clap(raw(true))] b: String, } diff --git a/tests/derive/next/raw_idents.rs b/tests/derive/next/raw_idents.rs index 25762c0e6bb..12c5d1658f0 100644 --- a/tests/derive/next/raw_idents.rs +++ b/tests/derive/next/raw_idents.rs @@ -4,7 +4,7 @@ use clap::Parser; fn raw_idents() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(short, long, value_parser)] + #[clap(short, long)] r#type: String, } diff --git a/tests/derive/next/rename_all_env.rs b/tests/derive/next/rename_all_env.rs index 46327c12ff0..20d4f40c728 100644 --- a/tests/derive/next/rename_all_env.rs +++ b/tests/derive/next/rename_all_env.rs @@ -9,7 +9,7 @@ fn it_works() { #[derive(Debug, PartialEq, Parser)] #[clap(rename_all_env = "kebab")] struct BehaviorModel { - #[clap(env, value_parser)] + #[clap(env)] be_nice: String, } @@ -21,7 +21,7 @@ fn it_works() { fn default_is_screaming() { #[derive(Debug, PartialEq, Parser)] struct BehaviorModel { - #[clap(env, value_parser)] + #[clap(env)] be_nice: String, } @@ -34,10 +34,10 @@ fn overridable() { #[derive(Debug, PartialEq, Parser)] #[clap(rename_all_env = "kebab")] struct BehaviorModel { - #[clap(env, value_parser)] + #[clap(env)] be_nice: String, - #[clap(rename_all_env = "pascal", env, value_parser)] + #[clap(rename_all_env = "pascal", env)] be_aggressive: String, } diff --git a/tests/derive/next/skip.rs b/tests/derive/next/skip.rs index d2e3b7ec086..160b0578f72 100644 --- a/tests/derive/next/skip.rs +++ b/tests/derive/next/skip.rs @@ -12,7 +12,7 @@ use clap::Parser; fn skip_1() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(short, value_parser)] + #[clap(short)] x: u32, #[clap(skip)] s: u32, @@ -39,17 +39,17 @@ fn skip_1() { fn skip_2() { #[derive(Parser, Debug, PartialEq)] struct Opt { - #[clap(short, value_parser)] + #[clap(short)] x: u32, #[clap(skip)] ss: String, #[clap(skip)] sn: u8, - #[clap(value_parser)] + y: u32, #[clap(skip)] sz: u16, - #[clap(value_parser)] + t: u32, } @@ -83,7 +83,7 @@ fn skip_enum() { #[derive(Parser, Debug, PartialEq)] pub struct Opt { - #[clap(long, short, value_parser)] + #[clap(long, short)] number: u32, #[clap(skip)] k: Kind, @@ -117,7 +117,7 @@ fn skip_help_doc_comments() { #[clap(skip)] c: u32, - #[clap(short, value_parser)] + #[clap(short)] n: u32, } @@ -136,7 +136,7 @@ fn skip_help_doc_comments() { fn skip_val() { #[derive(Parser, Debug, PartialEq)] pub struct Opt { - #[clap(long, short, value_parser)] + #[clap(long, short)] number: u32, #[clap(skip = "key")] diff --git a/tests/derive/next/subcommands.rs b/tests/derive/next/subcommands.rs index 2dcb897643f..9b3a69bef18 100644 --- a/tests/derive/next/subcommands.rs +++ b/tests/derive/next/subcommands.rs @@ -20,19 +20,19 @@ use clap::{Args, Parser, Subcommand}; enum Opt { /// Fetch stuff from GitHub Fetch { - #[clap(long, action)] + #[clap(long)] all: bool, /// Overwrite local branches. - #[clap(short, long, action)] + #[clap(short, long)] force: bool, - #[clap(value_parser)] + repo: String, }, Add { - #[clap(short, long, action)] + #[clap(short, long)] interactive: bool, - #[clap(short, long, action)] + #[clap(short, long)] verbose: bool, }, } @@ -89,10 +89,7 @@ fn test_no_parse() { #[derive(Parser, PartialEq, Debug)] enum Opt2 { - DoSomething { - #[clap(value_parser)] - arg: String, - }, + DoSomething { arg: String }, } #[test] @@ -127,13 +124,11 @@ fn test_null_commands() { #[derive(Parser, PartialEq, Debug)] #[clap(about = "Not shown")] struct Add { - #[clap(value_parser)] file: String, } /// Not shown #[derive(Parser, PartialEq, Debug)] struct Fetch { - #[clap(value_parser)] remote: String, } #[derive(Parser, PartialEq, Debug)] @@ -173,7 +168,7 @@ fn test_tuple_commands() { fn global_passed_down() { #[derive(Debug, PartialEq, Parser)] struct Opt { - #[clap(global = true, long, action)] + #[clap(global = true, long)] other: bool, #[clap(subcommand)] sub: Subcommands, @@ -187,7 +182,7 @@ fn global_passed_down() { #[derive(Debug, PartialEq, Args)] struct GlobalCmd { - #[clap(from_global, action)] + #[clap(from_global)] other: bool, } @@ -343,15 +338,13 @@ fn update_subcommands() { #[derive(Parser, PartialEq, Debug)] struct Command1 { - #[clap(value_parser)] arg1: i32, - #[clap(value_parser)] + arg2: i32, } #[derive(Parser, PartialEq, Debug)] struct Command2 { - #[clap(value_parser)] arg2: i32, } @@ -405,15 +398,13 @@ fn update_sub_subcommands() { #[derive(Args, PartialEq, Debug)] struct Command1 { - #[clap(value_parser)] arg1: i32, - #[clap(value_parser)] + arg2: i32, } #[derive(Args, PartialEq, Debug)] struct Command2 { - #[clap(value_parser)] arg2: i32, } @@ -466,15 +457,13 @@ fn update_ext_subcommand() { #[derive(Args, PartialEq, Debug)] struct Command1 { - #[clap(value_parser)] arg1: i32, - #[clap(value_parser)] + arg2: i32, } #[derive(Args, PartialEq, Debug)] struct Command2 { - #[clap(value_parser)] arg2: i32, } @@ -569,7 +558,6 @@ fn built_in_subcommand_escaped() { #[derive(Debug, PartialEq, Parser)] enum Command { Install { - #[clap(value_parser)] arg: Option, }, #[clap(external_subcommand)] @@ -598,7 +586,6 @@ fn built_in_subcommand_escaped() { #[derive(Debug, PartialEq, Parser)] enum Command { Install { - #[clap(value_parser)] arg: Option, }, #[clap(external_subcommand)] diff --git a/tests/derive/next/type_alias_regressions.rs b/tests/derive/next/type_alias_regressions.rs index c418644f413..a66f4fa8bae 100644 --- a/tests/derive/next/type_alias_regressions.rs +++ b/tests/derive/next/type_alias_regressions.rs @@ -11,11 +11,10 @@ type Option = std::option::Option; #[derive(Parser)] pub struct Opts { - #[clap(value_parser)] another_string: String, #[clap(subcommand)] command: Command, - #[clap(short, long, value_enum, value_parser)] + #[clap(short, long, value_enum)] choice: ArgChoice, } diff --git a/tests/derive/next/utf8.rs b/tests/derive/next/utf8.rs index 6389ef67168..dac3b45f903 100644 --- a/tests/derive/next/utf8.rs +++ b/tests/derive/next/utf8.rs @@ -6,13 +6,12 @@ use std::os::unix::ffi::OsStringExt; #[derive(Parser, Debug, PartialEq, Eq)] struct Positional { - #[clap(value_parser)] arg: String, } #[derive(Parser, Debug, PartialEq, Eq)] struct Named { - #[clap(short, long, value_parser)] + #[clap(short, long)] arg: String, } @@ -77,13 +76,12 @@ fn invalid_utf8_strict_option_long_equals() { #[derive(Parser, Debug, PartialEq, Eq)] struct PositionalOs { - #[clap(value_parser)] arg: OsString, } #[derive(Parser, Debug, PartialEq, Eq)] struct NamedOs { - #[clap(short, long, value_parser)] + #[clap(short, long)] arg: OsString, } diff --git a/tests/derive/next/value_enum.rs b/tests/derive/next/value_enum.rs index 4f93f57d1ba..ca9faaa52ca 100644 --- a/tests/derive/next/value_enum.rs +++ b/tests/derive/next/value_enum.rs @@ -19,7 +19,7 @@ fn basic() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, value_parser)] + #[clap(value_enum)] arg: ArgChoice, } @@ -54,7 +54,7 @@ fn default_value() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, value_parser, default_value_t)] + #[clap(value_enum, default_value_t)] arg: ArgChoice, } @@ -89,7 +89,7 @@ fn multi_word_is_renamed_kebab() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, value_parser)] + #[clap(value_enum)] arg: ArgChoice, } @@ -118,7 +118,7 @@ fn variant_with_defined_casing() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, value_parser)] + #[clap(value_enum)] arg: ArgChoice, } @@ -141,7 +141,7 @@ fn casing_is_propagated_from_parent() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, value_parser)] + #[clap(value_enum)] arg: ArgChoice, } @@ -165,7 +165,7 @@ fn casing_propagation_is_overridden() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, value_parser)] + #[clap(value_enum)] arg: ArgChoice, } @@ -188,7 +188,7 @@ fn ignore_case() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, value_parser, ignore_case(true))] + #[clap(value_enum, ignore_case(true))] arg: ArgChoice, } @@ -215,7 +215,7 @@ fn ignore_case_set_to_false() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, ignore_case(false), value_parser)] + #[clap(value_enum, ignore_case(false))] arg: ArgChoice, } @@ -238,7 +238,7 @@ fn alias() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, ignore_case(false), value_parser)] + #[clap(value_enum, ignore_case(false))] arg: ArgChoice, } @@ -266,7 +266,7 @@ fn multiple_alias() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, ignore_case(false), value_parser)] + #[clap(value_enum, ignore_case(false))] arg: ArgChoice, } @@ -375,7 +375,7 @@ fn option_type() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, value_parser)] + #[clap(value_enum)] arg: Option, } @@ -405,7 +405,7 @@ fn option_option_type() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, long, value_parser)] + #[clap(value_enum, long)] arg: Option>, } @@ -439,7 +439,7 @@ fn vec_type() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, short, long, value_parser)] + #[clap(value_enum, short, long)] arg: Vec, } @@ -469,7 +469,7 @@ fn option_vec_type() { #[derive(Parser, PartialEq, Debug)] struct Opt { - #[clap(value_enum, short, long, value_parser)] + #[clap(value_enum, short, long)] arg: Option>, } @@ -505,8 +505,7 @@ fn vec_type_default_value() { short, long, default_value = "foo,bar", - value_delimiter = ',', - value_parser + value_delimiter = ',' )] arg: Vec, } diff --git a/tests/derive_ui/next/bool_value_enum.rs b/tests/derive_ui/next/bool_value_enum.rs index f98d507bd49..6ee48e5212c 100644 --- a/tests/derive_ui/next/bool_value_enum.rs +++ b/tests/derive_ui/next/bool_value_enum.rs @@ -3,7 +3,7 @@ use clap::Parser; #[derive(Parser, Debug)] #[clap(name = "basic")] struct Opt { - #[clap(short, value_enum)] + #[clap(short, value_enum, default_value_t)] opts: bool, } diff --git a/tests/derive_ui/next/bool_value_enum.stderr b/tests/derive_ui/next/bool_value_enum.stderr index 4ec347dd34b..d6dd2073ecc 100644 --- a/tests/derive_ui/next/bool_value_enum.stderr +++ b/tests/derive_ui/next/bool_value_enum.stderr @@ -1,79 +1,11 @@ -warning: use of deprecated variant `clap::ArgAction::IncOccurrence`: Replaced with `ArgAction::SetTrue` or `ArgAction::Count` - --> tests/derive_ui/next/bool_value_enum.rs:7:5 - | -7 | opts: bool, - | ^^^^ - | - = note: `#[warn(deprecated)]` on by default - -warning: use of deprecated variant `clap::ArgAction::IncOccurrence`: Replaced with `ArgAction::SetTrue` or `ArgAction::Count` - --> tests/derive_ui/next/bool_value_enum.rs:7:5 - | -7 | opts: bool, - | ^^^^ - -error[E0277]: the trait bound `bool: ArgEnum` is not satisfied - --> tests/derive_ui/next/bool_value_enum.rs:7:11 +error[E0277]: the trait bound `bool: ValueEnum` is not satisfied + --> tests/derive_ui/next/bool_value_enum.rs:6:31 | -7 | opts: bool, - | ^^^^ the trait `ArgEnum` is not implemented for `bool` +6 | #[clap(short, value_enum, default_value_t)] + | ^^^^^^^^^^^^^^^ the trait `ValueEnum` is not implemented for `bool` | -note: required by `clap::ValueEnum::from_str` +note: required by `to_possible_value` --> src/derive.rs | - | fn from_str(input: &str, ignore_case: bool) -> Result { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0618]: expected function, found enum variant `bool` - --> tests/derive_ui/next/bool_value_enum.rs:7:11 - | -7 | opts: bool, - | ^^^^ call expression requires function - | -help: `bool` is a unit variant, you need to write it without the parenthesis - | -7 | opts: bool, - | ~~~~ - -warning: use of deprecated associated function `clap::ArgMatches::is_present`: Replaced with either `ArgAction::SetTrue` or `ArgMatches::contains_id(...)` - --> tests/derive_ui/next/bool_value_enum.rs:7:11 - | -7 | opts: bool, - | ^^^^ - -warning: use of deprecated associated function `clap::Arg::<'help>::possible_values`: Replaced with `Arg::value_parser(PossibleValuesParser::new(...)).takes_value(true)` - --> tests/derive_ui/next/bool_value_enum.rs:7:11 - | -7 | opts: bool, - | ^^^^ - -error[E0277]: the trait bound `bool: ArgEnum` is not satisfied - --> tests/derive_ui/next/bool_value_enum.rs:7:11 - | -7 | opts: bool, - | ^^^^ the trait `ArgEnum` is not implemented for `bool` - | -note: required by `value_variants` - --> src/derive.rs - | - | fn value_variants<'a>() -> &'a [Self]; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0277]: the trait bound `bool: ArgEnum` is not satisfied - --> tests/derive_ui/next/bool_value_enum.rs:6:5 - | -6 | / #[clap(short, value_enum)] -7 | | opts: bool, - | |______________^ the trait `ArgEnum` is not implemented for `bool` - | -note: required by a bound in `ArgEnum` - --> src/derive.rs - | - | / pub trait ValueEnum: Sized + Clone { - | | /// All possible argument values, in display order. - | | fn value_variants<'a>() -> &'a [Self]; - | | -... | - | | fn to_possible_value<'a>(&self) -> Option>; - | | } - | |_^ required by this bound in `ArgEnum` + | fn to_possible_value<'a>(&self) -> Option>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/derive_ui/non_existent_attr.rs b/tests/derive_ui/next/non_existent_attr.rs similarity index 100% rename from tests/derive_ui/non_existent_attr.rs rename to tests/derive_ui/next/non_existent_attr.rs diff --git a/tests/derive_ui/next/non_existent_attr.stderr b/tests/derive_ui/next/non_existent_attr.stderr new file mode 100644 index 00000000000..881d15a372c --- /dev/null +++ b/tests/derive_ui/next/non_existent_attr.stderr @@ -0,0 +1,5 @@ +error[E0599]: no method named `non_existing_attribute` found for struct `Arg` in the current scope + --> tests/derive_ui/next/non_existent_attr.rs:14:19 + | +14 | #[clap(short, non_existing_attribute = 1)] + | ^^^^^^^^^^^^^^^^^^^^^^ method not found in `Arg<'_>` diff --git a/tests/derive_ui/stable/non_existent_attr.rs b/tests/derive_ui/stable/non_existent_attr.rs new file mode 100644 index 00000000000..5275b446cac --- /dev/null +++ b/tests/derive_ui/stable/non_existent_attr.rs @@ -0,0 +1,21 @@ +// Copyright 2018 Guillaume Pinot (@TeXitoi) +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use clap::Parser; + +#[derive(Parser, Debug)] +#[clap(name = "basic")] +struct Opt { + #[clap(short, non_existing_attribute = 1)] + debug: bool, +} + +fn main() { + let opt = Opt::parse(); + println!("{:?}", opt); +} diff --git a/tests/derive_ui/non_existent_attr.stderr b/tests/derive_ui/stable/non_existent_attr.stderr similarity index 80% rename from tests/derive_ui/non_existent_attr.stderr rename to tests/derive_ui/stable/non_existent_attr.stderr index c970b909c8f..99b85be70bd 100644 --- a/tests/derive_ui/non_existent_attr.stderr +++ b/tests/derive_ui/stable/non_existent_attr.stderr @@ -1,5 +1,5 @@ warning: use of deprecated associated function `clap::ArgMatches::is_present`: Replaced with either `ArgAction::SetTrue` or `ArgMatches::contains_id(...)` - --> tests/derive_ui/non_existent_attr.rs:15:12 + --> tests/derive_ui/stable/non_existent_attr.rs:15:12 | 15 | debug: bool, | ^^^^ @@ -7,13 +7,13 @@ warning: use of deprecated associated function `clap::ArgMatches::is_present`: R = note: `#[warn(deprecated)]` on by default warning: use of deprecated associated function `clap::ArgMatches::is_present`: Replaced with either `ArgAction::SetTrue` or `ArgMatches::contains_id(...)` - --> tests/derive_ui/non_existent_attr.rs:15:12 + --> tests/derive_ui/stable/non_existent_attr.rs:15:12 | 15 | debug: bool, | ^^^^ error[E0599]: no method named `non_existing_attribute` found for struct `Arg` in the current scope - --> tests/derive_ui/non_existent_attr.rs:14:19 + --> tests/derive_ui/stable/non_existent_attr.rs:14:19 | 14 | #[clap(short, non_existing_attribute = 1)] | ^^^^^^^^^^^^^^^^^^^^^^ method not found in `Arg<'_>`