diff --git a/README.md b/README.md index 9b93dbe0998..29ff30e5249 100644 --- a/README.md +++ b/README.md @@ -281,21 +281,21 @@ The next example shows a far less verbose method, but sacrifices some of the adv // // This example demonstrates clap's "usage strings" method of creating arguments // which is less verbose -use clap::{App, Arg}; +use clap::{App, arg}; fn main() { let matches = App::new("myapp") .version("1.0") .author("Kevin K. ") .about("Does awesome things") - .arg(Arg::from_usage("-c, --config=[FILE] 'Sets a custom config file'")) - .arg(Arg::from_usage(" 'Sets the input file to use'")) - .arg(Arg::from_usage("-v... 'Sets the level of verbosity'")) + .arg(arg!(-c --config "Sets a custom config file").required(false)) + .arg(arg!( "Sets the input file to use")) + .arg(arg!(-v --verbose ... "Sets the level of verbosity")) .subcommand(App::new("test") .about("controls testing features") .version("1.3") .author("Someone E. ") - .arg(Arg::from_usage("-d, --debug 'Print debug information'"))) + .arg(arg!(-d --debug "Print debug information"))) .get_matches(); // Same as previous example... diff --git a/benches/02_simple.rs b/benches/02_simple.rs index 1a69175477d..46a725bbb5e 100644 --- a/benches/02_simple.rs +++ b/benches/02_simple.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg}; +use clap::{arg, App, Arg}; use criterion::{criterion_group, criterion_main, Criterion}; macro_rules! create_app { @@ -7,9 +7,9 @@ macro_rules! create_app { .version("0.1") .about("tests clap library") .author("Kevin K. ") - .arg(Arg::from_usage("-f --flag 'tests flags'")) - .arg(Arg::from_usage("-o --option=[opt] 'tests options'")) - .arg(Arg::from_usage("[positional] 'tests positional'")) + .arg(arg!(-f --flag "tests flags")) + .arg(arg!(-o --option "tests options").required(false)) + .arg(arg!([positional] "tests positional")) }}; } @@ -19,14 +19,14 @@ pub fn build_simple(c: &mut Criterion) { pub fn build_with_flag(c: &mut Criterion) { c.bench_function("build_with_flag", |b| { - b.iter(|| App::new("claptests").arg(Arg::from_usage("-s, --some 'something'"))) + b.iter(|| App::new("claptests").arg(arg!(-s --some "something"))) }); } pub fn build_with_flag_ref(c: &mut Criterion) { c.bench_function("build_with_flag_ref", |b| { b.iter(|| { - let arg = Arg::from_usage("-s, --some 'something'"); + let arg = arg!(-s --some "something"); App::new("claptests").arg(&arg) }) }); @@ -34,14 +34,14 @@ pub fn build_with_flag_ref(c: &mut Criterion) { pub fn build_with_opt(c: &mut Criterion) { c.bench_function("build_with_opt", |b| { - b.iter(|| App::new("claptests").arg(Arg::from_usage("-s, --some 'something'"))) + b.iter(|| App::new("claptests").arg(arg!(-s --some "something"))) }); } pub fn build_with_opt_ref(c: &mut Criterion) { c.bench_function("build_with_opt_ref", |b| { b.iter(|| { - let arg = Arg::from_usage("-s, --some 'something'"); + let arg = arg!(-s --some "something"); App::new("claptests").arg(&arg) }) }); diff --git a/benches/03_complex.rs b/benches/03_complex.rs index 0dc1043ef12..536bd1b8a1d 100644 --- a/benches/03_complex.rs +++ b/benches/03_complex.rs @@ -1,10 +1,51 @@ -use clap::{App, AppSettings, Arg, ArgSettings}; +use clap::{arg, App, AppSettings, Arg, ArgSettings}; use criterion::{criterion_group, criterion_main, Criterion}; static OPT3_VALS: [&str; 2] = ["fast", "slow"]; static POS3_VALS: [&str; 2] = ["vi", "emacs"]; macro_rules! create_app { + () => {{ + App::new("claptests") + .version("0.1") + .about("tests clap library") + .author("Kevin K. ") + .arg(arg!(-o --option ... "tests options").required(false)) + .arg(arg!([positional] "tests positionals")) + .arg(arg!(-f --flag ... "tests flags").global(true)) + .args(&[ + arg!(flag2: -F "tests flags with exclusions") + .conflicts_with("flag") + .requires("option2"), + arg!(option2: --"long-option-2" "tests long options with exclusions") + .required(false) + .conflicts_with("option") + .requires("positional2"), + arg!([positional2] "tests positionals with exclusions"), + arg!(-O --Option "tests options with specific value sets") + .required(false) + .possible_values(OPT3_VALS), + arg!([positional3] ... "tests positionals with specific values") + .possible_values(POS3_VALS), + arg!(--multvals "Tests multiple values not mult occs").required(false).value_names(&["one", "two"]), + arg!( + --multvalsmo "Tests multiple values, not mult occs" + ).multiple_values(true).required(false).value_names(&["one", "two"]), + arg!(--minvals2 ... "Tests 2 min vals").min_values(2).multiple_values(true).required(false), + arg!(--maxvals3 ... "Tests 3 max vals").max_values(3).multiple_values(true).required(false), + ]) + .subcommand( + App::new("subcmd") + .about("tests subcommands") + .version("0.1") + .author("Kevin K. ") + .arg(arg!(-o --option ... "tests options").required(false)) + .arg(arg!([scpositional] "tests positionals")) + ) + }}; +} + +macro_rules! create_app_from_usage { () => {{ App::new("claptests") .version("0.1") @@ -46,7 +87,7 @@ macro_rules! create_app { } pub fn build_from_usage(c: &mut Criterion) { - c.bench_function("build_from_usage", |b| b.iter(|| create_app!())); + c.bench_function("build_from_usage", |b| b.iter(|| create_app_from_usage!())); } pub fn build_from_builder(c: &mut Criterion) { diff --git a/benches/04_new_help.rs b/benches/04_new_help.rs index a0e65d06fa7..044ed4909a6 100644 --- a/benches/04_new_help.rs +++ b/benches/04_new_help.rs @@ -1,5 +1,5 @@ use clap::App; -use clap::{Arg, ArgSettings}; +use clap::{arg, Arg, ArgSettings}; use criterion::{criterion_group, criterion_main, Criterion}; use std::io::Cursor; @@ -15,15 +15,18 @@ fn app_example1<'c>() -> App<'c> { .version("1.0") .author("Kevin K. ") .about("Does awesome things") - .arg(Arg::from_usage( - "-c, --config=[FILE] 'Sets a custom config file'", - )) - .arg(Arg::from_usage(" 'Sets an optional output file'")) - .arg(Arg::from_usage("-d... 'Turn debugging information on'")) + .arg( + arg!( + -c --config "Sets a custom config file" + ) + .required(false), + ) + .arg(arg!( "Sets an optional output file")) + .arg(arg!(d: -d ... "Turn debugging information on")) .subcommand( App::new("test") .about("does testing things") - .arg(Arg::from_usage("-l, --list 'lists test values'")), + .arg(arg!(-l --list "lists test values")), ) } @@ -51,11 +54,14 @@ fn app_example3<'c>() -> App<'c> { .help("the input file to use") .setting(ArgSettings::Required), ]) - .arg(Arg::from_usage("--license 'display the license file'")) - .arg(Arg::from_usage("[output] 'Supply an output file to use'")) - .arg(Arg::from_usage( - "-i, --int=[IFACE] 'Set an interface to use'", - )) + .arg(arg!(--license "display the license file")) + .arg(arg!([output] "Supply an output file to use")) + .arg( + arg!( + -i --int "Set an interface to use" + ) + .required(false), + ) } fn app_example4<'c>() -> App<'c> { diff --git a/examples/01a_quick_example.rs b/examples/01a_quick_example.rs index 6117102532f..fad61f06367 100644 --- a/examples/01a_quick_example.rs +++ b/examples/01a_quick_example.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg}; +use clap::{arg, App}; fn main() { // This example shows how to create an application with several arguments using usage strings, which can be @@ -33,17 +33,20 @@ fn main() { .version("1.0") .author("Kevin K. ") .about("Does awesome things") - .arg(Arg::from_usage( - "-c, --config=[FILE] 'Sets a custom config file'", - )) - .arg(Arg::from_usage("[output] 'Sets an optional output file'")) - .arg(Arg::from_usage( - "-d..., --debug... 'Turn debugging information on'", + .arg( + arg!( + -c --config "Sets a custom config file" + ) + .required(false), + ) + .arg(arg!([output] "Sets an optional output file")) + .arg(arg!( + -d --debug ... "Turn debugging information on" )) .subcommand( App::new("test") .about("does testing things") - .arg(Arg::from_usage("-l, --list 'lists test values'")), + .arg(arg!(-l --list "lists test values")), ) .get_matches(); diff --git a/examples/02_apps.rs b/examples/02_apps.rs index 03555317b32..c5e688cb20b 100644 --- a/examples/02_apps.rs +++ b/examples/02_apps.rs @@ -9,8 +9,8 @@ fn main() { // another option, usage(), which is an exception to the rule. This should only be used when // the default usage string automatically generated by clap doesn't suffice. // - // You also set all the valid arguments your App should accept via the arg(), args(), arg() - // and args_from_usage() (as well as subcommands via the subcommand() and subcommands() methods) which + // You also set all the valid arguments your App should accept via the arg() and args() + // (as well as subcommands via the subcommand() and subcommands() methods) which // will be covered later. // // Once all options have been set, call one of the .get_matches* family of methods in order to diff --git a/examples/03_args.rs b/examples/03_args.rs index f1196e30d09..47b8b61955b 100644 --- a/examples/03_args.rs +++ b/examples/03_args.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg}; +use clap::{arg, App, Arg}; fn main() { // Args describe a possible valid argument which may be supplied by the user at runtime. There @@ -9,9 +9,8 @@ fn main() { // methods describing various settings for the individual arguments. Or by supplying a "usage" // string. Both methods have their pros and cons. // - // Arguments can be added to applications in two manners, one at a time with the arg(), and - // arg() method, or multiple arguments at once via a Vec inside the args() method, - // or a single &str describing multiple Args (one per line) supplied to args_from_usage(). + // Arguments can be added to applications in two manners, one at a time with the arg() + // method, or multiple arguments at once via a `&[Arg]` inside the args() method. // // There are various options which can be set for a given argument, some apply to any of the // three types of arguments, some only apply one or two of the types. *NOTE* if you set @@ -50,12 +49,15 @@ fn main() { // // // One "Flag" using a usage string - .arg(Arg::from_usage("--license 'display the license file'")) - // Two args, one "Positional", and one "Option" using a usage string - .arg(Arg::from_usage("[output] 'Supply an output file to use'")) - .arg(Arg::from_usage( - "-i, --int=[IFACE] 'Set an interface to use'", - )) + .arg(arg!(--license "display the license file")) + // Two args one Positional and one Option using a usage string + .arg(arg!([output] "Supply an output file to use")) + .arg( + arg!( + -i --int "Set an interface to use" + ) + .required(false), + ) .get_matches(); // Here are some examples of using the arguments defined above. Keep in mind that this is only diff --git a/examples/05_flag_args.rs b/examples/05_flag_args.rs index d0de5fdd522..40df9455a85 100644 --- a/examples/05_flag_args.rs +++ b/examples/05_flag_args.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg}; +use clap::{arg, App, Arg}; fn main() { // Of the three argument types, flags are the most simple. Flags are simple switches which can @@ -29,10 +29,13 @@ fn main() { // also has a conflicts_with_all(Vec<&str>) // and an exclusive(true) ) - .arg(Arg::from_usage( - "-c, --config=[FILE] 'sets a custom config file'", - )) - .arg(Arg::from_usage("[output] 'sets an output file'")) + .arg( + arg!( + -c --config "sets a custom config file" + ) + .required(false), + ) + .arg(arg!([output] "sets an output file")) .get_matches(); // We can find out whether or not awesome was used diff --git a/examples/07_option_args.rs b/examples/07_option_args.rs index e7ae9bcc55a..e19cebee04f 100644 --- a/examples/07_option_args.rs +++ b/examples/07_option_args.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg}; +use clap::{arg, App, Arg}; fn main() { // Option arguments are those that take an additional value, such as "-c value". In clap they @@ -33,10 +33,13 @@ fn main() { // also has a conflicts_with_all(Vec<&str>) // and an exclusive(true) ) - .arg(Arg::from_usage( - "-c, --config=[FILE] 'the config file to use'", - )) - .arg(Arg::from_usage("[output] 'the output file to use'")) + .arg( + arg!( + -c --config "the config file to use" + ) + .required(false), + ) + .arg(arg!([output] "the output file to use")) .get_matches(); // We can find out whether or not "input" was used diff --git a/examples/12_typed_values.rs b/examples/12_typed_values.rs index 83b09357138..819a56361d9 100644 --- a/examples/12_typed_values.rs +++ b/examples/12_typed_values.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg}; +use clap::{arg, App}; fn main() { // You can use some convenience methods provided by clap to get typed values, so long as the @@ -22,12 +22,15 @@ fn main() { let matches = App::new("myapp") // Create two arguments, a required positional which accepts multiple values // and an optional '-l value' - .arg(Arg::from_usage( - "... 'A sequence of whole positive numbers, i.e. 20 25 30'", - )) - .arg(Arg::from_usage( - "-l [len] 'A length to use, defaults to 10 when omitted'", + .arg(arg!( + ... "A sequence of whole positive numbers, i.e. 20 25 30" )) + .arg( + arg!( + l: -l "A length to use, defaults to 10 when omitted" + ) + .required(false), + ) .get_matches(); // This code loops through all the values provided to "seq" and adds 2 diff --git a/examples/13_enum_values.rs b/examples/13_enum_values.rs index 8b8f7b4cb0c..d67acc8dc32 100644 --- a/examples/13_enum_values.rs +++ b/examples/13_enum_values.rs @@ -5,7 +5,7 @@ use std::str::FromStr; // Add clap like normal -use clap::{App, Arg}; +use clap::{arg, App}; // Define your enum enum Vals { @@ -35,7 +35,7 @@ fn main() { let m = App::new("myapp") // Use a single positional argument that is required .arg( - Arg::from_usage(" 'The type to use'") + arg!( "The type to use") // Define the list of possible values .possible_values(["Foo", "Bar", "Baz", "Qux"]), ) diff --git a/examples/14_groups.rs b/examples/14_groups.rs index 2f20584ad84..738187e8c40 100644 --- a/examples/14_groups.rs +++ b/examples/14_groups.rs @@ -20,16 +20,16 @@ /// of the three numbers. So you create three flags `--major`, `--minor`, and `--patch`. All of /// these arguments shouldn't be used at one time but you want to specify that *at least one* of /// them is used. For this, you can create a group. -use clap::{App, Arg, ArgGroup}; +use clap::{arg, App, Arg, ArgGroup}; fn main() { // Create application like normal let matches = App::new("myapp") // Add the version arguments - .arg(Arg::from_usage("--set-ver [ver] 'set version manually'")) - .arg(Arg::from_usage("--major 'auto inc major'")) - .arg(Arg::from_usage("--minor 'auto inc minor'")) - .arg(Arg::from_usage("--patch 'auto inc patch'")) + .arg(arg!(--"set-ver" "set version manually").required(false)) + .arg(arg!(--major "auto inc major")) + .arg(arg!(--minor "auto inc minor")) + .arg(arg!(--patch "auto inc patch")) // Create a group, make it required, and add the above arguments .group( ArgGroup::new("vers") @@ -38,8 +38,12 @@ fn main() { ) // Arguments can also be added to a group individually, these two arguments // are part of the "input" group which is not required - .arg(Arg::from_usage("[INPUT_FILE] 'some regular input'").group("input")) - .arg(Arg::from_usage("--spec-in [SPEC_IN] 'some special input argument'").group("input")) + .arg(arg!([INPUT_FILE] "some regular input").group("input")) + .arg( + arg!(--"spec-in" "some special input argument") + .required(false) + .group("input"), + ) // Now let's assume we have a -c [config] argument which requires one of // (but **not** both) the "input" arguments .arg( diff --git a/examples/16_app_settings.rs b/examples/16_app_settings.rs index 986b4f9d3b9..905a883026b 100644 --- a/examples/16_app_settings.rs +++ b/examples/16_app_settings.rs @@ -1,4 +1,4 @@ -use clap::{App, AppSettings, Arg}; +use clap::{arg, App, AppSettings}; fn main() { // You can use AppSettings to change the application level behavior of clap. .setting() function @@ -11,7 +11,7 @@ fn main() { let matches = App::new("myapp") .setting(AppSettings::SubcommandsNegateReqs) // Negates requirement of parent command. - .arg(Arg::from_usage(" 'input file to use'")) + .arg(arg!( "input file to use")) // Required positional argument called input. This // will be only required if subcommand is not present. .subcommand(App::new("test").about("does some testing")) diff --git a/src/build/app/mod.rs b/src/build/app/mod.rs index 1c5979067e4..d7fcb751182 100644 --- a/src/build/app/mod.rs +++ b/src/build/app/mod.rs @@ -1199,7 +1199,7 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; + /// # use clap::{App, arg, Arg}; /// App::new("myprog") /// // Adding a single "flag" argument with a short and help text, using Arg::new() /// .arg( @@ -1210,7 +1210,7 @@ impl<'help> App<'help> { /// // Adding a single "option" argument with a short, a long, and help text using the less /// // verbose Arg::from() /// .arg( - /// Arg::from_usage("-c --config=[CONFIG] 'Optionally sets a config file to use'") + /// arg!(-c --config "Optionally sets a config file to use") /// ) /// # ; /// ``` @@ -1247,10 +1247,10 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; + /// # use clap::{App, arg, Arg}; /// App::new("myprog") /// .args(&[ - /// Arg::from_usage("[debug] -d 'turns on debugging info'"), + /// arg!("[debug] -d 'turns on debugging info'"), /// Arg::new("input").index(1).help("the input file to use") /// ]) /// # ; @@ -1760,12 +1760,12 @@ impl<'help> App<'help> { /// of the arguments from the specified group is present at runtime. /// /// ```no_run - /// # use clap::{App, Arg, ArgGroup}; + /// # use clap::{App, arg, ArgGroup}; /// App::new("app") - /// .arg(Arg::from_usage("--set-ver [ver] 'set the version manually'")) - /// .arg(Arg::from_usage("--major 'auto increase major'")) - /// .arg(Arg::from_usage("--minor 'auto increase minor'")) - /// .arg(Arg::from_usage("--patch 'auto increase patch'")) + /// .arg(arg!("--set-ver [ver] 'set the version manually'")) + /// .arg(arg!("--major 'auto increase major'")) + /// .arg(arg!("--minor 'auto increase minor'")) + /// .arg(arg!("--patch 'auto increase patch'")) /// .group(ArgGroup::new("vers") /// .args(&["set-ver", "major", "minor","patch"]) /// .required(true)) @@ -1782,14 +1782,14 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg, ArgGroup}; + /// # use clap::{App, arg, ArgGroup}; /// App::new("app") - /// .arg(Arg::from_usage("--set-ver [ver] 'set the version manually'")) - /// .arg(Arg::from_usage("--major 'auto increase major'")) - /// .arg(Arg::from_usage("--minor 'auto increase minor'")) - /// .arg(Arg::from_usage("--patch 'auto increase patch'")) - /// .arg(Arg::from_usage("-c [FILE] 'a config file'")) - /// .arg(Arg::from_usage("-i [IFACE] 'an interface'")) + /// .arg(arg!("--set-ver [ver] 'set the version manually'")) + /// .arg(arg!("--major 'auto increase major'")) + /// .arg(arg!("--minor 'auto increase minor'")) + /// .arg(arg!("--patch 'auto increase patch'")) + /// .arg(arg!("-c [FILE] 'a config file'")) + /// .arg(arg!("-i [IFACE] 'an interface'")) /// .groups(&[ /// ArgGroup::new("vers") /// .args(&["set-ver", "major", "minor","patch"]) @@ -1818,11 +1818,11 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// App::new("myprog") /// .subcommand(App::new("config") /// .about("Controls configuration features") - /// .arg(Arg::from_usage(" 'Required configuration file to use'"))) + /// .arg(arg!(" 'Required configuration file to use'"))) /// # ; /// ``` #[inline] diff --git a/src/build/app/settings.rs b/src/build/app/settings.rs index 5ee7a6433bf..1b29e9f5a68 100644 --- a/src/build/app/settings.rs +++ b/src/build/app/settings.rs @@ -819,12 +819,12 @@ pub enum AppSettings { /// avoided in many cases. /// /// ```rust - /// # use clap::{App, Arg, AppSettings}; + /// # use clap::{App, arg, AppSettings}; /// let app = App::new("app") /// .setting(AppSettings::IgnoreErrors) - /// .arg(Arg::from_usage("-c, --config=[FILE] 'Sets a custom config file'")) - /// .arg(Arg::from_usage("-x, --stuff=[FILE] 'Sets a custom stuff file'")) - /// .arg(Arg::from_usage("-f 'Flag'")); + /// .arg(arg!(-c --config "Sets a custom config file").required(false)) + /// .arg(arg!(-x --stuff "Sets a custom stuff file").required(false)) + /// .arg(arg!(f: -f "Flag")); /// /// let r = app.try_get_matches_from(vec!["app", "-c", "file", "-f", "-x"]); /// @@ -883,10 +883,10 @@ pub enum AppSettings { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, AppSettings}; + /// # use clap::{App, arg, AppSettings}; /// let m = App::new("myprog") /// .setting(AppSettings::NoBinaryName) - /// .arg(Arg::from_usage("... 'commands to run'")) + /// .arg(arg!( ... "commands to run")) /// .get_matches_from(vec!["command", "set"]); /// /// let cmds: Vec<&str> = m.values_of("cmd").unwrap().collect(); @@ -1028,10 +1028,10 @@ pub enum AppSettings { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, AppSettings}; + /// # use clap::{App, arg, AppSettings}; /// let m = App::new("myprog") /// .setting(AppSettings::TrailingVarArg) - /// .arg(Arg::from_usage("... 'commands to run'")) + /// .arg(arg!( ... "commands to run")) /// .get_matches_from(vec!["myprog", "arg1", "-r", "val1"]); /// /// let trail: Vec<&str> = m.values_of("cmd").unwrap().collect(); diff --git a/src/build/arg/mod.rs b/src/build/arg/mod.rs index 28c9f80614c..e1018776e44 100644 --- a/src/build/arg/mod.rs +++ b/src/build/arg/mod.rs @@ -69,7 +69,7 @@ impl Default for ArgProvider { /// # Examples /// /// ```rust -/// # use clap::Arg; +/// # use clap::{Arg, arg}; /// // Using the traditional builder pattern and setting each option manually /// let cfg = Arg::new("config") /// .short('c') @@ -78,7 +78,7 @@ impl Default for ArgProvider { /// .value_name("FILE") /// .help("Provides a config file to myprog"); /// // Using a usage string (setting a similar argument to the one above) -/// let input = Arg::from_usage("-i, --input=[FILE] 'Provides an input file to the program'"); +/// let input = arg!(-i --input "Provides an input file to the program"); /// ``` #[allow(missing_debug_implementations)] #[derive(Default, Clone)] @@ -1446,12 +1446,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust # use clap::{App, Arg}; - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// let m = App::new("prog") - /// .arg(Arg::from_usage("-f, --flag 'some flag'") + /// .arg(arg!(-f --flag "some flag") /// .conflicts_with("debug")) - /// .arg(Arg::from_usage("-d, --debug 'other flag'")) - /// .arg(Arg::from_usage("-c, --color 'third flag'") + /// .arg(arg!(-d --debug "other flag")) + /// .arg(arg!(-c --color "third flag") /// .overrides_with("flag")) /// .get_matches_from(vec![ /// "prog", "-f", "-d", "-c"]); @@ -1471,9 +1471,9 @@ impl<'help> Arg<'help> { /// preventing a "Unexpected multiple usage" error): /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// let m = App::new("posix") - /// .arg(Arg::from_usage("--flag 'some flag'").overrides_with("flag")) + /// .arg(arg!(--flag "some flag").overrides_with("flag")) /// .get_matches_from(vec!["posix", "--flag", "--flag"]); /// assert!(m.is_present("flag")); /// assert_eq!(m.occurrences_of("flag"), 1); @@ -1484,9 +1484,9 @@ impl<'help> Arg<'help> { /// if it's a flag and it already accepts multiple occurrences. /// /// ``` - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// let m = App::new("posix") - /// .arg(Arg::from_usage("--flag... 'some flag'").overrides_with("flag")) + /// .arg(arg!(--flag ... "some flag").overrides_with("flag")) /// .get_matches_from(vec!["", "--flag", "--flag", "--flag", "--flag"]); /// assert!(m.is_present("flag")); /// assert_eq!(m.occurrences_of("flag"), 4); @@ -1497,9 +1497,9 @@ impl<'help> Arg<'help> { /// occurrence happened. /// /// ``` - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// let m = App::new("posix") - /// .arg(Arg::from_usage("--opt [val] 'some option'").overrides_with("opt")) + /// .arg(arg!(--opt "some option").overrides_with("opt")) /// .get_matches_from(vec!["", "--opt=some", "--opt=other"]); /// assert!(m.is_present("opt")); /// assert_eq!(m.occurrences_of("opt"), 1); @@ -1528,9 +1528,10 @@ impl<'help> Arg<'help> { /// will ignore the "override self" setting. /// /// ``` - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// let m = App::new("posix") - /// .arg(Arg::from_usage("--opt [val]... 'some option'") + /// .arg(arg!(--opt ... "some option") + /// .multiple_values(true) /// .overrides_with("opt")) /// .get_matches_from(vec!["", "--opt", "first", "over", "--opt", "other", "val"]); /// assert!(m.is_present("opt")); @@ -1552,12 +1553,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// let m = App::new("prog") - /// .arg(Arg::from_usage("-f, --flag 'some flag'") + /// .arg(arg!(-f --flag "some flag") /// .conflicts_with("color")) - /// .arg(Arg::from_usage("-d, --debug 'other flag'")) - /// .arg(Arg::from_usage("-c, --color 'third flag'") + /// .arg(arg!(-d --debug "other flag")) + /// .arg(arg!(-c --color "third flag") /// .overrides_with_all(&["flag", "debug"])) /// .get_matches_from(vec![ /// "prog", "-f", "-d", "-c"]); diff --git a/src/build/arg/tests.rs b/src/build/arg/tests.rs index 0840da93666..6a6506e43f9 100644 --- a/src/build/arg/tests.rs +++ b/src/build/arg/tests.rs @@ -1,28 +1,4 @@ -use super::{settings::ArgSettings, Arg}; - -#[test] -fn short_flag_misspell() { - let a = Arg::from_usage("-f1, --flag 'some flag'"); - assert_eq!(a.name, "flag"); - assert_eq!(a.short.unwrap(), 'f'); - assert_eq!(a.long.unwrap(), "flag"); - assert_eq!(a.help.unwrap(), "some flag"); - assert!(!a.is_set(ArgSettings::MultipleOccurrences)); - assert!(a.val_names.is_empty()); - assert!(a.num_vals.is_none()); -} - -#[test] -fn short_flag_name_missing() { - let a = Arg::from_usage("-f 'some flag'"); - assert_eq!(a.name, "f"); - assert_eq!(a.short.unwrap(), 'f'); - assert!(a.long.is_none()); - assert_eq!(a.help.unwrap(), "some flag"); - assert!(!a.is_set(ArgSettings::MultipleOccurrences)); - assert!(a.val_names.is_empty()); - assert!(a.num_vals.is_none()); -} +use crate::Arg; // This test will *fail to compile* if Arg is not Send + Sync #[test] diff --git a/src/build/arg_group.rs b/src/build/arg_group.rs index 449511611f4..1b22cb7bee0 100644 --- a/src/build/arg_group.rs +++ b/src/build/arg_group.rs @@ -36,12 +36,12 @@ use yaml_rust::Yaml; /// the arguments from the specified group is present at runtime. /// /// ```rust -/// # use clap::{App, Arg, ArgGroup, ErrorKind}; +/// # use clap::{App, arg, ArgGroup, ErrorKind}; /// let result = App::new("app") -/// .arg(Arg::from_usage("--set-ver [ver] 'set the version manually'")) -/// .arg(Arg::from_usage("--major 'auto increase major'")) -/// .arg(Arg::from_usage("--minor 'auto increase minor'")) -/// .arg(Arg::from_usage("--patch 'auto increase patch'")) +/// .arg(arg!(--"set-ver" "set the version manually").required(false)) +/// .arg(arg!(--major "auto increase major")) +/// .arg(arg!(--minor "auto increase minor")) +/// .arg(arg!(--patch "auto increase patch")) /// .group(ArgGroup::new("vers") /// .args(&["set-ver", "major", "minor", "patch"]) /// .required(true)) @@ -54,12 +54,12 @@ use yaml_rust::Yaml; /// This next example shows a passing parse of the same scenario /// /// ```rust -/// # use clap::{App, Arg, ArgGroup}; +/// # use clap::{App, arg, ArgGroup}; /// let result = App::new("app") -/// .arg(Arg::from_usage("--set-ver [ver] 'set the version manually'")) -/// .arg(Arg::from_usage("--major 'auto increase major'")) -/// .arg(Arg::from_usage("--minor 'auto increase minor'")) -/// .arg(Arg::from_usage("--patch 'auto increase patch'")) +/// .arg(arg!(--"set-ver" "set the version manually").required(false)) +/// .arg(arg!(--major "auto increase major")) +/// .arg(arg!(--minor "auto increase minor")) +/// .arg(arg!(--patch "auto increase patch")) /// .group(ArgGroup::new("vers") /// .args(&["set-ver", "major", "minor","patch"]) /// .required(true)) diff --git a/src/parse/errors.rs b/src/parse/errors.rs index e6fe075f583..a7d25cfb53f 100644 --- a/src/parse/errors.rs +++ b/src/parse/errors.rs @@ -47,9 +47,9 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; + /// # use clap::{App, arg, ErrorKind}; /// let result = App::new("prog") - /// .arg(Arg::from_usage("--flag 'some flag'")) + /// .arg(arg!(--flag "some flag")) /// .try_get_matches_from(vec!["prog", "--other"]); /// assert!(result.is_err()); /// assert_eq!(result.unwrap_err().kind, ErrorKind::UnknownArgument); diff --git a/src/parse/matches/arg_matches.rs b/src/parse/matches/arg_matches.rs index eacc9cb9c8b..e59172d7b0e 100644 --- a/src/parse/matches/arg_matches.rs +++ b/src/parse/matches/arg_matches.rs @@ -178,12 +178,12 @@ impl ArgMatches { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// use std::ffi::OsString; /// use std::os::unix::ffi::{OsStrExt,OsStringExt}; /// /// let m = App::new("utf8") - /// .arg(Arg::from_usage(" 'some arg'") + /// .arg(arg!( "some arg") /// .allow_invalid_utf8(true)) /// .get_matches_from(vec![OsString::from("myprog"), /// // "Hi {0xe9}!" @@ -221,12 +221,12 @@ impl ArgMatches { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// use std::ffi::OsString; /// use std::os::unix::ffi::{OsStrExt,OsStringExt}; /// /// let m = App::new("utf8") - /// .arg(Arg::from_usage(" 'some arg'") + /// .arg(arg!( "some arg") /// .allow_invalid_utf8(true)) /// .get_matches_from(vec![OsString::from("myprog"), /// // "Hi {0xe9}!" @@ -306,12 +306,12 @@ impl ArgMatches { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// use std::ffi::OsString; /// use std::os::unix::ffi::OsStringExt; /// /// let m = App::new("utf8") - /// .arg(Arg::from_usage("... 'some arg'") + /// .arg(arg!( ... "some arg") /// .allow_invalid_utf8(true)) /// .get_matches_from(vec![OsString::from("myprog"), /// // "Hi" @@ -343,12 +343,12 @@ impl ArgMatches { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// use std::ffi::{OsStr,OsString}; /// use std::os::unix::ffi::{OsStrExt,OsStringExt}; /// /// let m = App::new("utf8") - /// .arg(Arg::from_usage("... 'some arg'") + /// .arg(arg!( ... "some arg") /// .allow_invalid_utf8(true)) /// .get_matches_from(vec![OsString::from("myprog"), /// // "Hi" @@ -392,9 +392,9 @@ impl ArgMatches { /// # Examples /// /// ``` - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// let matches = App::new("myapp") - /// .arg(Arg::from_usage("[length] 'Set the length to use as a pos whole num, i.e. 20'")) + /// .arg(arg!([length] "Set the length to use as a pos whole num i.e. 20")) /// .get_matches_from(&["test", "12"]); /// /// // Specify the type explicitly (or use turbofish) @@ -442,9 +442,9 @@ impl ArgMatches { /// # Examples /// /// ``` - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// let matches = App::new("myapp") - /// .arg(Arg::from_usage("[length] 'Set the length to use as a pos whole num, i.e. 20'")) + /// .arg(arg!([length] "Set the length to use as a pos whole num i.e. 20")) /// .get_matches_from(&["test", "12"]); /// /// // Specify the type explicitly (or use turbofish) @@ -479,9 +479,9 @@ impl ArgMatches { /// # Examples /// /// ``` - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// let matches = App::new("myapp") - /// .arg(Arg::from_usage("[length]... 'A sequence of integers because integers are neat!'")) + /// .arg(arg!([length] ... "A sequence of integers because integers are neat!")) /// .get_matches_from(&["test", "12", "77", "40"]); /// /// // Specify the type explicitly (or use turbofish) @@ -531,9 +531,9 @@ impl ArgMatches { /// # Examples /// /// ``` - /// # use clap::{App, Arg}; + /// # use clap::{App, arg}; /// let matches = App::new("myapp") - /// .arg(Arg::from_usage("[length]... 'A sequence of integers because integers are neat!'")) + /// .arg(arg!([length] ... "A sequence of integers because integers are neat!")) /// .get_matches_from(&["test", "12", "77", "40"]); /// /// // Specify the type explicitly (or use turbofish) @@ -1099,12 +1099,12 @@ impl<'a> Default for GroupedValues<'a> { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] -/// # use clap::{App, Arg}; +/// # use clap::{App, arg}; /// use std::ffi::OsString; /// use std::os::unix::ffi::{OsStrExt,OsStringExt}; /// /// let m = App::new("utf8") -/// .arg(Arg::from_usage(" 'some arg'") +/// .arg(arg!( "some arg") /// .allow_invalid_utf8(true)) /// .get_matches_from(vec![OsString::from("myprog"), /// // "Hi {0xe9}!" diff --git a/tests/app_settings.rs b/tests/app_settings.rs index 988856f7a5b..0bb786479ba 100644 --- a/tests/app_settings.rs +++ b/tests/app_settings.rs @@ -1,6 +1,6 @@ mod utils; -use clap::{App, AppSettings, Arg, ErrorKind}; +use clap::{arg, App, AppSettings, Arg, ErrorKind}; static ALLOW_EXT_SC: &str = "clap-test v1.4.8 @@ -430,8 +430,10 @@ fn skip_possible_values() { .version("1.3") .setting(AppSettings::HidePossibleValuesInHelp) .args(&[ - Arg::from_usage("-o, --opt [opt] 'some option'").possible_values(["one", "two"]), - Arg::from_usage("[arg1] 'some pos arg'").possible_values(["three", "four"]), + arg!(-o --opt "some option") + .required(false) + .possible_values(["one", "two"]), + arg!([arg1] "some pos arg").possible_values(["three", "four"]), ]); assert!(utils::compare_output( @@ -447,8 +449,8 @@ fn stop_delim_values_only_pos_follows() { let r = App::new("onlypos") .setting(AppSettings::DontDelimitTrailingValues) .args(&[ - Arg::from_usage("-f [flag] 'some opt'"), - Arg::from_usage("[arg]... 'some arg'"), + arg!(f: -f "some opt").required(false), + arg!([arg] ... "some arg"), ]) .try_get_matches_from(vec!["", "--", "-f", "-g,x"]); assert!(r.is_ok()); @@ -466,7 +468,7 @@ fn dont_delim_values_trailingvararg() { let m = App::new("positional") .setting(AppSettings::TrailingVarArg) .setting(AppSettings::DontDelimitTrailingValues) - .arg(Arg::from_usage("[opt]... 'some pos'")) + .arg(arg!([opt] ... "some pos")) .get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"]); assert!(m.is_present("opt")); assert_eq!( @@ -478,10 +480,7 @@ fn dont_delim_values_trailingvararg() { #[test] fn delim_values_only_pos_follows() { let r = App::new("onlypos") - .args(&[ - Arg::from_usage("-f [flag] 'some opt'"), - Arg::from_usage("[arg]... 'some arg'"), - ]) + .args(&[arg!(f: -f [flag] "some opt"), arg!([arg] ... "some arg")]) .try_get_matches_from(vec!["", "--", "-f", "-g,x"]); assert!(r.is_ok()); let m = r.unwrap(); @@ -497,7 +496,7 @@ fn delim_values_only_pos_follows() { fn delim_values_trailingvararg() { let m = App::new("positional") .setting(AppSettings::TrailingVarArg) - .arg(Arg::from_usage("[opt]... 'some pos'")) + .arg(arg!([opt] ... "some pos")) .get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"]); assert!(m.is_present("opt")); assert_eq!( @@ -510,8 +509,8 @@ fn delim_values_trailingvararg() { fn delim_values_only_pos_follows_with_delim() { let r = App::new("onlypos") .args(&[ - Arg::from_usage("-f [flag] 'some opt'"), - Arg::from_usage("[arg]... 'some arg'").use_delimiter(true), + arg!(f: -f [flag] "some opt"), + arg!([arg] ... "some arg").use_delimiter(true), ]) .try_get_matches_from(vec!["", "--", "-f", "-g,x"]); assert!(r.is_ok()); @@ -528,7 +527,7 @@ fn delim_values_only_pos_follows_with_delim() { fn delim_values_trailingvararg_with_delim() { let m = App::new("positional") .setting(AppSettings::TrailingVarArg) - .arg(Arg::from_usage("[opt]... 'some pos'").use_delimiter(true)) + .arg(arg!([opt] ... "some pos").use_delimiter(true)) .get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"]); assert!(m.is_present("opt")); assert_eq!( @@ -608,7 +607,7 @@ fn leading_double_hyphen_trailingvararg() { let m = App::new("positional") .setting(AppSettings::TrailingVarArg) .setting(AppSettings::AllowLeadingHyphen) - .arg(Arg::from_usage("[opt]... 'some pos'")) + .arg(arg!([opt] ... "some pos")) .get_matches_from(vec!["", "--foo", "-Wl", "bar"]); assert!(m.is_present("opt")); assert_eq!( @@ -670,8 +669,8 @@ fn args_negate_subcommands_one_level() { let res = App::new("disablehelp") .setting(AppSettings::ArgsNegateSubcommands) .setting(AppSettings::SubcommandsNegateReqs) - .arg(Arg::from_usage(" 'some arg'")) - .arg(Arg::from_usage(" 'some arg'")) + .arg(arg!( "some arg")) + .arg(arg!( "some arg")) .subcommand(App::new("sub1").subcommand(App::new("sub2").subcommand(App::new("sub3")))) .try_get_matches_from(vec!["", "pickles", "sub1"]); assert!(res.is_ok(), "error: {:?}", res.unwrap_err().kind); @@ -684,12 +683,12 @@ fn args_negate_subcommands_two_levels() { let res = App::new("disablehelp") .global_setting(AppSettings::ArgsNegateSubcommands) .global_setting(AppSettings::SubcommandsNegateReqs) - .arg(Arg::from_usage(" 'some arg'")) - .arg(Arg::from_usage(" 'some arg'")) + .arg(arg!( "some arg")) + .arg(arg!( "some arg")) .subcommand( App::new("sub1") - .arg(Arg::from_usage(" 'some'")) - .arg(Arg::from_usage(" 'some'")) + .arg(arg!( "some")) + .arg(arg!( "some")) .subcommand(App::new("sub2").subcommand(App::new("sub3"))), ) .try_get_matches_from(vec!["", "sub1", "arg", "sub2"]); @@ -704,7 +703,7 @@ fn args_negate_subcommands_two_levels() { #[test] fn propagate_vals_down() { let m = App::new("myprog") - .arg(Arg::from_usage("[cmd] 'command to run'").global(true)) + .arg(arg!([cmd] "command to run").global(true)) .subcommand(App::new("foo")) .try_get_matches_from(vec!["myprog", "set", "foo"]); assert!(m.is_ok(), "{:?}", m.unwrap_err().kind); @@ -718,8 +717,8 @@ fn propagate_vals_down() { fn allow_missing_positional() { let m = App::new("test") .setting(AppSettings::AllowMissingPositional) - .arg(Arg::from_usage("[src] 'some file'").default_value("src")) - .arg(Arg::from_usage(" 'some file'")) + .arg(arg!([src] "some file").default_value("src")) + .arg(arg!( "some file")) .try_get_matches_from(vec!["test", "file"]); assert!(m.is_ok(), "{:?}", m.unwrap_err().kind); let m = m.unwrap(); @@ -731,8 +730,8 @@ fn allow_missing_positional() { fn allow_missing_positional_no_default() { let m = App::new("test") .setting(AppSettings::AllowMissingPositional) - .arg(Arg::from_usage("[src] 'some file'")) - .arg(Arg::from_usage(" 'some file'")) + .arg(arg!([src] "some file")) + .arg(arg!( "some file")) .try_get_matches_from(vec!["test", "file"]); assert!(m.is_ok(), "{:?}", m.unwrap_err().kind); let m = m.unwrap(); @@ -744,8 +743,8 @@ fn allow_missing_positional_no_default() { fn missing_positional_no_hyphen() { let r = App::new("bench") .setting(AppSettings::AllowMissingPositional) - .arg(Arg::from_usage("[BENCH] 'some bench'")) - .arg(Arg::from_usage("[ARGS]... 'some args'")) + .arg(arg!([BENCH] "some bench")) + .arg(arg!([ARGS] ... "some args")) .try_get_matches_from(vec!["bench", "foo", "arg1", "arg2", "arg3"]); assert!(r.is_ok(), "{:?}", r.unwrap_err().kind); @@ -765,8 +764,8 @@ fn missing_positional_no_hyphen() { fn missing_positional_hyphen() { let r = App::new("bench") .setting(AppSettings::AllowMissingPositional) - .arg(Arg::from_usage("[BENCH] 'some bench'")) - .arg(Arg::from_usage("[ARGS]... 'some args'")) + .arg(arg!([BENCH] "some bench")) + .arg(arg!([ARGS] ... "some args")) .try_get_matches_from(vec!["bench", "--", "arg1", "arg2", "arg3"]); assert!(r.is_ok(), "{:?}", r.unwrap_err().kind); @@ -786,10 +785,10 @@ fn missing_positional_hyphen() { fn missing_positional_hyphen_far_back() { let r = App::new("bench") .setting(AppSettings::AllowMissingPositional) - .arg(Arg::from_usage("[BENCH1] 'some bench'")) - .arg(Arg::from_usage("[BENCH2] 'some bench'")) - .arg(Arg::from_usage("[BENCH3] 'some bench'")) - .arg(Arg::from_usage("[ARGS]... 'some args'")) + .arg(arg!([BENCH1] "some bench")) + .arg(arg!([BENCH2] "some bench")) + .arg(arg!([BENCH3] "some bench")) + .arg(arg!([ARGS] ... "some args")) .try_get_matches_from(vec!["bench", "foo", "--", "arg1", "arg2", "arg3"]); assert!(r.is_ok(), "{:?}", r.unwrap_err().kind); @@ -813,9 +812,9 @@ fn missing_positional_hyphen_far_back() { fn missing_positional_hyphen_req_error() { let r = App::new("bench") .setting(AppSettings::AllowMissingPositional) - .arg(Arg::from_usage("[BENCH1] 'some bench'")) - .arg(Arg::from_usage(" 'some bench'")) - .arg(Arg::from_usage("[ARGS]... 'some args'")) + .arg(arg!([BENCH1] "some bench")) + .arg(arg!( "some bench")) + .arg(arg!([ARGS] ... "some args")) .try_get_matches_from(vec!["bench", "foo", "--", "arg1", "arg2", "arg3"]); assert!(r.is_err()); assert_eq!(r.unwrap_err().kind, ErrorKind::MissingRequiredArgument); @@ -825,7 +824,7 @@ fn missing_positional_hyphen_req_error() { fn issue_1066_allow_leading_hyphen_and_unknown_args() { let res = App::new("prog") .global_setting(AppSettings::AllowLeadingHyphen) - .arg(Arg::from_usage("--some-argument")) + .arg(arg!(--"some-argument")) .try_get_matches_from(vec!["prog", "hello"]); assert!(res.is_err()); @@ -836,7 +835,7 @@ fn issue_1066_allow_leading_hyphen_and_unknown_args() { fn issue_1066_allow_leading_hyphen_and_unknown_args_no_vals() { let res = App::new("prog") .global_setting(AppSettings::AllowLeadingHyphen) - .arg(Arg::from_usage("--some-argument")) + .arg(arg!(--"some-argument")) .try_get_matches_from(vec!["prog", "--hello"]); assert!(res.is_err()); @@ -847,7 +846,7 @@ fn issue_1066_allow_leading_hyphen_and_unknown_args_no_vals() { fn issue_1066_allow_leading_hyphen_and_unknown_args_option() { let res = App::new("prog") .global_setting(AppSettings::AllowLeadingHyphen) - .arg(Arg::from_usage("--some-argument=[val]")) + .arg(arg!(--"some-argument" )) .try_get_matches_from(vec!["prog", "-hello"]); assert!(res.is_err()); @@ -922,7 +921,7 @@ fn aaos_flags() { // flags let res = App::new("posix") .setting(AppSettings::AllArgsOverrideSelf) - .arg(Arg::from_usage("--flag 'some flag'")) + .arg(arg!(--flag "some flag")) .try_get_matches_from(vec!["", "--flag", "--flag"]); assert!(res.is_ok()); let m = res.unwrap(); @@ -935,7 +934,7 @@ fn aaos_flags_mult() { // flags with multiple let res = App::new("posix") .setting(AppSettings::AllArgsOverrideSelf) - .arg(Arg::from_usage("--flag... 'some flag'")) + .arg(arg!(--flag ... "some flag")) .try_get_matches_from(vec!["", "--flag", "--flag", "--flag", "--flag"]); assert!(res.is_ok()); let m = res.unwrap(); @@ -948,7 +947,7 @@ fn aaos_opts() { // opts let res = App::new("posix") .setting(AppSettings::AllArgsOverrideSelf) - .arg(Arg::from_usage("--opt [val] 'some option'")) + .arg(arg!(--opt "some option")) .try_get_matches_from(vec!["", "--opt=some", "--opt=other"]); assert!(res.is_ok()); let m = res.unwrap(); @@ -962,8 +961,12 @@ fn aaos_opts_w_other_overrides() { // opts with other overrides let res = App::new("posix") .setting(AppSettings::AllArgsOverrideSelf) - .arg(Arg::from_usage("--opt [val] 'some option'")) - .arg(Arg::from_usage("--other [val] 'some other option'").overrides_with("opt")) + .arg(arg!(--opt "some option").required(false)) + .arg( + arg!(--other "some other option") + .required(false) + .overrides_with("opt"), + ) .try_get_matches_from(vec!["", "--opt=some", "--other=test", "--opt=other"]); assert!(res.is_ok()); let m = res.unwrap(); @@ -978,8 +981,12 @@ fn aaos_opts_w_other_overrides_rev() { // opts with other overrides, rev let res = App::new("posix") .setting(AppSettings::AllArgsOverrideSelf) - .arg(Arg::from_usage("--opt [val] 'some option'")) - .arg(Arg::from_usage("--other [val] 'some other option'").overrides_with("opt")) + .arg(arg!(--opt "some option").required(true)) + .arg( + arg!(--other "some other option") + .required(true) + .overrides_with("opt"), + ) .try_get_matches_from(vec!["", "--opt=some", "--opt=other", "--other=val"]); assert!(res.is_ok()); let m = res.unwrap(); @@ -993,8 +1000,12 @@ fn aaos_opts_w_other_overrides_2() { // opts with other overrides let res = App::new("posix") .setting(AppSettings::AllArgsOverrideSelf) - .arg(Arg::from_usage("--opt [val] 'some option'").overrides_with("other")) - .arg(Arg::from_usage("--other [val] 'some other option'")) + .arg( + arg!(--opt "some option") + .required(false) + .overrides_with("other"), + ) + .arg(arg!(--other "some other option").required(false)) .try_get_matches_from(vec!["", "--opt=some", "--other=test", "--opt=other"]); assert!(res.is_ok()); let m = res.unwrap(); @@ -1009,8 +1020,12 @@ fn aaos_opts_w_other_overrides_rev_2() { // opts with other overrides, rev let res = App::new("posix") .setting(AppSettings::AllArgsOverrideSelf) - .arg(Arg::from_usage("--opt [val] 'some option'").overrides_with("other")) - .arg(Arg::from_usage("--other [val] 'some other option'")) + .arg( + arg!(--opt "some option") + .required(true) + .overrides_with("other"), + ) + .arg(arg!(--other "some other option").required(true)) .try_get_matches_from(vec!["", "--opt=some", "--opt=other", "--other=val"]); assert!(res.is_ok()); let m = res.unwrap(); @@ -1025,7 +1040,7 @@ fn aaos_opts_mult() { let res = App::new("posix") .setting(AppSettings::AllArgsOverrideSelf) .arg( - Arg::from_usage("--opt [val]... 'some option'") + arg!(--opt ... "some option") .number_of_values(1) .takes_value(true) .use_delimiter(true) @@ -1047,7 +1062,7 @@ fn aaos_opts_mult_req_delims() { // opts with multiple and require delims let res = App::new("posix") .setting(AppSettings::AllArgsOverrideSelf) - .arg(Arg::from_usage("--opt [val]... 'some option'")) + .arg(arg!(--opt ... "some option").multiple_values(true)) .try_get_matches_from(vec![ "", "--opt", @@ -1073,7 +1088,7 @@ fn aaos_pos_mult() { // opts with multiple let res = App::new("posix") .setting(AppSettings::AllArgsOverrideSelf) - .arg(Arg::from_usage("[val]... 'some pos'")) + .arg(arg!([val] ... "some pos")) .try_get_matches_from(vec!["", "some", "other", "value"]); assert!(res.is_ok()); let m = res.unwrap(); @@ -1089,7 +1104,7 @@ fn aaos_pos_mult() { fn aaos_option_use_delim_false() { let m = App::new("posix") .setting(AppSettings::AllArgsOverrideSelf) - .arg(Arg::from_usage("--opt [val] 'some option'").use_delimiter(false)) + .arg(arg!(--opt "some option").use_delimiter(false)) .get_matches_from(vec!["", "--opt=some,other", "--opt=one,two"]); assert!(m.is_present("opt")); assert_eq!(m.occurrences_of("opt"), 1); diff --git a/tests/arg_aliases.rs b/tests/arg_aliases.rs index 094d37cac2a..1c043f6473c 100644 --- a/tests/arg_aliases.rs +++ b/tests/arg_aliases.rs @@ -1,6 +1,6 @@ mod utils; -use clap::{App, Arg}; +use clap::{arg, App, Arg}; static SC_VISIBLE_ALIAS_HELP: &str = "ct-test 1.2 @@ -167,7 +167,7 @@ fn invisible_arg_aliases_help_output() { .takes_value(true) .aliases(&["invisible", "als1", "more"]), ) - .arg(Arg::from_usage("-f, --flag").aliases(&["unseeable", "flg1", "anyway"])), + .arg(arg!(-f - -flag).aliases(&["unseeable", "flg1", "anyway"])), ); assert!(utils::compare_output( app, diff --git a/tests/arg_aliases_short.rs b/tests/arg_aliases_short.rs index 0e73d5d8f37..a4e4d42e1a4 100644 --- a/tests/arg_aliases_short.rs +++ b/tests/arg_aliases_short.rs @@ -1,6 +1,6 @@ mod utils; -use clap::{App, Arg}; +use clap::{arg, App, Arg}; static SC_VISIBLE_ALIAS_HELP: &str = "ct-test 1.2 @@ -163,7 +163,7 @@ fn invisible_short_arg_aliases_help_output() { .takes_value(true) .short_aliases(&['a', 'b', 'c']), ) - .arg(Arg::from_usage("-f, --flag").short_aliases(&['x', 'y', 'z'])), + .arg(arg!(-f - -flag).short_aliases(&['x', 'y', 'z'])), ); assert!(utils::compare_output( app, diff --git a/tests/conflicts.rs b/tests/conflicts.rs index 19070e7ddc3..f1e79c0c0b6 100644 --- a/tests/conflicts.rs +++ b/tests/conflicts.rs @@ -1,6 +1,6 @@ mod utils; -use clap::{App, Arg, ArgGroup, ErrorKind}; +use clap::{arg, App, Arg, ArgGroup, ErrorKind}; static CONFLICT_ERR: &str = "error: The argument '-F' cannot be used with '--flag' @@ -29,8 +29,8 @@ For more information try --help #[test] fn flag_conflict() { let result = App::new("flag_conflict") - .arg(Arg::from_usage("-f, --flag 'some flag'").conflicts_with("other")) - .arg(Arg::from_usage("-o, --other 'some flag'")) + .arg(arg!(-f --flag "some flag").conflicts_with("other")) + .arg(arg!(-o --other "some flag")) .try_get_matches_from(vec!["myprog", "-f", "-o"]); assert!(result.is_err()); let err = result.err().unwrap(); @@ -40,8 +40,8 @@ fn flag_conflict() { #[test] fn flag_conflict_2() { let result = App::new("flag_conflict") - .arg(Arg::from_usage("-f, --flag 'some flag'").conflicts_with("other")) - .arg(Arg::from_usage("-o, --other 'some flag'")) + .arg(arg!(-f --flag "some flag").conflicts_with("other")) + .arg(arg!(-o --other "some flag")) .try_get_matches_from(vec!["myprog", "-o", "-f"]); assert!(result.is_err()); let err = result.err().unwrap(); @@ -51,8 +51,8 @@ fn flag_conflict_2() { #[test] fn flag_conflict_with_all() { let result = App::new("flag_conflict") - .arg(Arg::from_usage("-f, --flag 'some flag'").conflicts_with_all(&["other"])) - .arg(Arg::from_usage("-o, --other 'some flag'")) + .arg(arg!(-f --flag "some flag").conflicts_with_all(&["other"])) + .arg(arg!(-o --other "some flag")) .try_get_matches_from(vec!["myprog", "-o", "-f"]); assert!(result.is_err()); let err = result.err().unwrap(); @@ -62,8 +62,8 @@ fn flag_conflict_with_all() { #[test] fn flag_conflict_with_everything() { let result = App::new("flag_conflict") - .arg(Arg::from_usage("-f, --flag 'some flag'").exclusive(true)) - .arg(Arg::from_usage("-o, --other 'some flag'")) + .arg(arg!(-f --flag "some flag").exclusive(true)) + .arg(arg!(-o --other "some flag")) .try_get_matches_from(vec!["myprog", "-o", "-f"]); assert!(result.is_err()); let err = result.err().unwrap(); @@ -73,10 +73,10 @@ fn flag_conflict_with_everything() { #[test] fn group_conflict() { let result = App::new("group_conflict") - .arg(Arg::from_usage("-f, --flag 'some flag'").conflicts_with("gr")) + .arg(arg!(-f --flag "some flag").conflicts_with("gr")) .group(ArgGroup::new("gr").required(true).arg("some").arg("other")) - .arg(Arg::from_usage("--some 'some arg'")) - .arg(Arg::from_usage("--other 'other arg'")) + .arg(arg!(--some "some arg")) + .arg(arg!(--other "other arg")) .try_get_matches_from(vec!["myprog", "--other", "-f"]); assert!(result.is_err()); let err = result.err().unwrap(); @@ -86,10 +86,10 @@ fn group_conflict() { #[test] fn group_conflict_2() { let result = App::new("group_conflict") - .arg(Arg::from_usage("-f, --flag 'some flag'").conflicts_with("gr")) + .arg(arg!(-f --flag "some flag").conflicts_with("gr")) .group(ArgGroup::new("gr").required(true).arg("some").arg("other")) - .arg(Arg::from_usage("--some 'some arg'")) - .arg(Arg::from_usage("--other 'other arg'")) + .arg(arg!(--some "some arg")) + .arg(arg!(--other "other arg")) .try_get_matches_from(vec!["myprog", "-f", "--some"]); assert!(result.is_err()); let err = result.err().unwrap(); @@ -238,8 +238,12 @@ fn conflicts_with_invalid_arg() { #[test] fn conflict_with_unused_default() { let result = App::new("conflict") - .arg(Arg::from_usage("-o, --opt=[opt] 'some opt'").default_value("default")) - .arg(Arg::from_usage("-f, --flag 'some flag'").conflicts_with("opt")) + .arg( + arg!(-o --opt "some opt") + .required(false) + .default_value("default"), + ) + .arg(arg!(-f --flag "some flag").conflicts_with("opt")) .try_get_matches_from(vec!["myprog", "-f"]); assert!(result.is_ok()); @@ -253,11 +257,12 @@ fn conflict_with_unused_default() { fn conflicts_with_alongside_default() { let result = App::new("conflict") .arg( - Arg::from_usage("-o, --opt=[opt] 'some opt'") + arg!(-o --opt "some opt") .default_value("default") + .required(false) .conflicts_with("flag"), ) - .arg(Arg::from_usage("-f, --flag 'some flag'")) + .arg(arg!(-f --flag "some flag")) .try_get_matches_from(vec!["myprog", "-f"]); assert!( diff --git a/tests/default_missing_vals.rs b/tests/default_missing_vals.rs index 02117819f94..0eaf450dafc 100644 --- a/tests/default_missing_vals.rs +++ b/tests/default_missing_vals.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg, ArgMatches}; +use clap::{arg, App, Arg, ArgMatches}; #[test] fn opt_missing() { @@ -82,7 +82,7 @@ fn opt_default() { // assert no change to usual argument handling when adding default_missing_value() let r = App::new("app") .arg( - Arg::from_usage("-o [opt] 'some opt'") + arg!(o: -o [opt] "some opt") .default_value("default") .default_missing_value("default_missing"), ) @@ -98,7 +98,7 @@ fn opt_default_user_override() { // assert no change to usual argument handling when adding default_missing_value() let r = App::new("app") .arg( - Arg::from_usage("-o [opt] 'some opt'") + arg!(o: -o [opt] "some opt") .default_value("default") .default_missing_value("default_missing"), ) diff --git a/tests/default_vals.rs b/tests/default_vals.rs index 054c5bef549..d9cc5d8ad79 100644 --- a/tests/default_vals.rs +++ b/tests/default_vals.rs @@ -1,10 +1,14 @@ mod utils; -use clap::{App, Arg, ErrorKind}; +use clap::{arg, App, Arg, ErrorKind}; #[test] fn opts() { let r = App::new("df") - .arg(Arg::from_usage("-o [opt] 'some opt'").default_value("default")) + .arg( + arg!(o: -o "some opt") + .required(false) + .default_value("default"), + ) .try_get_matches_from(vec![""]); assert!(r.is_ok()); let m = r.unwrap(); @@ -16,7 +20,8 @@ fn opts() { fn opt_without_value_fail() { let r = App::new("df") .arg( - Arg::from_usage("-o [opt] 'some opt'") + arg!(o: -o "some opt") + .required(false) .default_value("default") .forbid_empty_values(true), ) @@ -32,7 +37,11 @@ fn opt_without_value_fail() { #[test] fn opt_user_override() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'").default_value("default")) + .arg( + arg!(--opt "some arg") + .required(false) + .default_value("default"), + ) .try_get_matches_from(vec!["", "--opt", "value"]); assert!(r.is_ok()); let m = r.unwrap(); @@ -43,7 +52,7 @@ fn opt_user_override() { #[test] fn positionals() { let r = App::new("df") - .arg(Arg::from_usage("[arg] 'some opt'").default_value("default")) + .arg(arg!([arg] "some opt").default_value("default")) .try_get_matches_from(vec![""]); assert!(r.is_ok()); let m = r.unwrap(); @@ -54,7 +63,7 @@ fn positionals() { #[test] fn positional_user_override() { let r = App::new("df") - .arg(Arg::from_usage("[arg] 'some arg'").default_value("default")) + .arg(arg!([arg] "some arg").default_value("default")) .try_get_matches_from(vec!["", "value"]); assert!(r.is_ok()); let m = r.unwrap(); @@ -70,7 +79,11 @@ fn osstr_opts() { let expected = OsStr::new("default"); let r = App::new("df") - .arg(Arg::from_usage("-o [opt] 'some opt'").default_value_os(expected)) + .arg( + arg!(o: -o "some opt") + .required(false) + .default_value_os(expected), + ) .try_get_matches_from(vec![""]); assert!(r.is_ok()); let m = r.unwrap(); @@ -84,7 +97,11 @@ fn osstr_opt_user_override() { let default = OsStr::new("default"); let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'").default_value_os(default)) + .arg( + arg!(--opt "some arg") + .required(false) + .default_value_os(default), + ) .try_get_matches_from(vec!["", "--opt", "value"]); assert!(r.is_ok()); let m = r.unwrap(); @@ -98,7 +115,7 @@ fn osstr_positionals() { let expected = OsStr::new("default"); let r = App::new("df") - .arg(Arg::from_usage("[arg] 'some opt'").default_value_os(expected)) + .arg(arg!([arg] "some opt").default_value_os(expected)) .try_get_matches_from(vec![""]); assert!(r.is_ok()); let m = r.unwrap(); @@ -112,7 +129,7 @@ fn osstr_positional_user_override() { let default = OsStr::new("default"); let r = App::new("df") - .arg(Arg::from_usage("[arg] 'some arg'").default_value_os(default)) + .arg(arg!([arg] "some arg").default_value_os(default)) .try_get_matches_from(vec!["", "value"]); assert!(r.is_ok()); let m = r.unwrap(); @@ -125,8 +142,8 @@ fn osstr_positional_user_override() { #[test] fn default_if_arg_present_no_default() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) - .arg(Arg::from_usage("[arg] 'some arg'").default_value_if("opt", None, Some("default"))) + .arg(arg!(--opt "some arg").required(true)) + .arg(arg!([arg] "some arg").default_value_if("opt", None, Some("default"))) .try_get_matches_from(vec!["", "--opt", "some"]); assert!(r.is_ok()); let m = r.unwrap(); @@ -137,8 +154,8 @@ fn default_if_arg_present_no_default() { #[test] fn default_if_arg_present_no_default_user_override() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) - .arg(Arg::from_usage("[arg] 'some arg'").default_value_if("opt", None, Some("default"))) + .arg(arg!(--opt "some arg").required(false)) + .arg(arg!([arg] "some arg").default_value_if("opt", None, Some("default"))) .try_get_matches_from(vec!["", "--opt", "some", "other"]); assert!(r.is_ok()); let m = r.unwrap(); @@ -149,9 +166,9 @@ fn default_if_arg_present_no_default_user_override() { #[test] fn default_if_arg_present_no_arg_with_default() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_if("opt", None, Some("default")), ) @@ -165,9 +182,9 @@ fn default_if_arg_present_no_arg_with_default() { #[test] fn default_if_arg_present_with_default() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_if("opt", None, Some("default")), ) @@ -181,9 +198,9 @@ fn default_if_arg_present_with_default() { #[test] fn default_if_arg_present_with_default_user_override() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_if("opt", None, Some("default")), ) @@ -197,9 +214,9 @@ fn default_if_arg_present_with_default_user_override() { #[test] fn default_if_arg_present_no_arg_with_default_user_override() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_if("opt", None, Some("default")), ) @@ -215,12 +232,8 @@ fn default_if_arg_present_no_arg_with_default_user_override() { #[test] fn default_if_arg_present_with_value_no_default() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) - .arg(Arg::from_usage("[arg] 'some arg'").default_value_if( - "opt", - Some("value"), - Some("default"), - )) + .arg(arg!(--opt "some arg").required(false)) + .arg(arg!([arg] "some arg").default_value_if("opt", Some("value"), Some("default"))) .try_get_matches_from(vec!["", "--opt", "value"]); assert!(r.is_ok()); let m = r.unwrap(); @@ -231,12 +244,8 @@ fn default_if_arg_present_with_value_no_default() { #[test] fn default_if_arg_present_with_value_no_default_fail() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) - .arg(Arg::from_usage("[arg] 'some arg'").default_value_if( - "opt", - Some("value"), - Some("default"), - )) + .arg(arg!(--opt "some arg").required(false)) + .arg(arg!([arg] "some arg").default_value_if("opt", Some("value"), Some("default"))) .try_get_matches_from(vec!["", "--opt", "other"]); assert!(r.is_ok()); let m = r.unwrap(); @@ -247,12 +256,8 @@ fn default_if_arg_present_with_value_no_default_fail() { #[test] fn default_if_arg_present_with_value_no_default_user_override() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) - .arg(Arg::from_usage("[arg] 'some arg'").default_value_if( - "opt", - Some("some"), - Some("default"), - )) + .arg(arg!(--opt "some arg").required(false)) + .arg(arg!([arg] "some arg").default_value_if("opt", Some("some"), Some("default"))) .try_get_matches_from(vec!["", "--opt", "some", "other"]); assert!(r.is_ok()); let m = r.unwrap(); @@ -263,9 +268,9 @@ fn default_if_arg_present_with_value_no_default_user_override() { #[test] fn default_if_arg_present_with_value_no_arg_with_default() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_if("opt", Some("some"), Some("default")), ) @@ -279,9 +284,9 @@ fn default_if_arg_present_with_value_no_arg_with_default() { #[test] fn default_if_arg_present_with_value_no_arg_with_default_fail() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_if("opt", Some("some"), Some("default")), ) @@ -295,9 +300,9 @@ fn default_if_arg_present_with_value_no_arg_with_default_fail() { #[test] fn default_if_arg_present_with_value_with_default() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_if("opt", Some("some"), Some("default")), ) @@ -311,9 +316,9 @@ fn default_if_arg_present_with_value_with_default() { #[test] fn default_if_arg_present_with_value_with_default_user_override() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_if("opt", Some("some"), Some("default")), ) @@ -327,9 +332,9 @@ fn default_if_arg_present_with_value_with_default_user_override() { #[test] fn default_if_arg_present_no_arg_with_value_with_default_user_override() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_if("opt", Some("some"), Some("default")), ) @@ -343,9 +348,9 @@ fn default_if_arg_present_no_arg_with_value_with_default_user_override() { #[test] fn default_if_arg_present_no_arg_with_value_with_default_user_override_fail() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_if("opt", Some("some"), Some("default")), ) @@ -361,8 +366,8 @@ fn default_if_arg_present_no_arg_with_value_with_default_user_override_fail() { #[test] fn no_default_if_arg_present_with_value_no_default() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) - .arg(Arg::from_usage("[arg] 'some arg'").default_value_if("opt", Some("value"), None)) + .arg(arg!(--opt "some arg").required(false)) + .arg(arg!([arg] "some arg").default_value_if("opt", Some("value"), None)) .try_get_matches_from(vec!["", "--opt", "value"]); assert!(r.is_ok()); let m = r.unwrap(); @@ -372,9 +377,9 @@ fn no_default_if_arg_present_with_value_no_default() { #[test] fn no_default_if_arg_present_with_value_with_default() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("default") .default_value_if("opt", Some("value"), None), ) @@ -388,9 +393,9 @@ fn no_default_if_arg_present_with_value_with_default() { #[test] fn no_default_if_arg_present_with_value_with_default_user_override() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("default") .default_value_if("opt", Some("value"), None), ) @@ -404,9 +409,9 @@ fn no_default_if_arg_present_with_value_with_default_user_override() { #[test] fn no_default_if_arg_present_no_arg_with_value_with_default() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("default") .default_value_if("opt", Some("value"), None), ) @@ -422,10 +427,10 @@ fn no_default_if_arg_present_no_arg_with_value_with_default() { #[test] fn default_ifs_arg_present() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) - .arg(Arg::from_usage("--flag 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) + .arg(arg!(--flag "some arg")) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_ifs(&[ ("opt", Some("some"), Some("default")), @@ -442,10 +447,10 @@ fn default_ifs_arg_present() { #[test] fn no_default_ifs_arg_present() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) - .arg(Arg::from_usage("--flag 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) + .arg(arg!(--flag "some arg")) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_ifs(&[("opt", Some("some"), Some("default")), ("flag", None, None)]), ) @@ -459,10 +464,10 @@ fn no_default_ifs_arg_present() { #[test] fn default_ifs_arg_present_user_override() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) - .arg(Arg::from_usage("--flag 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) + .arg(arg!(--flag "some arg")) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_ifs(&[ ("opt", Some("some"), Some("default")), @@ -479,10 +484,10 @@ fn default_ifs_arg_present_user_override() { #[test] fn default_ifs_arg_present_order() { let r = App::new("df") - .arg(Arg::from_usage("--opt [FILE] 'some arg'")) - .arg(Arg::from_usage("--flag 'some arg'")) + .arg(arg!(--opt "some arg").required(false)) + .arg(arg!(--flag "some arg")) .arg( - Arg::from_usage("[arg] 'some arg'") + arg!([arg] "some arg") .default_value("first") .default_value_ifs(&[ ("opt", Some("some"), Some("default")), diff --git a/tests/env.rs b/tests/env.rs index 4efd64d7764..d75f245cccd 100644 --- a/tests/env.rs +++ b/tests/env.rs @@ -3,18 +3,14 @@ use std::env; use std::ffi::OsStr; -use clap::{App, Arg}; +use clap::{arg, App, Arg}; #[test] fn env() { env::set_var("CLP_TEST_ENV", "env"); let r = App::new("df") - .arg( - Arg::from_usage("[arg] 'some opt'") - .env("CLP_TEST_ENV") - .takes_value(true), - ) + .arg(arg!([arg] "some opt").env("CLP_TEST_ENV").takes_value(true)) .try_get_matches_from(vec![""]); assert!(r.is_ok()); @@ -50,7 +46,7 @@ fn env_os() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env_os(OsStr::new("CLP_TEST_ENV_OS")) .takes_value(true), ) @@ -71,7 +67,7 @@ fn no_env() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_NONE") .takes_value(true), ) @@ -91,7 +87,7 @@ fn no_env_no_takes_value() { env::remove_var("CLP_TEST_ENV_NONE"); let r = App::new("df") - .arg(Arg::from_usage("[arg] 'some opt'").env("CLP_TEST_ENV_NONE")) + .arg(arg!([arg] "some opt").env("CLP_TEST_ENV_NONE")) .try_get_matches_from(vec![""]); assert!(r.is_ok()); @@ -107,7 +103,7 @@ fn with_default() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_WD") .takes_value(true) .default_value("default"), @@ -127,7 +123,7 @@ fn opt_user_override() { let r = App::new("df") .arg( - Arg::from_usage("--arg [FILE] 'some arg'") + arg!(--arg [FILE] "some arg") .env("CLP_TEST_ENV_OR") .takes_value(true), ) @@ -150,7 +146,7 @@ fn positionals() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_P") .takes_value(true), ) @@ -169,7 +165,7 @@ fn positionals_user_override() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_POR") .takes_value(true), ) @@ -192,7 +188,7 @@ fn multiple_one() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_MO") .takes_value(true) .use_delimiter(true) @@ -213,7 +209,7 @@ fn multiple_three() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_MULTI1") .takes_value(true) .use_delimiter(true) @@ -237,7 +233,7 @@ fn multiple_no_delimiter() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_MULTI2") .takes_value(true) .multiple_values(true), @@ -260,7 +256,7 @@ fn possible_value() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_PV") .takes_value(true) .possible_value("env"), @@ -280,7 +276,7 @@ fn not_possible_value() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_NPV") .takes_value(true) .possible_value("never"), @@ -296,7 +292,7 @@ fn validator() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_VDOR") .takes_value(true) .validator(|s| { @@ -322,7 +318,7 @@ fn validator_output() { let m = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_VO") .takes_value(true) .validator(|s| s.parse::()), @@ -338,7 +334,7 @@ fn validator_invalid() { let r = App::new("df") .arg( - Arg::from_usage("[arg] 'some opt'") + arg!([arg] "some opt") .env("CLP_TEST_ENV_IV") .takes_value(true) .validator(|s| { diff --git a/tests/flag_subcommands.rs b/tests/flag_subcommands.rs index f6900bdb528..3b79de070fc 100644 --- a/tests/flag_subcommands.rs +++ b/tests/flag_subcommands.rs @@ -1,6 +1,6 @@ mod utils; -use clap::{App, AppSettings, Arg, ErrorKind}; +use clap::{arg, App, AppSettings, Arg, ErrorKind}; #[test] fn flag_subcommand_normal() { @@ -274,14 +274,14 @@ fn flag_subcommand_multiple() { App::new("some") .short_flag('S') .long_flag("some") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage("-p, --print 'print something'")) + .arg(arg!(-f --flag "some flag")) + .arg(arg!(-p --print "print something")) .subcommand( App::new("result") .short_flag('R') .long_flag("result") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage("-p, --print 'print something'")), + .arg(arg!(-f --flag "some flag")) + .arg(arg!(-p --print "print something")), ), ) .get_matches_from(vec!["myprog", "-SfpRfp"]); diff --git a/tests/flags.rs b/tests/flags.rs index 0aaf05118b1..65dc964bfbd 100644 --- a/tests/flags.rs +++ b/tests/flags.rs @@ -1,5 +1,5 @@ mod utils; -use clap::{App, Arg}; +use clap::{arg, App, Arg}; const USE_FLAG_AS_ARGUMENT: &str = "error: Found argument '--another-flag' which wasn't expected, or isn't valid in this context @@ -16,8 +16,8 @@ For more information try --help fn flag_using_short() { let m = App::new("flag") .args(&[ - Arg::from_usage("-f, --flag 'some flag'"), - Arg::from_usage("-c, --color 'some other flag'"), + arg!(-f --flag "some flag"), + arg!(-c --color "some other flag"), ]) .get_matches_from(vec!["", "-f", "-c"]); assert!(m.is_present("flag")); @@ -27,7 +27,7 @@ fn flag_using_short() { #[test] fn lots_o_flags_sep() { let r = App::new("opts") - .arg(Arg::from_usage("-o... 'some flag'")) + .arg(arg!(o: -o ... "some flag")) .try_get_matches_from(vec![ "", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", @@ -61,7 +61,7 @@ fn lots_o_flags_sep() { #[test] fn lots_o_flags_combined() { let r = App::new("opts") - .arg(Arg::from_usage("-o... 'some flag'")) + .arg(arg!(o: -o ... "some flag")) .try_get_matches_from(vec![ "", "-oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo", @@ -79,10 +79,7 @@ fn lots_o_flags_combined() { #[test] fn flag_using_long() { let m = App::new("flag") - .args(&[ - Arg::from_usage("--flag 'some flag'"), - Arg::from_usage("--color 'some other flag'"), - ]) + .args(&[arg!(--flag "some flag"), arg!(--color "some other flag")]) .get_matches_from(vec!["", "--flag", "--color"]); assert!(m.is_present("flag")); assert!(m.is_present("color")); @@ -103,8 +100,8 @@ fn flag_using_long_with_literals() { fn flag_using_mixed() { let m = App::new("flag") .args(&[ - Arg::from_usage("-f, --flag 'some flag'"), - Arg::from_usage("-c, --color 'some other flag'"), + arg!(-f --flag "some flag"), + arg!(-c --color "some other flag"), ]) .get_matches_from(vec!["", "-f", "--color"]); assert!(m.is_present("flag")); @@ -112,8 +109,8 @@ fn flag_using_mixed() { let m = App::new("flag") .args(&[ - Arg::from_usage("-f, --flag 'some flag'"), - Arg::from_usage("-c, --color 'some other flag'"), + arg!(-f --flag "some flag"), + arg!(-c --color "some other flag"), ]) .get_matches_from(vec!["", "--flag", "-c"]); assert!(m.is_present("flag")); @@ -124,9 +121,9 @@ fn flag_using_mixed() { fn multiple_flags_in_single() { let m = App::new("multe_flags") .args(&[ - Arg::from_usage("-f, --flag 'some flag'"), - Arg::from_usage("-c, --color 'some other flag'"), - Arg::from_usage("-d, --debug 'another other flag'"), + arg!(-f --flag "some flag"), + arg!(-c --color "some other flag"), + arg!(-d --debug "another other flag"), ]) .get_matches_from(vec!["", "-fcd"]); assert!(m.is_present("flag")); diff --git a/tests/global_args.rs b/tests/global_args.rs index 46bbba4f20c..82cfdced7f9 100644 --- a/tests/global_args.rs +++ b/tests/global_args.rs @@ -1,6 +1,6 @@ mod utils; -use clap::{App, Arg}; +use clap::{arg, App, Arg}; #[test] fn issue_1076() { @@ -49,20 +49,12 @@ fn propagate_global_arg_in_subcommand_to_subsubcommand_1385() { #[test] fn propagate_global_arg_to_subcommand_in_subsubcommand_2053() { let m = App::new("opts") - .arg(Arg::from_usage("--global-flag").global(true)) - .arg( - Arg::from_usage("--global-str ") - .required(false) - .global(true), - ) + .arg(arg!(--"global-flag").global(true)) + .arg(arg!(--"global-str" ).required(false).global(true)) .subcommand( App::new("test") - .arg(Arg::from_usage("--sub-flag").global(true)) - .arg( - Arg::from_usage("--sub-str ") - .required(false) - .global(true), - ) + .arg(arg!(--"sub-flag").global(true)) + .arg(arg!(--"sub-str" ).required(false).global(true)) .subcommand(App::new("test")), ) .get_matches_from(&[ diff --git a/tests/groups.rs b/tests/groups.rs index 0f06957a4b1..367d117720c 100644 --- a/tests/groups.rs +++ b/tests/groups.rs @@ -1,6 +1,6 @@ mod utils; -use clap::{App, Arg, ArgGroup, ErrorKind}; +use clap::{arg, App, Arg, ArgGroup, ErrorKind}; static REQ_GROUP_USAGE: &str = "error: The following required arguments were not provided: @@ -32,8 +32,8 @@ For more information try --help #[test] fn required_group_missing_arg() { let result = App::new("group") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage(" -c, --color 'some other flag'")) + .arg(arg!(-f --flag "some flag")) + .arg(arg!( -c --color "some other flag")) .group(ArgGroup::new("req").args(&["flag", "color"]).required(true)) .try_get_matches_from(vec![""]); assert!(result.is_err()); @@ -46,8 +46,8 @@ fn required_group_missing_arg() { #[should_panic = "Argument group 'req' contains non-existent argument"] fn non_existing_arg() { let _ = App::new("group") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage("-c, --color 'some other flag'")) + .arg(arg!(-f --flag "some flag")) + .arg(arg!(-c --color "some other flag")) .group(ArgGroup::new("req").args(&["flg", "color"]).required(true)) .try_get_matches_from(vec![""]); } @@ -57,8 +57,8 @@ fn non_existing_arg() { #[should_panic = "Argument group name must be unique\n\n\t'req' is already in use"] fn unique_group_name() { let _ = App::new("group") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage("-c, --color 'some other flag'")) + .arg(arg!(-f --flag "some flag")) + .arg(arg!(-c --color "some other flag")) .group(ArgGroup::new("req").args(&["flag"]).required(true)) .group(ArgGroup::new("req").args(&["color"]).required(true)) .try_get_matches_from(vec![""]); @@ -86,8 +86,8 @@ fn arg_group_new_of_arg_name() { #[test] fn group_single_value() { let res = App::new("group") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage("-c, --color [color] 'some option'")) + .arg(arg!(-f --flag "some flag")) + .arg(arg!(-c --color [color] "some option")) .group(ArgGroup::new("grp").args(&["flag", "color"])) .try_get_matches_from(vec!["", "-c", "blue"]); assert!(res.is_ok()); @@ -100,8 +100,8 @@ fn group_single_value() { #[test] fn group_single_flag() { let res = App::new("group") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage("-c, --color [color] 'some option'")) + .arg(arg!(-f --flag "some flag")) + .arg(arg!(-c --color [color] "some option")) .group(ArgGroup::new("grp").args(&["flag", "color"])) .try_get_matches_from(vec!["", "-f"]); assert!(res.is_ok()); @@ -114,8 +114,8 @@ fn group_single_flag() { #[test] fn group_empty() { let res = App::new("group") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage("-c, --color [color] 'some option'")) + .arg(arg!(-f --flag "some flag")) + .arg(arg!(-c --color [color] "some option")) .group(ArgGroup::new("grp").args(&["flag", "color"])) .try_get_matches_from(vec![""]); assert!(res.is_ok()); @@ -128,8 +128,8 @@ fn group_empty() { #[test] fn group_reqired_flags_empty() { let result = App::new("group") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage("-c, --color 'some option'")) + .arg(arg!(-f --flag "some flag")) + .arg(arg!(-c --color "some option")) .group(ArgGroup::new("grp").required(true).args(&["flag", "color"])) .try_get_matches_from(vec![""]); assert!(result.is_err()); @@ -140,8 +140,8 @@ fn group_reqired_flags_empty() { #[test] fn group_multi_value_single_arg() { let res = App::new("group") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage("-c, --color [color]... 'some option'")) + .arg(arg!(-f --flag "some flag")) + .arg(arg!(-c --color "some option").multiple_values(true)) .group(ArgGroup::new("grp").args(&["flag", "color"])) .try_get_matches_from(vec!["", "-c", "blue", "red", "green"]); assert!(res.is_ok(), "{:?}", res.unwrap_err().kind); @@ -157,7 +157,7 @@ fn group_multi_value_single_arg() { #[test] fn empty_group() { let r = App::new("empty_group") - .arg(Arg::from_usage("-f, --flag 'some flag'")) + .arg(arg!(-f --flag "some flag")) .group(ArgGroup::new("vers").required(true)) .try_get_matches_from(vec!["empty_prog"]); assert!(r.is_err()); @@ -168,9 +168,9 @@ fn empty_group() { #[test] fn req_group_usage_string() { let app = App::new("req_group") - .arg(Arg::from_usage("[base] 'Base commit'")) - .arg(Arg::from_usage( - "-d, --delete 'Remove the base commit information'", + .arg(arg!([base] "Base commit")) + .arg(arg!( + -d --delete "Remove the base commit information" )) .group( ArgGroup::new("base_or_delete") @@ -189,9 +189,9 @@ fn req_group_usage_string() { #[test] fn req_group_with_conflict_usage_string() { let app = App::new("req_group") - .arg(Arg::from_usage("[base] 'Base commit'").conflicts_with("delete")) - .arg(Arg::from_usage( - "-d, --delete 'Remove the base commit information'", + .arg(arg!([base] "Base commit").conflicts_with("delete")) + .arg(arg!( + -d --delete "Remove the base commit information" )) .group( ArgGroup::new("base_or_delete") @@ -210,9 +210,9 @@ fn req_group_with_conflict_usage_string() { #[test] fn req_group_with_conflict_usage_string_only_options() { let app = App::new("req_group") - .arg(Arg::from_usage(" -a --all 'All'").conflicts_with("delete")) - .arg(Arg::from_usage( - " -d, --delete 'Remove the base commit information'", + .arg(arg!(-a --all "All").conflicts_with("delete")) + .arg(arg!( + -d --delete "Remove the base commit information" )) .group( ArgGroup::new("all_or_delete") @@ -230,8 +230,8 @@ fn req_group_with_conflict_usage_string_only_options() { #[test] fn required_group_multiple_args() { let result = App::new("group") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage("-c, --color 'some other flag'")) + .arg(arg!(-f --flag "some flag")) + .arg(arg!(-c --color "some other flag")) .group( ArgGroup::new("req") .args(&["flag", "color"]) @@ -248,8 +248,8 @@ fn required_group_multiple_args() { #[test] fn group_multiple_args_error() { let result = App::new("group") - .arg(Arg::from_usage("-f, --flag 'some flag'")) - .arg(Arg::from_usage("-c, --color 'some other flag'")) + .arg(arg!(-f --flag "some flag")) + .arg(arg!(-c --color "some other flag")) .group(ArgGroup::new("req").args(&["flag", "color"])) .try_get_matches_from(vec!["group", "-f", "-c"]); assert!(result.is_err()); diff --git a/tests/help.rs b/tests/help.rs index 867352beb11..2bf792d3ae2 100644 --- a/tests/help.rs +++ b/tests/help.rs @@ -1,6 +1,6 @@ mod utils; -use clap::{App, AppSettings, Arg, ArgGroup, ArgSettings, ErrorKind, PossibleValue}; +use clap::{arg, App, AppSettings, Arg, ArgGroup, ArgSettings, ErrorKind, PossibleValue}; static REQUIRE_DELIM_HELP: &str = "test 1.3 @@ -666,7 +666,7 @@ fn help_subcommand() { .subcommand( App::new("test") .about("tests things") - .arg(Arg::from_usage("-v --verbose 'with verbosity'")), + .arg(arg!(-v --verbose "with verbosity")), ) .try_get_matches_from(vec!["myprog", "help"]); @@ -832,12 +832,17 @@ fn multi_level_sc_help() { .about("tests subcommands") .author("Kevin K. ") .version("0.1") - .arg(Arg::from_usage( - "-f, --flag 'tests flags'", + .arg(arg!( + -f --flag "tests flags" )) - .arg(Arg::from_usage( - "-o, --option [scoption]... 'tests options'", - )), + .arg( + arg!( + -o --option "tests options" + ) + .required(false) + .multiple_values(true) + .multiple_occurrences(true), + ), ), ); assert!(utils::compare_output( @@ -1365,7 +1370,7 @@ fn sc_negates_reqs() { let app = App::new("prog") .version("1.0") .setting(AppSettings::SubcommandsNegateReqs) - .arg(Arg::from_usage("-o, --opt 'tests options'")) + .arg(arg!(-o --opt "tests options")) .arg(Arg::new("PATH").help("help")) .subcommand(App::new("test")); assert!(utils::compare_output( @@ -1380,8 +1385,8 @@ fn sc_negates_reqs() { fn hidden_args() { let app = App::new("prog") .version("1.0") - .arg(Arg::from_usage("-f, --flag 'testing flags'")) - .arg(Arg::from_usage("-o, --opt [FILE] 'tests options'")) + .arg(arg!(-f --flag "testing flags")) + .arg(arg!(-o --opt "tests options").required(false)) .arg(Arg::new("pos").hidden(true)); assert!(utils::compare_output( app, @@ -1396,8 +1401,8 @@ fn args_negate_sc() { let app = App::new("prog") .version("1.0") .setting(AppSettings::ArgsNegateSubcommands) - .arg(Arg::from_usage("-f, --flag 'testing flags'")) - .arg(Arg::from_usage("-o, --opt [FILE] 'tests options'")) + .arg(arg!(-f --flag "testing flags")) + .arg(arg!(-o --opt "tests options").required(false)) .arg(Arg::new("PATH").help("help")) .subcommand(App::new("test")); assert!(utils::compare_output( @@ -1412,8 +1417,8 @@ fn args_negate_sc() { fn issue_1046_hidden_scs() { let app = App::new("prog") .version("1.0") - .arg(Arg::from_usage("-f, --flag 'testing flags'")) - .arg(Arg::from_usage("-o, --opt [FILE] 'tests options'")) + .arg(arg!(-f --flag "testing flags")) + .arg(arg!(-o --opt "tests options").required(false)) .arg(Arg::new("PATH").help("some")) .subcommand(App::new("test").setting(AppSettings::Hidden)); assert!(utils::compare_output( @@ -1734,7 +1739,9 @@ fn issue_1052_require_delim_help() { .about("tests stuff") .version("1.3") .arg( - Arg::from_usage("-f, --fake 'some help'") + arg!(-f --fake "some help") + .required(true) + .value_names(&["some", "val"]) .takes_value(true) .use_delimiter(true) .require_delimiter(true) @@ -1756,7 +1763,9 @@ fn custom_headers_headers() { .about("does stuff") .version("1.4") .arg( - Arg::from_usage("-f, --fake 'some help'") + arg!(-f --fake "some help") + .required(true) + .value_names(&["some", "val"]) .takes_value(true) .use_delimiter(true) .require_delimiter(true) @@ -1813,7 +1822,9 @@ fn multiple_custom_help_headers() { .about("does stuff") .version("1.4") .arg( - Arg::from_usage("-f, --fake 'some help'") + arg!(-f --fake "some help") + .required(true) + .value_names(&["some", "val"]) .takes_value(true) .use_delimiter(true) .require_delimiter(true) @@ -1828,18 +1839,16 @@ fn multiple_custom_help_headers() { ) .help_heading(Some("SPECIAL")) .arg( - Arg::from_usage( - "-b, --birthday-song 'Change which song is played for birthdays'", - ) - .help_heading(Some("OVERRIDE SPECIAL")), + arg!(-b --"birthday-song" "Change which song is played for birthdays") + .help_heading(Some("OVERRIDE SPECIAL")), ) .arg( - Arg::from_usage("--style