mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
refactor: Port over to arg!
This commit is contained in:
parent
263fe30568
commit
4c4a2b86a0
43 changed files with 819 additions and 701 deletions
10
README.md
10
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. <kbknapp@gmail.com>")
|
||||
.about("Does awesome things")
|
||||
.arg(Arg::from_usage("-c, --config=[FILE] 'Sets a custom config file'"))
|
||||
.arg(Arg::from_usage("<INPUT> 'Sets the input file to use'"))
|
||||
.arg(Arg::from_usage("-v... 'Sets the level of verbosity'"))
|
||||
.arg(arg!(-c --config <FILE> "Sets a custom config file").required(false))
|
||||
.arg(arg!(<INPUT> "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. <someone_else@other.com>")
|
||||
.arg(Arg::from_usage("-d, --debug 'Print debug information'")))
|
||||
.arg(arg!(-d --debug "Print debug information")))
|
||||
.get_matches();
|
||||
|
||||
// Same as previous example...
|
||||
|
|
|
@ -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. <kbknapp@gmail.com>")
|
||||
.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 <opt> "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 <FILE> 'something'")))
|
||||
b.iter(|| App::new("claptests").arg(arg!(-s --some <FILE> "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 <FILE> 'something'");
|
||||
let arg = arg!(-s --some <FILE> "something");
|
||||
App::new("claptests").arg(&arg)
|
||||
})
|
||||
});
|
||||
|
|
|
@ -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. <kbknapp@gmail.com>")
|
||||
.arg(arg!(-o --option <opt> ... "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" <option2> "tests long options with exclusions")
|
||||
.required(false)
|
||||
.conflicts_with("option")
|
||||
.requires("positional2"),
|
||||
arg!([positional2] "tests positionals with exclusions"),
|
||||
arg!(-O --Option <option3> "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 <minvals> ... "Tests 2 min vals").min_values(2).multiple_values(true).required(false),
|
||||
arg!(--maxvals3 <maxvals> ... "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. <kbknapp@gmail.com>")
|
||||
.arg(arg!(-o --option <scoption> ... "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) {
|
||||
|
|
|
@ -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. <kbknapp@gmail.com>")
|
||||
.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... 'Turn debugging information on'"))
|
||||
.arg(
|
||||
arg!(
|
||||
-c --config <FILE> "Sets a custom config file"
|
||||
)
|
||||
.required(false),
|
||||
)
|
||||
.arg(arg!(<output> "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 <IFACE> "Set an interface to use"
|
||||
)
|
||||
.required(false),
|
||||
)
|
||||
}
|
||||
|
||||
fn app_example4<'c>() -> App<'c> {
|
||||
|
|
|
@ -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. <kbknapp@gmail.com>")
|
||||
.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 <FILE> "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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<Arg> 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 <IFACE> "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
|
||||
|
|
|
@ -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 <FILE> "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
|
||||
|
|
|
@ -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 <FILE> "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
|
||||
|
|
|
@ -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(
|
||||
"<seq>... '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!(
|
||||
<seq> ... "A sequence of whole positive numbers, i.e. 20 25 30"
|
||||
))
|
||||
.arg(
|
||||
arg!(
|
||||
l: -l <len> "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
|
||||
|
|
|
@ -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("<type> 'The type to use'")
|
||||
arg!(<type> "The type to use")
|
||||
// Define the list of possible values
|
||||
.possible_values(["Foo", "Bar", "Baz", "Qux"]),
|
||||
)
|
||||
|
|
|
@ -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" <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" <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(
|
||||
|
|
|
@ -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> 'input file to use'"))
|
||||
.arg(arg!(<input> "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"))
|
||||
|
|
|
@ -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 <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("<config> 'Required configuration file to use'")))
|
||||
/// .arg(arg!("<config> 'Required configuration file to use'")))
|
||||
/// # ;
|
||||
/// ```
|
||||
#[inline]
|
||||
|
|
|
@ -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 <FILE> "Sets a custom config file").required(false))
|
||||
/// .arg(arg!(-x --stuff <FILE> "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("<cmd>... 'commands to run'"))
|
||||
/// .arg(arg!(<cmd> ... "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("<cmd>... 'commands to run'"))
|
||||
/// .arg(arg!(<cmd> ... "commands to run"))
|
||||
/// .get_matches_from(vec!["myprog", "arg1", "-r", "val1"]);
|
||||
///
|
||||
/// let trail: Vec<&str> = m.values_of("cmd").unwrap().collect();
|
||||
|
|
|
@ -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 <FILE> "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 <val> "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 <val> ... "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"]);
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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" <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" <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))
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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("<arg> 'some arg'")
|
||||
/// .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("<arg> 'some arg'")
|
||||
/// .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("<arg>... 'some arg'")
|
||||
/// .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("<arg>... 'some arg'")
|
||||
/// .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("<arg> 'some arg'")
|
||||
/// .arg(arg!(<arg> "some arg")
|
||||
/// .allow_invalid_utf8(true))
|
||||
/// .get_matches_from(vec![OsString::from("myprog"),
|
||||
/// // "Hi {0xe9}!"
|
||||
|
|
|
@ -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 <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 <flag> "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("<arg1> 'some arg'"))
|
||||
.arg(Arg::from_usage("<arg2> 'some arg'"))
|
||||
.arg(arg!(<arg1> "some arg"))
|
||||
.arg(arg!(<arg2> "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("<arg1> 'some arg'"))
|
||||
.arg(Arg::from_usage("<arg2> 'some arg'"))
|
||||
.arg(arg!(<arg1> "some arg"))
|
||||
.arg(arg!(<arg2> "some arg"))
|
||||
.subcommand(
|
||||
App::new("sub1")
|
||||
.arg(Arg::from_usage("<arg> 'some'"))
|
||||
.arg(Arg::from_usage("<arg2> 'some'"))
|
||||
.arg(arg!(<arg> "some"))
|
||||
.arg(arg!(<arg2> "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("<dest> 'some file'"))
|
||||
.arg(arg!([src] "some file").default_value("src"))
|
||||
.arg(arg!(<dest> "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("<dest> 'some file'"))
|
||||
.arg(arg!([src] "some file"))
|
||||
.arg(arg!(<dest> "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("<BENCH2> 'some bench'"))
|
||||
.arg(Arg::from_usage("[ARGS]... 'some args'"))
|
||||
.arg(arg!([BENCH1] "some bench"))
|
||||
.arg(arg!(<BENCH2> "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" <val>))
|
||||
.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 <val> "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 <val> "some option").required(false))
|
||||
.arg(
|
||||
arg!(--other <val> "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 <val> "some option").required(true))
|
||||
.arg(
|
||||
arg!(--other <val> "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 <val> "some option")
|
||||
.required(false)
|
||||
.overrides_with("other"),
|
||||
)
|
||||
.arg(arg!(--other <val> "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 <val> "some option")
|
||||
.required(true)
|
||||
.overrides_with("other"),
|
||||
)
|
||||
.arg(arg!(--other <val> "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 <val> ... "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 <val> ... "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 <val> "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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 <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 <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!(
|
||||
|
|
|
@ -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"),
|
||||
)
|
||||
|
|
|
@ -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 <opt> "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 <opt> "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 <FILE> "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 <opt> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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")),
|
||||
|
|
38
tests/env.rs
38
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::<i32>()),
|
||||
|
@ -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| {
|
||||
|
|
|
@ -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"]);
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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 <global-str>")
|
||||
.required(false)
|
||||
.global(true),
|
||||
)
|
||||
.arg(arg!(--"global-flag").global(true))
|
||||
.arg(arg!(--"global-str" <str>).required(false).global(true))
|
||||
.subcommand(
|
||||
App::new("test")
|
||||
.arg(Arg::from_usage("--sub-flag").global(true))
|
||||
.arg(
|
||||
Arg::from_usage("--sub-str <sub-str>")
|
||||
.required(false)
|
||||
.global(true),
|
||||
)
|
||||
.arg(arg!(--"sub-flag").global(true))
|
||||
.arg(arg!(--"sub-str" <str>).required(false).global(true))
|
||||
.subcommand(App::new("test")),
|
||||
)
|
||||
.get_matches_from(&[
|
||||
|
|
|
@ -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:
|
||||
<base|--delete>
|
||||
|
@ -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 <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("<all> -a --all 'All'").conflicts_with("delete"))
|
||||
.arg(Arg::from_usage(
|
||||
"<delete> -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());
|
||||
|
|
|
@ -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. <kbknapp@gmail.com>")
|
||||
.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 <scoption> "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 <FILE> 'tests options'"))
|
||||
.arg(arg!(-o --opt <FILE> "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 <FILE> "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 <FILE> "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 <FILE> "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> <val> '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> <val> '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> <val> '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 <song> 'Change which song is played for birthdays'",
|
||||
)
|
||||
.help_heading(Some("OVERRIDE SPECIAL")),
|
||||
arg!(-b --"birthday-song" <song> "Change which song is played for birthdays")
|
||||
.help_heading(Some("OVERRIDE SPECIAL")),
|
||||
)
|
||||
.arg(
|
||||
Arg::from_usage("--style <style> 'Choose musical style to play the song'")
|
||||
arg!(--style <style> "Choose musical style to play the song")
|
||||
.required(false)
|
||||
.help_heading(None),
|
||||
)
|
||||
.arg(Arg::from_usage(
|
||||
"-v --birthday-song-volume <volume> 'Change the volume of the birthday song'",
|
||||
.arg(arg!(
|
||||
-v --"birthday-song-volume" <volume> "Change the volume of the birthday song"
|
||||
))
|
||||
.help_heading(None)
|
||||
.arg(
|
||||
|
@ -1903,11 +1912,11 @@ fn custom_help_headers_hidden_args() {
|
|||
)
|
||||
.help_heading(Some("SPECIAL"))
|
||||
.arg(
|
||||
Arg::from_usage("-b, --song <song> 'Change which song is played for birthdays'")
|
||||
arg!(-b --song <song> "Change which song is played for birthdays")
|
||||
.help_heading(Some("OVERRIDE SPECIAL")),
|
||||
)
|
||||
.arg(Arg::from_usage(
|
||||
"-v --song-volume <volume> 'Change the volume of the birthday song'",
|
||||
.arg(arg!(
|
||||
-v --"song-volume" <volume> "Change the volume of the birthday song"
|
||||
))
|
||||
.help_heading(None)
|
||||
.arg(
|
||||
|
@ -2396,7 +2405,7 @@ fn only_custom_heading_opts_no_args() {
|
|||
.setting(AppSettings::DisableVersionFlag)
|
||||
.mut_arg("help", |a| a.hidden(true))
|
||||
.help_heading(Some("NETWORKING"))
|
||||
.arg(Arg::from_usage("-s, --speed [SPEED] 'How fast'"));
|
||||
.arg(arg!(-s --speed <SPEED> "How fast").required(false));
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
mod utils;
|
||||
|
||||
use clap::{App, AppSettings, Arg};
|
||||
use clap::{arg, App, AppSettings, Arg};
|
||||
|
||||
static HIDDEN_ARGS: &str = "test 1.4
|
||||
|
||||
|
@ -25,9 +25,9 @@ fn hidden_args() {
|
|||
.about("tests stuff")
|
||||
.version("1.4")
|
||||
.args(&[
|
||||
Arg::from_usage("-f, --flag 'some flag'").hidden(true),
|
||||
Arg::from_usage("-F, --flag2 'some other flag'"),
|
||||
Arg::from_usage("--option [opt] 'some option'"),
|
||||
arg!(-f --flag "some flag").hidden(true),
|
||||
arg!(-F --flag2 "some other flag"),
|
||||
arg!(--option <opt> "some option").required(false),
|
||||
Arg::new("DUMMY").hidden(true),
|
||||
]);
|
||||
assert!(utils::compare_output(
|
||||
|
@ -285,7 +285,11 @@ fn hidden_opt_args_only() {
|
|||
.after_help("After help")
|
||||
.mut_arg("help", |a| a.hidden(true))
|
||||
.mut_arg("version", |a| a.hidden(true))
|
||||
.args(&[Arg::from_usage("--option [opt] 'some option'").hidden(true)]);
|
||||
.arg(
|
||||
arg!(--option <opt> "some option")
|
||||
.required(false)
|
||||
.hidden(true),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
use clap::{App, AppSettings, Arg};
|
||||
use clap::{arg, App, AppSettings, Arg};
|
||||
|
||||
#[test]
|
||||
fn single_short_arg_without_value() {
|
||||
let app = App::new("app")
|
||||
.setting(AppSettings::IgnoreErrors)
|
||||
.arg(Arg::from_usage(
|
||||
"-c, --config=[FILE] 'Sets a custom config file'",
|
||||
));
|
||||
let app = App::new("app").setting(AppSettings::IgnoreErrors).arg(arg!(
|
||||
-c --config [FILE] "Sets a custom config file"
|
||||
));
|
||||
|
||||
let r = app.try_get_matches_from(vec!["app", "-c" /* missing: , "config file" */]);
|
||||
|
||||
|
@ -17,11 +15,9 @@ fn single_short_arg_without_value() {
|
|||
|
||||
#[test]
|
||||
fn single_long_arg_without_value() {
|
||||
let app = App::new("app")
|
||||
.setting(AppSettings::IgnoreErrors)
|
||||
.arg(Arg::from_usage(
|
||||
"-c, --config=[FILE] 'Sets a custom config file'",
|
||||
));
|
||||
let app = App::new("app").setting(AppSettings::IgnoreErrors).arg(arg!(
|
||||
-c --config [FILE] "Sets a custom config file"
|
||||
));
|
||||
|
||||
let r = app.try_get_matches_from(vec!["app", "--config" /* missing: , "config file" */]);
|
||||
|
||||
|
@ -34,13 +30,13 @@ fn single_long_arg_without_value() {
|
|||
fn multiple_args_and_final_arg_without_value() {
|
||||
let app = App::new("app")
|
||||
.setting(AppSettings::IgnoreErrors)
|
||||
.arg(Arg::from_usage(
|
||||
"-c, --config=[FILE] 'Sets a custom config file'",
|
||||
.arg(arg!(
|
||||
-c --config [FILE] "Sets a custom config file"
|
||||
))
|
||||
.arg(Arg::from_usage(
|
||||
"-x, --stuff=[FILE] 'Sets a custom stuff file'",
|
||||
.arg(arg!(
|
||||
-x --stuff [FILE] "Sets a custom stuff file"
|
||||
))
|
||||
.arg(Arg::from_usage("-f 'Flag'"));
|
||||
.arg(arg!(f: -f "Flag"));
|
||||
|
||||
let r = app.try_get_matches_from(vec![
|
||||
"app", "-c", "file", "-f", "-x", /* missing: , "some stuff" */
|
||||
|
@ -57,13 +53,13 @@ fn multiple_args_and_final_arg_without_value() {
|
|||
fn multiple_args_and_intermittent_arg_without_value() {
|
||||
let app = App::new("app")
|
||||
.setting(AppSettings::IgnoreErrors)
|
||||
.arg(Arg::from_usage(
|
||||
"-c, --config=[FILE] 'Sets a custom config file'",
|
||||
.arg(arg!(
|
||||
-c --config[FILE] "Sets a custom config file"
|
||||
))
|
||||
.arg(Arg::from_usage(
|
||||
"-x, --stuff=[FILE] 'Sets a custom stuff file'",
|
||||
.arg(arg!(
|
||||
-x --stuff[FILE] "Sets a custom stuff file"
|
||||
))
|
||||
.arg(Arg::from_usage("-f 'Flag'"));
|
||||
.arg(arg!(f: -f "Flag"));
|
||||
|
||||
let r = app.try_get_matches_from(vec![
|
||||
"app", "-x", /* missing: ,"some stuff" */
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
use clap::{App, Arg, ArgSettings, ErrorKind};
|
||||
use clap::{arg, App, Arg, ArgSettings, ErrorKind};
|
||||
|
||||
#[test]
|
||||
fn multiple_occurrences_of_flags_long() {
|
||||
let m = App::new("mo_flags_long")
|
||||
.arg(
|
||||
Arg::from_usage("--multflag 'allowed multiple flag'")
|
||||
.setting(ArgSettings::MultipleOccurrences),
|
||||
)
|
||||
.arg(Arg::from_usage("--flag 'disallowed multiple flag'"))
|
||||
.arg(arg!(--multflag "allowed multiple flag").setting(ArgSettings::MultipleOccurrences))
|
||||
.arg(arg!(--flag "disallowed multiple flag"))
|
||||
.get_matches_from(vec!["", "--multflag", "--flag", "--multflag"]);
|
||||
assert!(m.is_present("multflag"));
|
||||
assert_eq!(m.occurrences_of("multflag"), 2);
|
||||
|
@ -18,11 +15,8 @@ fn multiple_occurrences_of_flags_long() {
|
|||
#[test]
|
||||
fn multiple_occurrences_of_flags_short() {
|
||||
let m = App::new("mo_flags_short")
|
||||
.arg(
|
||||
Arg::from_usage("-m --multflag 'allowed multiple flag'")
|
||||
.setting(ArgSettings::MultipleOccurrences),
|
||||
)
|
||||
.arg(Arg::from_usage("-f --flag 'disallowed multiple flag'"))
|
||||
.arg(arg!(-m --multflag "allowed multiple flag").setting(ArgSettings::MultipleOccurrences))
|
||||
.arg(arg!(-f --flag "disallowed multiple flag"))
|
||||
.get_matches_from(vec!["", "-m", "-f", "-m"]);
|
||||
assert!(m.is_present("multflag"));
|
||||
assert_eq!(m.occurrences_of("multflag"), 2);
|
||||
|
@ -33,15 +27,12 @@ fn multiple_occurrences_of_flags_short() {
|
|||
#[test]
|
||||
fn multiple_occurrences_of_flags_mixed() {
|
||||
let m = App::new("mo_flags_mixed")
|
||||
.arg(arg!(-m --multflag1 "allowed multiple flag").setting(ArgSettings::MultipleOccurrences))
|
||||
.arg(
|
||||
Arg::from_usage("-m, --multflag1 'allowed multiple flag'")
|
||||
arg!(-n --multflag2 "another allowed multiple flag")
|
||||
.setting(ArgSettings::MultipleOccurrences),
|
||||
)
|
||||
.arg(
|
||||
Arg::from_usage("-n, --multflag2 'another allowed multiple flag'")
|
||||
.setting(ArgSettings::MultipleOccurrences),
|
||||
)
|
||||
.arg(Arg::from_usage("-f, --flag 'disallowed multiple flag'"))
|
||||
.arg(arg!(-f --flag "disallowed multiple flag"))
|
||||
.get_matches_from(vec![
|
||||
"",
|
||||
"-m",
|
||||
|
@ -98,10 +89,7 @@ fn multiple_occurrences_of_flags_large_quantity() {
|
|||
.chain(vec!["-m"; 1024].into_iter())
|
||||
.collect();
|
||||
let m = App::new("mo_flags_large_qty")
|
||||
.arg(
|
||||
Arg::from_usage("-m --multflag 'allowed multiple flag'")
|
||||
.setting(ArgSettings::MultipleOccurrences),
|
||||
)
|
||||
.arg(arg!(-m --multflag "allowed multiple flag").setting(ArgSettings::MultipleOccurrences))
|
||||
.get_matches_from(args);
|
||||
assert!(m.is_present("multflag"));
|
||||
assert_eq!(m.occurrences_of("multflag"), 1024);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
mod utils;
|
||||
|
||||
use clap::{App, AppSettings, Arg, ArgMatches, ArgSettings, ErrorKind};
|
||||
use clap::{arg, App, AppSettings, Arg, ArgMatches, ArgSettings, ErrorKind};
|
||||
|
||||
#[cfg(feature = "suggestions")]
|
||||
static DYM: &str =
|
||||
|
@ -146,7 +146,7 @@ fn require_equals_pass() {
|
|||
#[test]
|
||||
fn stdin_char() {
|
||||
let r = App::new("opts")
|
||||
.arg(Arg::from_usage("-f [flag] 'some flag'"))
|
||||
.arg(arg!(f: -f [flag] "some flag"))
|
||||
.try_get_matches_from(vec!["", "-f", "-"]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -158,8 +158,8 @@ fn stdin_char() {
|
|||
fn opts_using_short() {
|
||||
let r = App::new("opts")
|
||||
.args(&[
|
||||
Arg::from_usage("-f [flag] 'some flag'"),
|
||||
Arg::from_usage("-c [color] 'some other flag'"),
|
||||
arg!(f: -f [flag] "some flag"),
|
||||
arg!(c: -c [color] "some other flag"),
|
||||
])
|
||||
.try_get_matches_from(vec!["", "-f", "some", "-c", "other"]);
|
||||
assert!(r.is_ok());
|
||||
|
@ -173,7 +173,7 @@ fn opts_using_short() {
|
|||
#[test]
|
||||
fn lots_o_vals() {
|
||||
let r = App::new("opts")
|
||||
.arg(Arg::from_usage("-o [opt]... 'some opt'"))
|
||||
.arg(arg!(o: -o <opt> "some opt").multiple_values(true))
|
||||
.try_get_matches_from(vec![
|
||||
"", "-o", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
||||
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
||||
|
@ -214,8 +214,8 @@ fn lots_o_vals() {
|
|||
fn opts_using_long_space() {
|
||||
let r = App::new("opts")
|
||||
.args(&[
|
||||
Arg::from_usage("--flag [flag] 'some flag'"),
|
||||
Arg::from_usage("--color [color] 'some other flag'"),
|
||||
arg!(--flag [flag] "some flag"),
|
||||
arg!(--color [color] "some other flag"),
|
||||
])
|
||||
.try_get_matches_from(vec!["", "--flag", "some", "--color", "other"]);
|
||||
assert!(r.is_ok());
|
||||
|
@ -230,8 +230,8 @@ fn opts_using_long_space() {
|
|||
fn opts_using_long_equals() {
|
||||
let r = App::new("opts")
|
||||
.args(&[
|
||||
Arg::from_usage("--flag [flag] 'some flag'"),
|
||||
Arg::from_usage("--color [color] 'some other flag'"),
|
||||
arg!(--flag [flag] "some flag"),
|
||||
arg!(--color [color] "some other flag"),
|
||||
])
|
||||
.try_get_matches_from(vec!["", "--flag=some", "--color=other"]);
|
||||
assert!(r.is_ok());
|
||||
|
@ -246,8 +246,8 @@ fn opts_using_long_equals() {
|
|||
fn opts_using_mixed() {
|
||||
let r = App::new("opts")
|
||||
.args(&[
|
||||
Arg::from_usage("-f, --flag [flag] 'some flag'"),
|
||||
Arg::from_usage("-c, --color [color] 'some other flag'"),
|
||||
arg!(-f --flag [flag] "some flag"),
|
||||
arg!(-c --color [color] "some other flag"),
|
||||
])
|
||||
.try_get_matches_from(vec!["", "-f", "some", "--color", "other"]);
|
||||
assert!(r.is_ok());
|
||||
|
@ -262,8 +262,8 @@ fn opts_using_mixed() {
|
|||
fn opts_using_mixed2() {
|
||||
let r = App::new("opts")
|
||||
.args(&[
|
||||
Arg::from_usage("-f, --flag [flag] 'some flag'"),
|
||||
Arg::from_usage("-c, --color [color] 'some other flag'"),
|
||||
arg!(-f --flag [flag] "some flag"),
|
||||
arg!(-c --color [color] "some other flag"),
|
||||
])
|
||||
.try_get_matches_from(vec!["", "--flag=some", "-c", "other"]);
|
||||
assert!(r.is_ok());
|
||||
|
@ -277,7 +277,7 @@ fn opts_using_mixed2() {
|
|||
#[test]
|
||||
fn default_values_user_value() {
|
||||
let r = App::new("df")
|
||||
.arg(Arg::from_usage("-o [opt] 'some opt'").default_value("default"))
|
||||
.arg(arg!(o: -o [opt] "some opt").default_value("default"))
|
||||
.try_get_matches_from(vec!["", "-o", "value"]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -288,8 +288,8 @@ fn default_values_user_value() {
|
|||
#[test]
|
||||
fn multiple_vals_pos_arg_equals() {
|
||||
let r = App::new("mvae")
|
||||
.arg(Arg::from_usage("-o [opt]... 'some opt'"))
|
||||
.arg(Arg::from_usage("[file] 'some file'"))
|
||||
.arg(arg!(o: -o [opt] ... "some opt"))
|
||||
.arg(arg!([file] "some file"))
|
||||
.try_get_matches_from(vec!["", "-o=1", "some"]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -302,8 +302,12 @@ fn multiple_vals_pos_arg_equals() {
|
|||
#[test]
|
||||
fn multiple_vals_pos_arg_delim() {
|
||||
let r = App::new("mvae")
|
||||
.arg(Arg::from_usage("-o [opt]... 'some opt'").setting(ArgSettings::UseValueDelimiter))
|
||||
.arg(Arg::from_usage("[file] 'some file'"))
|
||||
.arg(
|
||||
arg!(o: -o <opt> "some opt")
|
||||
.multiple_values(true)
|
||||
.setting(ArgSettings::UseValueDelimiter),
|
||||
)
|
||||
.arg(arg!([file] "some file"))
|
||||
.try_get_matches_from(vec!["", "-o", "1,2", "some"]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -317,11 +321,11 @@ fn multiple_vals_pos_arg_delim() {
|
|||
fn require_delims_no_delim() {
|
||||
let r = App::new("mvae")
|
||||
.arg(
|
||||
Arg::from_usage("-o [opt]... 'some opt'")
|
||||
arg!(o: -o [opt] ... "some opt")
|
||||
.setting(ArgSettings::UseValueDelimiter)
|
||||
.setting(ArgSettings::RequireDelimiter),
|
||||
)
|
||||
.arg(Arg::from_usage("[file] 'some file'"))
|
||||
.arg(arg!([file] "some file"))
|
||||
.try_get_matches_from(vec!["mvae", "-o", "1", "2", "some"]);
|
||||
assert!(r.is_err());
|
||||
let err = r.unwrap_err();
|
||||
|
@ -332,11 +336,12 @@ fn require_delims_no_delim() {
|
|||
fn require_delims() {
|
||||
let r = App::new("mvae")
|
||||
.arg(
|
||||
Arg::from_usage("-o [opt]... 'some opt'")
|
||||
arg!(o: -o <opt> "some opt")
|
||||
.multiple_values(true)
|
||||
.setting(ArgSettings::UseValueDelimiter)
|
||||
.setting(ArgSettings::RequireDelimiter),
|
||||
)
|
||||
.arg(Arg::from_usage("[file] 'some file'"))
|
||||
.arg(arg!([file] "some file"))
|
||||
.try_get_matches_from(vec!["", "-o", "1,2", "some"]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -349,7 +354,11 @@ fn require_delims() {
|
|||
#[test]
|
||||
fn leading_hyphen_pass() {
|
||||
let r = App::new("mvae")
|
||||
.arg(Arg::from_usage("-o [opt]... 'some opt'").setting(ArgSettings::AllowHyphenValues))
|
||||
.arg(
|
||||
arg!(o: -o <opt> "some opt")
|
||||
.multiple_values(true)
|
||||
.setting(ArgSettings::AllowHyphenValues),
|
||||
)
|
||||
.try_get_matches_from(vec!["", "-o", "-2", "3"]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -360,7 +369,7 @@ fn leading_hyphen_pass() {
|
|||
#[test]
|
||||
fn leading_hyphen_fail() {
|
||||
let r = App::new("mvae")
|
||||
.arg(Arg::from_usage("-o [opt] 'some opt'"))
|
||||
.arg(arg!(o: -o <opt> "some opt"))
|
||||
.try_get_matches_from(vec!["", "-o", "-2"]);
|
||||
assert!(r.is_err());
|
||||
let m = r.unwrap_err();
|
||||
|
@ -370,8 +379,12 @@ fn leading_hyphen_fail() {
|
|||
#[test]
|
||||
fn leading_hyphen_with_flag_after() {
|
||||
let r = App::new("mvae")
|
||||
.arg(Arg::from_usage("-o [opt]... 'some opt'").setting(ArgSettings::AllowHyphenValues))
|
||||
.arg(Arg::from_usage("-f 'some flag'"))
|
||||
.arg(
|
||||
arg!(o: -o <opt> "some opt")
|
||||
.multiple_values(true)
|
||||
.setting(ArgSettings::AllowHyphenValues),
|
||||
)
|
||||
.arg(arg!(f: -f "some flag"))
|
||||
.try_get_matches_from(vec!["", "-o", "-2", "-f"]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -383,8 +396,8 @@ fn leading_hyphen_with_flag_after() {
|
|||
#[test]
|
||||
fn leading_hyphen_with_flag_before() {
|
||||
let r = App::new("mvae")
|
||||
.arg(Arg::from_usage("-o [opt]... 'some opt'").setting(ArgSettings::AllowHyphenValues))
|
||||
.arg(Arg::from_usage("-f 'some flag'"))
|
||||
.arg(arg!(o: -o [opt] ... "some opt").setting(ArgSettings::AllowHyphenValues))
|
||||
.arg(arg!(f: -f "some flag"))
|
||||
.try_get_matches_from(vec!["", "-f", "-o", "-2"]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -397,12 +410,12 @@ fn leading_hyphen_with_flag_before() {
|
|||
fn leading_hyphen_with_only_pos_follows() {
|
||||
let r = App::new("mvae")
|
||||
.arg(
|
||||
Arg::from_usage("-o [opt]... 'some opt'")
|
||||
arg!(o: -o [opt] ... "some opt")
|
||||
.number_of_values(1)
|
||||
.setting(ArgSettings::TakesValue)
|
||||
.setting(ArgSettings::AllowHyphenValues),
|
||||
)
|
||||
.arg(Arg::from_usage("[arg] 'some arg'"))
|
||||
.arg(arg!([arg] "some arg"))
|
||||
.try_get_matches_from(vec!["", "-o", "-2", "--", "val"]);
|
||||
assert!(r.is_ok(), "{:?}", r);
|
||||
let m = r.unwrap();
|
||||
|
@ -424,6 +437,7 @@ fn did_you_mean() {
|
|||
|
||||
#[test]
|
||||
fn issue_665() {
|
||||
// Verify fix for "arg_from_usage(): required values not being enforced when followed by another option"
|
||||
let res = App::new("tester")
|
||||
.arg(Arg::from_usage("-v, --reroll-count=[N] 'Mark the patch series as PATCH vN'"))
|
||||
.arg(
|
||||
|
@ -455,8 +469,8 @@ fn issue_1047_min_zero_vals_default_val() {
|
|||
|
||||
fn issue_1105_setup(argv: Vec<&'static str>) -> Result<ArgMatches, clap::Error> {
|
||||
App::new("opts")
|
||||
.arg(Arg::from_usage("-o, --option [opt] 'some option'"))
|
||||
.arg(Arg::from_usage("--flag 'some flag'"))
|
||||
.arg(arg!(-o --option <opt> "some option"))
|
||||
.arg(arg!(--flag "some flag"))
|
||||
.try_get_matches_from(argv)
|
||||
}
|
||||
|
||||
|
@ -531,7 +545,7 @@ fn issue_1073_suboptimal_flag_suggestion() {
|
|||
#[test]
|
||||
fn short_non_ascii_no_space() {
|
||||
let matches = App::new("app")
|
||||
.arg(Arg::from_usage("<opt> -磨 <opt>"))
|
||||
.arg(arg!(opt: -'磨' <opt>))
|
||||
.get_matches_from(&["test", "-磨VALUE"]);
|
||||
|
||||
assert_eq!("VALUE", matches.value_of("opt").unwrap());
|
||||
|
@ -540,7 +554,7 @@ fn short_non_ascii_no_space() {
|
|||
#[test]
|
||||
fn short_eq_val_starts_with_eq() {
|
||||
let matches = App::new("app")
|
||||
.arg(Arg::from_usage("<opt> -f <opt>"))
|
||||
.arg(arg!(opt: -f <opt>))
|
||||
.get_matches_from(&["test", "-f==value"]);
|
||||
|
||||
assert_eq!("=value", matches.value_of("opt").unwrap());
|
||||
|
@ -549,7 +563,7 @@ fn short_eq_val_starts_with_eq() {
|
|||
#[test]
|
||||
fn long_eq_val_starts_with_eq() {
|
||||
let matches = App::new("app")
|
||||
.arg(Arg::from_usage("<opt> --foo <opt>"))
|
||||
.arg(arg!(opt: --foo <opt>))
|
||||
.get_matches_from(&["test", "--foo==value"]);
|
||||
|
||||
assert_eq!("=value", matches.value_of("opt").unwrap());
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
use clap::{App, Arg, ErrorKind};
|
||||
use clap::{arg, App, Arg, ErrorKind};
|
||||
|
||||
#[test]
|
||||
fn only_pos_follow() {
|
||||
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"]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -19,7 +16,7 @@ fn only_pos_follow() {
|
|||
fn issue_946() {
|
||||
let r = App::new("compiletest")
|
||||
.setting(clap::AppSettings::AllowLeadingHyphen)
|
||||
.arg(Arg::from_usage("--exact 'filters match exactly'"))
|
||||
.arg(arg!(--exact "filters match exactly"))
|
||||
.arg(
|
||||
clap::Arg::new("filter")
|
||||
.index(1)
|
||||
|
@ -37,10 +34,7 @@ fn issue_946() {
|
|||
#[test]
|
||||
fn positional() {
|
||||
let r = App::new("positional")
|
||||
.args(&[
|
||||
Arg::from_usage("-f, --flag 'some flag'"),
|
||||
Arg::new("positional").index(1),
|
||||
])
|
||||
.args(&[arg!(-f --flag "some flag"), Arg::new("positional").index(1)])
|
||||
.try_get_matches_from(vec!["", "-f", "test"]);
|
||||
assert!(r.is_ok(), "{:#?}", r);
|
||||
let m = r.unwrap();
|
||||
|
@ -49,10 +43,7 @@ fn positional() {
|
|||
assert_eq!(m.value_of("positional").unwrap(), "test");
|
||||
|
||||
let m = App::new("positional")
|
||||
.args(&[
|
||||
Arg::from_usage("-f, --flag 'some flag'"),
|
||||
Arg::new("positional").index(1),
|
||||
])
|
||||
.args(&[arg!(-f --flag "some flag"), Arg::new("positional").index(1)])
|
||||
.get_matches_from(vec!["", "test", "--flag"]);
|
||||
assert!(m.is_present("positional"));
|
||||
assert!(m.is_present("flag"));
|
||||
|
@ -62,7 +53,7 @@ fn positional() {
|
|||
#[test]
|
||||
fn lots_o_vals() {
|
||||
let r = App::new("opts")
|
||||
.arg(Arg::from_usage("[opt]... 'some pos'"))
|
||||
.arg(arg!(<opt>... "some pos"))
|
||||
.try_get_matches_from(vec![
|
||||
"", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
||||
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
|
||||
|
@ -103,7 +94,7 @@ fn lots_o_vals() {
|
|||
fn positional_multiple() {
|
||||
let r = App::new("positional_multiple")
|
||||
.args(&[
|
||||
Arg::from_usage("-f, --flag 'some flag'"),
|
||||
arg!(-f --flag "some flag"),
|
||||
Arg::new("positional")
|
||||
.index(1)
|
||||
.takes_value(true)
|
||||
|
@ -124,7 +115,7 @@ fn positional_multiple() {
|
|||
fn positional_multiple_3() {
|
||||
let r = App::new("positional_multiple")
|
||||
.args(&[
|
||||
Arg::from_usage("-f, --flag 'some flag'"),
|
||||
arg!(-f --flag "some flag"),
|
||||
Arg::new("positional")
|
||||
.index(1)
|
||||
.takes_value(true)
|
||||
|
@ -144,10 +135,7 @@ fn positional_multiple_3() {
|
|||
#[test]
|
||||
fn positional_multiple_2() {
|
||||
let result = App::new("positional_multiple")
|
||||
.args(&[
|
||||
Arg::from_usage("-f, --flag 'some flag'"),
|
||||
Arg::new("positional").index(1),
|
||||
])
|
||||
.args(&[arg!(-f --flag "some flag"), Arg::new("positional").index(1)])
|
||||
.try_get_matches_from(vec!["", "-f", "test1", "test2", "test3"]);
|
||||
assert!(result.is_err());
|
||||
let err = result.err().unwrap();
|
||||
|
@ -158,7 +146,7 @@ fn positional_multiple_2() {
|
|||
fn positional_possible_values() {
|
||||
let r = App::new("positional_possible_values")
|
||||
.args(&[
|
||||
Arg::from_usage("-f, --flag 'some flag'"),
|
||||
arg!(-f --flag "some flag"),
|
||||
Arg::new("positional").index(1).possible_value("test123"),
|
||||
])
|
||||
.try_get_matches_from(vec!["", "-f", "test123"]);
|
||||
|
@ -188,35 +176,35 @@ fn positional_hyphen_does_not_panic() {
|
|||
|
||||
#[test]
|
||||
fn single_positional_usage_string() {
|
||||
let mut app = App::new("test").arg(Arg::from_usage("[FILE] 'some file'"));
|
||||
let mut app = App::new("test").arg(arg!([FILE] "some file"));
|
||||
assert_eq!(app.render_usage(), "USAGE:\n test [FILE]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_positional_multiple_usage_string() {
|
||||
let mut app = App::new("test").arg(Arg::from_usage("[FILE]... 'some file'"));
|
||||
let mut app = App::new("test").arg(arg!([FILE]... "some file"));
|
||||
assert_eq!(app.render_usage(), "USAGE:\n test [FILE]...");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_positional_usage_string() {
|
||||
let mut app = App::new("test")
|
||||
.arg(Arg::from_usage("[FILE] 'some file'"))
|
||||
.arg(Arg::from_usage("[FILES]... 'some file'"));
|
||||
.arg(arg!([FILE] "some file"))
|
||||
.arg(arg!([FILES]... "some file"));
|
||||
assert_eq!(app.render_usage(), "USAGE:\n test [ARGS]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multiple_positional_one_required_usage_string() {
|
||||
let mut app = App::new("test")
|
||||
.arg(Arg::from_usage("<FILE> 'some file'"))
|
||||
.arg(Arg::from_usage("[FILES]... 'some file'"));
|
||||
.arg(arg!(<FILE> "some file"))
|
||||
.arg(arg!([FILES]... "some file"));
|
||||
assert_eq!(app.render_usage(), "USAGE:\n test <FILE> [FILES]...");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_positional_required_usage_string() {
|
||||
let mut app = App::new("test").arg(Arg::from_usage("<FILE> 'some file'"));
|
||||
let mut app = App::new("test").arg(arg!(<FILE> "some file"));
|
||||
assert_eq!(app.render_usage(), "USAGE:\n test <FILE>");
|
||||
}
|
||||
|
||||
|
@ -227,16 +215,16 @@ fn single_positional_required_usage_string() {
|
|||
with a lower index than a required positional argument"]
|
||||
fn missing_required() {
|
||||
let _ = App::new("test")
|
||||
.arg(Arg::from_usage("[FILE1] 'some file'"))
|
||||
.arg(Arg::from_usage("<FILE2> 'some file'"))
|
||||
.arg(arg!([FILE1] "some file"))
|
||||
.arg(arg!(<FILE2> "some file"))
|
||||
.try_get_matches_from(vec![""]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_required_2() {
|
||||
let r = App::new("test")
|
||||
.arg(Arg::from_usage("<FILE1> 'some file'"))
|
||||
.arg(Arg::from_usage("<FILE2> 'some file'"))
|
||||
.arg(arg!(<FILE1> "some file"))
|
||||
.arg(arg!(<FILE2> "some file"))
|
||||
.try_get_matches_from(vec!["test", "file"]);
|
||||
assert!(r.is_err());
|
||||
assert_eq!(r.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
|
||||
|
@ -245,9 +233,9 @@ fn missing_required_2() {
|
|||
#[test]
|
||||
fn last_positional() {
|
||||
let r = App::new("test")
|
||||
.arg(Arg::from_usage("<TARGET> 'some target'"))
|
||||
.arg(Arg::from_usage("[CORPUS] 'some corpus'"))
|
||||
.arg(Arg::from_usage("[ARGS]... 'some file'").last(true))
|
||||
.arg(arg!(<TARGET> "some target"))
|
||||
.arg(arg!([CORPUS] "some corpus"))
|
||||
.arg(arg!([ARGS]... "some file").last(true))
|
||||
.try_get_matches_from(vec!["test", "tgt", "--", "arg"]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -257,9 +245,9 @@ fn last_positional() {
|
|||
#[test]
|
||||
fn last_positional_no_double_dash() {
|
||||
let r = App::new("test")
|
||||
.arg(Arg::from_usage("<TARGET> 'some target'"))
|
||||
.arg(Arg::from_usage("[CORPUS] 'some corpus'"))
|
||||
.arg(Arg::from_usage("[ARGS]... 'some file'").last(true))
|
||||
.arg(arg!(<TARGET> "some target"))
|
||||
.arg(arg!([CORPUS] "some corpus"))
|
||||
.arg(arg!([ARGS]... "some file").last(true))
|
||||
.try_get_matches_from(vec!["test", "tgt", "crp", "arg"]);
|
||||
assert!(r.is_err());
|
||||
assert_eq!(r.unwrap_err().kind, ErrorKind::UnknownArgument);
|
||||
|
@ -268,9 +256,9 @@ fn last_positional_no_double_dash() {
|
|||
#[test]
|
||||
fn last_positional_second_to_last_mult() {
|
||||
let r = App::new("test")
|
||||
.arg(Arg::from_usage("<TARGET> 'some target'"))
|
||||
.arg(Arg::from_usage("[CORPUS]... 'some corpus'"))
|
||||
.arg(Arg::from_usage("[ARGS]... 'some file'").last(true))
|
||||
.arg(arg!(<TARGET> "some target"))
|
||||
.arg(arg!([CORPUS]... "some corpus"))
|
||||
.arg(arg!([ARGS]... "some file").last(true))
|
||||
.try_get_matches_from(vec!["test", "tgt", "crp1", "crp2", "--", "arg"]);
|
||||
assert!(r.is_ok(), "{:?}", r.unwrap_err().kind);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
use clap::{App, Arg, ErrorKind};
|
||||
use clap::{arg, App, Arg, ErrorKind};
|
||||
|
||||
#[test]
|
||||
fn flag_overrides_itself() {
|
||||
let res = App::new("posix")
|
||||
.arg(Arg::from_usage("--flag 'some flag'").overrides_with("flag"))
|
||||
.arg(
|
||||
arg!(--flag "some flag"
|
||||
)
|
||||
.overrides_with("flag"),
|
||||
)
|
||||
.try_get_matches_from(vec!["", "--flag", "--flag"]);
|
||||
assert!(res.is_ok());
|
||||
let m = res.unwrap();
|
||||
|
@ -14,7 +18,7 @@ fn flag_overrides_itself() {
|
|||
#[test]
|
||||
fn mult_flag_overrides_itself() {
|
||||
let res = App::new("posix")
|
||||
.arg(Arg::from_usage("--flag... 'some flag'").overrides_with("flag"))
|
||||
.arg(arg!(--flag ... "some flag").overrides_with("flag"))
|
||||
.try_get_matches_from(vec!["", "--flag", "--flag", "--flag", "--flag"]);
|
||||
assert!(res.is_ok());
|
||||
let m = res.unwrap();
|
||||
|
@ -25,7 +29,11 @@ fn mult_flag_overrides_itself() {
|
|||
#[test]
|
||||
fn option_overrides_itself() {
|
||||
let res = App::new("posix")
|
||||
.arg(Arg::from_usage("--opt [val] 'some option'").overrides_with("opt"))
|
||||
.arg(
|
||||
arg!(--opt <val> "some option")
|
||||
.required(false)
|
||||
.overrides_with("opt"),
|
||||
)
|
||||
.try_get_matches_from(vec!["", "--opt=some", "--opt=other"]);
|
||||
assert!(res.is_ok());
|
||||
let m = res.unwrap();
|
||||
|
@ -38,7 +46,8 @@ fn option_overrides_itself() {
|
|||
fn mult_option_require_delim_overrides_itself() {
|
||||
let res = App::new("posix")
|
||||
.arg(
|
||||
Arg::from_usage("--opt [val]... 'some option'")
|
||||
arg!(--opt <val> ... "some option")
|
||||
.required(false)
|
||||
.overrides_with("opt")
|
||||
.number_of_values(1)
|
||||
.takes_value(true)
|
||||
|
@ -59,7 +68,12 @@ fn mult_option_require_delim_overrides_itself() {
|
|||
#[test]
|
||||
fn mult_option_overrides_itself() {
|
||||
let res = App::new("posix")
|
||||
.arg(Arg::from_usage("--opt [val]... 'some option'").overrides_with("opt"))
|
||||
.arg(
|
||||
arg!(--opt <val> ... "some option")
|
||||
.required(false)
|
||||
.multiple_values(true)
|
||||
.overrides_with("opt"),
|
||||
)
|
||||
.try_get_matches_from(vec![
|
||||
"",
|
||||
"--opt",
|
||||
|
@ -83,7 +97,11 @@ fn mult_option_overrides_itself() {
|
|||
#[test]
|
||||
fn option_use_delim_false_override_itself() {
|
||||
let m = App::new("posix")
|
||||
.arg(Arg::from_usage("--opt [val] 'some option'").overrides_with("opt"))
|
||||
.arg(
|
||||
arg!(--opt <val> "some option")
|
||||
.required(false)
|
||||
.overrides_with("opt"),
|
||||
)
|
||||
.get_matches_from(vec!["", "--opt=some,other", "--opt=one,two"]);
|
||||
assert!(m.is_present("opt"));
|
||||
assert_eq!(m.occurrences_of("opt"), 1);
|
||||
|
@ -97,7 +115,7 @@ fn option_use_delim_false_override_itself() {
|
|||
fn pos_mult_overrides_itself() {
|
||||
// opts with multiple
|
||||
let res = App::new("posix")
|
||||
.arg(Arg::from_usage("[val]... 'some pos'").overrides_with("val"))
|
||||
.arg(arg!([val] ... "some pos").overrides_with("val"))
|
||||
.try_get_matches_from(vec!["", "some", "other", "value"]);
|
||||
assert!(res.is_ok());
|
||||
let m = res.unwrap();
|
||||
|
@ -111,8 +129,8 @@ fn pos_mult_overrides_itself() {
|
|||
#[test]
|
||||
fn posix_compatible_flags_long() {
|
||||
let m = App::new("posix")
|
||||
.arg(Arg::from_usage("--flag 'some flag'").overrides_with("color"))
|
||||
.arg(Arg::from_usage("--color 'some other flag'"))
|
||||
.arg(arg!(--flag "some flag").overrides_with("color"))
|
||||
.arg(arg!(--color "some other flag"))
|
||||
.get_matches_from(vec!["", "--flag", "--color"]);
|
||||
assert!(m.is_present("color"));
|
||||
assert!(!m.is_present("flag"));
|
||||
|
@ -121,8 +139,8 @@ fn posix_compatible_flags_long() {
|
|||
#[test]
|
||||
fn posix_compatible_flags_long_rev() {
|
||||
let m = App::new("posix")
|
||||
.arg(Arg::from_usage("--flag 'some flag'").overrides_with("color"))
|
||||
.arg(Arg::from_usage("--color 'some other flag'"))
|
||||
.arg(arg!(--flag "some flag").overrides_with("color"))
|
||||
.arg(arg!(--color "some other flag"))
|
||||
.get_matches_from(vec!["", "--color", "--flag"]);
|
||||
assert!(!m.is_present("color"));
|
||||
assert!(m.is_present("flag"));
|
||||
|
@ -131,8 +149,8 @@ fn posix_compatible_flags_long_rev() {
|
|||
#[test]
|
||||
fn posix_compatible_flags_short() {
|
||||
let m = App::new("posix")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").overrides_with("color"))
|
||||
.arg(Arg::from_usage("-c, --color 'some other flag'"))
|
||||
.arg(arg!(-f --flag "some flag").overrides_with("color"))
|
||||
.arg(arg!(-c --color "some other flag"))
|
||||
.get_matches_from(vec!["", "-f", "-c"]);
|
||||
assert!(m.is_present("color"));
|
||||
assert!(!m.is_present("flag"));
|
||||
|
@ -141,8 +159,8 @@ fn posix_compatible_flags_short() {
|
|||
#[test]
|
||||
fn posix_compatible_flags_short_rev() {
|
||||
let m = App::new("posix")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").overrides_with("color"))
|
||||
.arg(Arg::from_usage("-c, --color 'some other flag'"))
|
||||
.arg(arg!(-f --flag "some flag").overrides_with("color"))
|
||||
.arg(arg!(-c --color "some other flag"))
|
||||
.get_matches_from(vec!["", "-c", "-f"]);
|
||||
assert!(!m.is_present("color"));
|
||||
assert!(m.is_present("flag"));
|
||||
|
@ -151,8 +169,12 @@ fn posix_compatible_flags_short_rev() {
|
|||
#[test]
|
||||
fn posix_compatible_opts_long() {
|
||||
let m = App::new("posix")
|
||||
.arg(Arg::from_usage("--flag [flag] 'some flag'").overrides_with("color"))
|
||||
.arg(Arg::from_usage("--color [color] 'some other flag'"))
|
||||
.arg(
|
||||
arg!(--flag <flag> "some flag")
|
||||
.required(false)
|
||||
.overrides_with("color"),
|
||||
)
|
||||
.arg(arg!(--color <color> "some other flag").required(false))
|
||||
.get_matches_from(vec!["", "--flag", "some", "--color", "other"]);
|
||||
assert!(m.is_present("color"));
|
||||
assert_eq!(m.value_of("color").unwrap(), "other");
|
||||
|
@ -162,8 +184,12 @@ fn posix_compatible_opts_long() {
|
|||
#[test]
|
||||
fn posix_compatible_opts_long_rev() {
|
||||
let m = App::new("posix")
|
||||
.arg(Arg::from_usage("--flag [flag] 'some flag'").overrides_with("color"))
|
||||
.arg(Arg::from_usage("--color [color] 'some other flag'"))
|
||||
.arg(
|
||||
arg!(--flag <flag> "some flag")
|
||||
.required(false)
|
||||
.overrides_with("color"),
|
||||
)
|
||||
.arg(arg!(--color <color> "some other flag").required(false))
|
||||
.get_matches_from(vec!["", "--color", "some", "--flag", "other"]);
|
||||
assert!(!m.is_present("color"));
|
||||
assert!(m.is_present("flag"));
|
||||
|
@ -173,8 +199,12 @@ fn posix_compatible_opts_long_rev() {
|
|||
#[test]
|
||||
fn posix_compatible_opts_long_equals() {
|
||||
let m = App::new("posix")
|
||||
.arg(Arg::from_usage("--flag [flag] 'some flag'").overrides_with("color"))
|
||||
.arg(Arg::from_usage("--color [color] 'some other flag'"))
|
||||
.arg(
|
||||
arg!(--flag <flag> "some flag")
|
||||
.required(false)
|
||||
.overrides_with("color"),
|
||||
)
|
||||
.arg(arg!(--color <color> "some other flag").required(false))
|
||||
.get_matches_from(vec!["", "--flag=some", "--color=other"]);
|
||||
assert!(m.is_present("color"));
|
||||
assert_eq!(m.value_of("color").unwrap(), "other");
|
||||
|
@ -184,8 +214,12 @@ fn posix_compatible_opts_long_equals() {
|
|||
#[test]
|
||||
fn posix_compatible_opts_long_equals_rev() {
|
||||
let m = App::new("posix")
|
||||
.arg(Arg::from_usage("--flag [flag] 'some flag'").overrides_with("color"))
|
||||
.arg(Arg::from_usage("--color [color] 'some other flag'"))
|
||||
.arg(
|
||||
arg!(--flag <flag> "some flag")
|
||||
.required(false)
|
||||
.overrides_with("color"),
|
||||
)
|
||||
.arg(arg!(--color <color> "some other flag").required(false))
|
||||
.get_matches_from(vec!["", "--color=some", "--flag=other"]);
|
||||
assert!(!m.is_present("color"));
|
||||
assert!(m.is_present("flag"));
|
||||
|
@ -195,8 +229,12 @@ fn posix_compatible_opts_long_equals_rev() {
|
|||
#[test]
|
||||
fn posix_compatible_opts_short() {
|
||||
let m = App::new("posix")
|
||||
.arg(Arg::from_usage("-f [flag] 'some flag'").overrides_with("c"))
|
||||
.arg(Arg::from_usage("-c [color] 'some other flag'"))
|
||||
.arg(
|
||||
arg!(f: -f <flag> "some flag")
|
||||
.required(false)
|
||||
.overrides_with("c"),
|
||||
)
|
||||
.arg(arg!(c: -c <color> "some other flag").required(false))
|
||||
.get_matches_from(vec!["", "-f", "some", "-c", "other"]);
|
||||
assert!(m.is_present("c"));
|
||||
assert_eq!(m.value_of("c").unwrap(), "other");
|
||||
|
@ -206,8 +244,12 @@ fn posix_compatible_opts_short() {
|
|||
#[test]
|
||||
fn posix_compatible_opts_short_rev() {
|
||||
let m = App::new("posix")
|
||||
.arg(Arg::from_usage("-f [flag] 'some flag'").overrides_with("c"))
|
||||
.arg(Arg::from_usage("-c [color] 'some other flag'"))
|
||||
.arg(
|
||||
arg!(f: -f <flag> "some flag")
|
||||
.required(false)
|
||||
.overrides_with("c"),
|
||||
)
|
||||
.arg(arg!(c: -c <color> "some other flag").required(false))
|
||||
.get_matches_from(vec!["", "-c", "some", "-f", "other"]);
|
||||
assert!(!m.is_present("c"));
|
||||
assert!(m.is_present("f"));
|
||||
|
@ -217,9 +259,9 @@ fn posix_compatible_opts_short_rev() {
|
|||
#[test]
|
||||
fn conflict_overridden() {
|
||||
let m = App::new("conflict_overridden")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").conflicts_with("debug"))
|
||||
.arg(Arg::from_usage("-d, --debug 'other flag'"))
|
||||
.arg(Arg::from_usage("-c, --color 'third flag'").overrides_with("flag"))
|
||||
.arg(arg!(-f --flag "some flag").conflicts_with("debug"))
|
||||
.arg(arg!(-d --debug "other flag"))
|
||||
.arg(arg!(-c --color "third flag").overrides_with("flag"))
|
||||
.get_matches_from(vec!["", "-f", "-c", "-d"]);
|
||||
assert!(m.is_present("color"));
|
||||
assert!(!m.is_present("flag"));
|
||||
|
@ -229,9 +271,9 @@ fn conflict_overridden() {
|
|||
#[test]
|
||||
fn conflict_overridden_2() {
|
||||
let result = App::new("conflict_overridden")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").conflicts_with("debug"))
|
||||
.arg(Arg::from_usage("-d, --debug 'other flag'"))
|
||||
.arg(Arg::from_usage("-c, --color 'third flag'").overrides_with("flag"))
|
||||
.arg(arg!(-f --flag "some flag").conflicts_with("debug"))
|
||||
.arg(arg!(-d --debug "other flag"))
|
||||
.arg(arg!(-c --color "third flag").overrides_with("flag"))
|
||||
.try_get_matches_from(vec!["", "-f", "-d", "-c"]);
|
||||
assert!(result.is_ok());
|
||||
let m = result.unwrap();
|
||||
|
@ -243,9 +285,9 @@ fn conflict_overridden_2() {
|
|||
#[test]
|
||||
fn conflict_overridden_3() {
|
||||
let result = App::new("conflict_overridden")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").conflicts_with("debug"))
|
||||
.arg(Arg::from_usage("-d, --debug 'other flag'"))
|
||||
.arg(Arg::from_usage("-c, --color 'third flag'").overrides_with("flag"))
|
||||
.arg(arg!(-f --flag "some flag").conflicts_with("debug"))
|
||||
.arg(arg!(-d --debug "other flag"))
|
||||
.arg(arg!(-c --color "third flag").overrides_with("flag"))
|
||||
.try_get_matches_from(vec!["", "-d", "-c", "-f"]);
|
||||
assert!(result.is_err());
|
||||
let err = result.err().unwrap();
|
||||
|
@ -255,9 +297,9 @@ fn conflict_overridden_3() {
|
|||
#[test]
|
||||
fn conflict_overridden_4() {
|
||||
let m = App::new("conflict_overridden")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").conflicts_with("debug"))
|
||||
.arg(Arg::from_usage("-d, --debug 'other flag'"))
|
||||
.arg(Arg::from_usage("-c, --color 'third flag'").overrides_with("flag"))
|
||||
.arg(arg!(-f --flag "some flag").conflicts_with("debug"))
|
||||
.arg(arg!(-d --debug "other flag"))
|
||||
.arg(arg!(-c --color "third flag").overrides_with("flag"))
|
||||
.get_matches_from(vec!["", "-d", "-f", "-c"]);
|
||||
assert!(m.is_present("color"));
|
||||
assert!(!m.is_present("flag"));
|
||||
|
@ -268,7 +310,7 @@ fn conflict_overridden_4() {
|
|||
fn pos_required_overridden_by_flag() {
|
||||
let result = App::new("require_overridden")
|
||||
.arg(Arg::new("pos").index(1).required(true))
|
||||
.arg(Arg::from_usage("-c, --color 'some flag'").overrides_with("pos"))
|
||||
.arg(arg!(-c --color "some flag").overrides_with("pos"))
|
||||
.try_get_matches_from(vec!["", "test", "-c"]);
|
||||
assert!(result.is_ok(), "{:?}", result.unwrap_err());
|
||||
}
|
||||
|
@ -277,7 +319,7 @@ fn pos_required_overridden_by_flag() {
|
|||
fn require_overridden_2() {
|
||||
let m = App::new("require_overridden")
|
||||
.arg(Arg::new("req_pos").required(true))
|
||||
.arg(Arg::from_usage("-c, --color 'other flag'").overrides_with("req_pos"))
|
||||
.arg(arg!(-c --color "other flag").overrides_with("req_pos"))
|
||||
.get_matches_from(vec!["", "-c", "req_pos"]);
|
||||
assert!(!m.is_present("color"));
|
||||
assert!(m.is_present("req_pos"));
|
||||
|
@ -286,9 +328,9 @@ fn require_overridden_2() {
|
|||
#[test]
|
||||
fn require_overridden_3() {
|
||||
let m = App::new("require_overridden")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").requires("debug"))
|
||||
.arg(Arg::from_usage("-d, --debug 'other flag'"))
|
||||
.arg(Arg::from_usage("-c, --color 'third flag'").overrides_with("flag"))
|
||||
.arg(arg!(-f --flag "some flag").requires("debug"))
|
||||
.arg(arg!(-d --debug "other flag"))
|
||||
.arg(arg!(-c --color "third flag").overrides_with("flag"))
|
||||
.get_matches_from(vec!["", "-f", "-c"]);
|
||||
assert!(m.is_present("color"));
|
||||
assert!(!m.is_present("flag"));
|
||||
|
@ -298,9 +340,9 @@ fn require_overridden_3() {
|
|||
#[test]
|
||||
fn require_overridden_4() {
|
||||
let result = App::new("require_overridden")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").requires("debug"))
|
||||
.arg(Arg::from_usage("-d, --debug 'other flag'"))
|
||||
.arg(Arg::from_usage("-c, --color 'third flag'").overrides_with("flag"))
|
||||
.arg(arg!(-f --flag "some flag").requires("debug"))
|
||||
.arg(arg!(-d --debug "other flag"))
|
||||
.arg(arg!(-c --color "third flag").overrides_with("flag"))
|
||||
.try_get_matches_from(vec!["", "-c", "-f"]);
|
||||
assert!(result.is_err());
|
||||
let err = result.err().unwrap();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
mod utils;
|
||||
|
||||
use clap::{App, Arg, ArgGroup, ErrorKind};
|
||||
use clap::{arg, App, Arg, ArgGroup, ErrorKind};
|
||||
|
||||
static REQUIRE_EQUALS: &str = "error: The following required arguments were not provided:
|
||||
--opt=<FILE>
|
||||
|
@ -52,8 +52,8 @@ For more information try --help
|
|||
#[test]
|
||||
fn flag_required() {
|
||||
let result = App::new("flag_required")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").requires("color"))
|
||||
.arg(Arg::from_usage("-c, --color 'third flag'"))
|
||||
.arg(arg!(-f --flag "some flag").requires("color"))
|
||||
.arg(arg!(-c --color "third flag"))
|
||||
.try_get_matches_from(vec!["", "-f"]);
|
||||
assert!(result.is_err());
|
||||
let err = result.err().unwrap();
|
||||
|
@ -63,8 +63,8 @@ fn flag_required() {
|
|||
#[test]
|
||||
fn flag_required_2() {
|
||||
let m = App::new("flag_required")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").requires("color"))
|
||||
.arg(Arg::from_usage("-c, --color 'third flag'"))
|
||||
.arg(arg!(-f --flag "some flag").requires("color"))
|
||||
.arg(arg!(-c --color "third flag"))
|
||||
.get_matches_from(vec!["", "-f", "-c"]);
|
||||
assert!(m.is_present("color"));
|
||||
assert!(m.is_present("flag"));
|
||||
|
@ -73,8 +73,8 @@ fn flag_required_2() {
|
|||
#[test]
|
||||
fn option_required() {
|
||||
let result = App::new("option_required")
|
||||
.arg(Arg::from_usage("-f [flag] 'some flag'").requires("c"))
|
||||
.arg(Arg::from_usage("-c [color] 'third flag'"))
|
||||
.arg(arg!(f: -f <flag> "some flag").required(false).requires("c"))
|
||||
.arg(arg!(c: -c <color> "third flag").required(false))
|
||||
.try_get_matches_from(vec!["", "-f", "val"]);
|
||||
assert!(result.is_err());
|
||||
let err = result.err().unwrap();
|
||||
|
@ -84,8 +84,8 @@ fn option_required() {
|
|||
#[test]
|
||||
fn option_required_2() {
|
||||
let m = App::new("option_required")
|
||||
.arg(Arg::from_usage("-f [flag] 'some flag'").requires("c"))
|
||||
.arg(Arg::from_usage("-c [color] 'third flag'"))
|
||||
.arg(arg!(f: -f <flag> "some flag").required(false).requires("c"))
|
||||
.arg(arg!(c: -c <color> "third flag").required(false))
|
||||
.get_matches_from(vec!["", "-f", "val", "-c", "other_val"]);
|
||||
assert!(m.is_present("c"));
|
||||
assert_eq!(m.value_of("c").unwrap(), "other_val");
|
||||
|
@ -115,10 +115,10 @@ fn positional_required_2() {
|
|||
#[test]
|
||||
fn group_required() {
|
||||
let result = App::new("group_required")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'"))
|
||||
.arg(arg!(-f --flag "some flag"))
|
||||
.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!["", "-f"]);
|
||||
assert!(result.is_err());
|
||||
let err = result.err().unwrap();
|
||||
|
@ -128,10 +128,10 @@ fn group_required() {
|
|||
#[test]
|
||||
fn group_required_2() {
|
||||
let m = App::new("group_required")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'"))
|
||||
.arg(arg!(-f --flag "some flag"))
|
||||
.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"))
|
||||
.get_matches_from(vec!["", "-f", "--some"]);
|
||||
assert!(m.is_present("some"));
|
||||
assert!(!m.is_present("other"));
|
||||
|
@ -141,10 +141,10 @@ fn group_required_2() {
|
|||
#[test]
|
||||
fn group_required_3() {
|
||||
let m = App::new("group_required")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'"))
|
||||
.arg(arg!(-f --flag "some flag"))
|
||||
.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"))
|
||||
.get_matches_from(vec!["", "-f", "--other"]);
|
||||
assert!(!m.is_present("some"));
|
||||
assert!(m.is_present("other"));
|
||||
|
@ -154,10 +154,10 @@ fn group_required_3() {
|
|||
#[test]
|
||||
fn arg_require_group() {
|
||||
let result = App::new("arg_require_group")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").requires("gr"))
|
||||
.arg(arg!(-f --flag "some flag").requires("gr"))
|
||||
.group(ArgGroup::new("gr").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!["", "-f"]);
|
||||
assert!(result.is_err());
|
||||
let err = result.err().unwrap();
|
||||
|
@ -167,10 +167,10 @@ fn arg_require_group() {
|
|||
#[test]
|
||||
fn arg_require_group_2() {
|
||||
let res = App::new("arg_require_group")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").requires("gr"))
|
||||
.arg(arg!(-f --flag "some flag").requires("gr"))
|
||||
.group(ArgGroup::new("gr").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!["", "-f", "--some"]);
|
||||
assert!(res.is_ok());
|
||||
let m = res.unwrap();
|
||||
|
@ -182,10 +182,10 @@ fn arg_require_group_2() {
|
|||
#[test]
|
||||
fn arg_require_group_3() {
|
||||
let res = App::new("arg_require_group")
|
||||
.arg(Arg::from_usage("-f, --flag 'some flag'").requires("gr"))
|
||||
.arg(arg!(-f --flag "some flag").requires("gr"))
|
||||
.group(ArgGroup::new("gr").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!["", "-f", "--other"]);
|
||||
assert!(res.is_ok());
|
||||
let m = res.unwrap();
|
||||
|
@ -199,22 +199,25 @@ fn arg_require_group_3() {
|
|||
#[test]
|
||||
fn issue_753() {
|
||||
let m = App::new("test")
|
||||
.arg(Arg::from_usage(
|
||||
"-l, --list 'List available interfaces (and stop there)'",
|
||||
.arg(arg!(
|
||||
-l --list "List available interfaces (and stop there)"
|
||||
))
|
||||
.arg(
|
||||
Arg::from_usage(
|
||||
"-i, --iface=[INTERFACE] 'Ethernet interface for fetching NTP packets'",
|
||||
arg!(
|
||||
-i --iface <INTERFACE> "Ethernet interface for fetching NTP packets"
|
||||
)
|
||||
.required(false)
|
||||
.required_unless_present("list"),
|
||||
)
|
||||
.arg(
|
||||
Arg::from_usage("-f, --file=[TESTFILE] 'Fetch NTP packets from pcap file'")
|
||||
arg!(-f --file <TESTFILE> "Fetch NTP packets from pcap file")
|
||||
.required(false)
|
||||
.conflicts_with("iface")
|
||||
.required_unless_present("list"),
|
||||
)
|
||||
.arg(
|
||||
Arg::from_usage("-s, --server=[SERVER_IP] 'NTP server IP address'")
|
||||
arg!(-s --server <SERVER_IP> "NTP server IP address")
|
||||
.required(false)
|
||||
.required_unless_present("list"),
|
||||
)
|
||||
.try_get_matches_from(vec!["test", "--list"]);
|
||||
|
@ -927,19 +930,20 @@ For more information try --help
|
|||
fn issue_1158_app() -> App<'static> {
|
||||
App::new("example")
|
||||
.arg(
|
||||
Arg::from_usage("-c, --config [FILE] 'Custom config file.'")
|
||||
arg!(-c --config <FILE> "Custom config file.")
|
||||
.required(false)
|
||||
.required_unless_present("ID")
|
||||
.conflicts_with("ID"),
|
||||
)
|
||||
.arg(
|
||||
Arg::from_usage("[ID] 'ID'")
|
||||
arg!([ID] "ID")
|
||||
.required_unless_present("config")
|
||||
.conflicts_with("config")
|
||||
.requires_all(&["x", "y", "z"]),
|
||||
)
|
||||
.arg(Arg::from_usage("-x [X] 'X'"))
|
||||
.arg(Arg::from_usage("-y [Y] 'Y'"))
|
||||
.arg(Arg::from_usage("-z [Z] 'Z'"))
|
||||
.arg(arg!(x: -x <X> "X").required(false))
|
||||
.arg(arg!(y: -y <Y> "Y").required(false))
|
||||
.arg(arg!(z: -z <Z> "Z").required(false))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
mod utils;
|
||||
|
||||
use clap::{App, AppSettings, Arg, ErrorKind};
|
||||
use clap::{arg, App, AppSettings, Arg, ErrorKind};
|
||||
|
||||
static VISIBLE_ALIAS_HELP: &str = "clap-test 2.6
|
||||
|
||||
|
@ -251,8 +251,9 @@ USAGE:
|
|||
For more information try --help
|
||||
";
|
||||
|
||||
let app = App::new("dym")
|
||||
.subcommand(App::new("subcmd").arg(Arg::from_usage("-s --subcmdarg [subcmdarg] 'tests'")));
|
||||
let app = App::new("dym").subcommand(
|
||||
App::new("subcmd").arg(arg!(-s --subcmdarg <subcmdarg> "tests").required(false)),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
|
@ -276,8 +277,9 @@ USAGE:
|
|||
For more information try --help
|
||||
";
|
||||
|
||||
let app = App::new("dym")
|
||||
.subcommand(App::new("subcmd").arg(Arg::from_usage("-s --subcmdarg [subcmdarg] 'tests'")));
|
||||
let app = App::new("dym").subcommand(
|
||||
App::new("subcmd").arg(arg!(-s --subcmdarg <subcmdarg> "tests").required(false)),
|
||||
);
|
||||
|
||||
assert!(utils::compare_output(
|
||||
app,
|
||||
|
@ -344,7 +346,7 @@ fn replace() {
|
|||
#[test]
|
||||
fn issue_1031_args_with_same_name() {
|
||||
let res = App::new("prog")
|
||||
.arg(Arg::from_usage("--ui-path=<PATH>"))
|
||||
.arg(arg!(--"ui-path" <PATH>))
|
||||
.subcommand(App::new("signer"))
|
||||
.try_get_matches_from(vec!["prog", "--ui-path", "signer"]);
|
||||
|
||||
|
@ -356,7 +358,7 @@ fn issue_1031_args_with_same_name() {
|
|||
#[test]
|
||||
fn issue_1031_args_with_same_name_no_more_vals() {
|
||||
let res = App::new("prog")
|
||||
.arg(Arg::from_usage("--ui-path=<PATH>"))
|
||||
.arg(arg!(--"ui-path" <PATH>))
|
||||
.subcommand(App::new("signer"))
|
||||
.try_get_matches_from(vec!["prog", "--ui-path", "value", "signer"]);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
mod utils;
|
||||
|
||||
use clap::{App, Arg};
|
||||
use clap::{arg, App};
|
||||
|
||||
static EXAMPLE1_TMPL_S: &str = "{bin} {version}
|
||||
{author}
|
||||
|
@ -149,18 +149,21 @@ fn get_app() -> App<'static> {
|
|||
.version("1.0")
|
||||
.author("Kevin K. <kbknapp@gmail.com>")
|
||||
.about("Does awesome things")
|
||||
.arg(Arg::from_usage(
|
||||
"-c, --config=[FILE] 'Sets a custom config file'",
|
||||
.arg(
|
||||
arg!(
|
||||
-c --config <FILE> "Sets a custom config file"
|
||||
)
|
||||
.required(false),
|
||||
)
|
||||
.arg(arg!(
|
||||
<output> "Sets an optional output file"
|
||||
))
|
||||
.arg(Arg::from_usage(
|
||||
"<output> 'Sets an optional output file'",
|
||||
))
|
||||
.arg(Arg::from_usage(
|
||||
"-d... 'Turn debugging information on'",
|
||||
.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")),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#![cfg(windows)]
|
||||
|
||||
use clap::{App, Arg};
|
||||
use clap::{arg, App};
|
||||
use std::ffi::OsString;
|
||||
use std::os::windows::ffi::OsStringExt;
|
||||
|
||||
|
@ -23,7 +23,7 @@ fn bad_osstring(ascii: &[u8]) -> OsString {
|
|||
#[test]
|
||||
fn invalid_utf16_lossy_positional() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("<arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(<arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![OsString::from(""), bad_osstring(b"")]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -34,7 +34,7 @@ fn invalid_utf16_lossy_positional() {
|
|||
#[test]
|
||||
fn invalid_utf16_lossy_option_short_space() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(-a --arg <arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![
|
||||
OsString::from(""),
|
||||
OsString::from("-a"),
|
||||
|
@ -49,7 +49,7 @@ fn invalid_utf16_lossy_option_short_space() {
|
|||
#[test]
|
||||
fn invalid_utf16_lossy_option_short_equals() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(-a --arg <arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![OsString::from(""), bad_osstring(b"-a=")]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -60,7 +60,7 @@ fn invalid_utf16_lossy_option_short_equals() {
|
|||
#[test]
|
||||
fn invalid_utf16_lossy_option_short_no_space() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(-a --arg <arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![OsString::from(""), bad_osstring(b"-a")]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -71,7 +71,7 @@ fn invalid_utf16_lossy_option_short_no_space() {
|
|||
#[test]
|
||||
fn invalid_utf16_lossy_option_long_space() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(-a --arg <arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![
|
||||
OsString::from(""),
|
||||
OsString::from("--arg"),
|
||||
|
@ -86,7 +86,7 @@ fn invalid_utf16_lossy_option_long_space() {
|
|||
#[test]
|
||||
fn invalid_utf16_lossy_option_long_equals() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(-a --arg <arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![OsString::from(""), bad_osstring(b"--arg=")]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -97,7 +97,7 @@ fn invalid_utf16_lossy_option_long_equals() {
|
|||
#[test]
|
||||
fn invalid_utf16_positional() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("<arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(<arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![OsString::from(""), bad_osstring(b"")]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -108,7 +108,7 @@ fn invalid_utf16_positional() {
|
|||
#[test]
|
||||
fn invalid_utf16_option_short_space() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(-a --arg <arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![
|
||||
OsString::from(""),
|
||||
OsString::from("-a"),
|
||||
|
@ -123,7 +123,7 @@ fn invalid_utf16_option_short_space() {
|
|||
#[test]
|
||||
fn invalid_utf16_option_short_equals() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(-a --arg <arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![OsString::from(""), bad_osstring(b"-a=")]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -134,7 +134,7 @@ fn invalid_utf16_option_short_equals() {
|
|||
#[test]
|
||||
fn invalid_utf16_option_short_no_space() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(-a --arg <arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![OsString::from(""), bad_osstring(b"-a")]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
@ -145,7 +145,7 @@ fn invalid_utf16_option_short_no_space() {
|
|||
#[test]
|
||||
fn invalid_utf16_option_long_space() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(-a --arg <arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![
|
||||
OsString::from(""),
|
||||
OsString::from("--arg"),
|
||||
|
@ -160,7 +160,7 @@ fn invalid_utf16_option_long_space() {
|
|||
#[test]
|
||||
fn invalid_utf16_option_long_equals() {
|
||||
let r = App::new("bad_utf16")
|
||||
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'").allow_invalid_utf8(true))
|
||||
.arg(arg!(-a --arg <arg> "some arg").allow_invalid_utf8(true))
|
||||
.try_get_matches_from(vec![OsString::from(""), bad_osstring(b"--arg=")]);
|
||||
assert!(r.is_ok());
|
||||
let m = r.unwrap();
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::str;
|
|||
|
||||
use regex::Regex;
|
||||
|
||||
use clap::{App, Arg, ArgGroup};
|
||||
use clap::{arg, App, Arg, ArgGroup};
|
||||
|
||||
pub fn compare<S, S2>(l: S, r: S2) -> bool
|
||||
where
|
||||
|
@ -59,37 +59,53 @@ pub fn complex_app() -> App<'static> {
|
|||
.version("v1.4.8")
|
||||
.about("tests clap library")
|
||||
.author("Kevin K. <kbknapp@gmail.com>")
|
||||
.arg(Arg::from_usage(
|
||||
"[option] -o --option=[opt]... 'tests options'",
|
||||
))
|
||||
.arg(Arg::from_usage("[positional] 'tests positionals'"))
|
||||
.arg(Arg::from_usage("-f --flag... 'tests flags'").global(true))
|
||||
.arg(
|
||||
arg!(
|
||||
-o --option <opt> "tests options"
|
||||
)
|
||||
.required(false)
|
||||
.multiple_values(true)
|
||||
.multiple_occurrences(true),
|
||||
)
|
||||
.arg(arg!([positional] "tests positionals"))
|
||||
.arg(arg!(-f --flag ... "tests flags").global(true))
|
||||
.args(&[
|
||||
Arg::from_usage("[flag2] -F 'tests flags with exclusions'")
|
||||
arg!(flag2: -F "tests flags with exclusions")
|
||||
.conflicts_with("flag")
|
||||
.requires("long-option-2"),
|
||||
Arg::from_usage("--long-option-2 [option2] 'tests long options with exclusions'")
|
||||
arg!(--"long-option-2" <option2> "tests long options with exclusions")
|
||||
.required(false)
|
||||
.conflicts_with("option")
|
||||
.requires("positional2"),
|
||||
Arg::from_usage("[positional2] 'tests positionals with exclusions'"),
|
||||
Arg::from_usage("-O --option3 [option3] 'specific vals'").possible_values(opt3_vals),
|
||||
Arg::from_usage("[positional3]... 'tests specific values'").possible_values(pos3_vals),
|
||||
Arg::from_usage("--multvals [one] [two] 'Tests multiple values, not mult occs'"),
|
||||
Arg::from_usage("--multvalsmo... [one] [two] 'Tests multiple values, and mult occs'"),
|
||||
Arg::from_usage("--minvals2 [minvals]... 'Tests 2 min vals'").min_values(2),
|
||||
Arg::from_usage("--maxvals3 [maxvals]... 'Tests 3 max vals'").max_values(3),
|
||||
arg!([positional2] "tests positionals with exclusions"),
|
||||
arg!(-O --option3 <option3> "specific vals")
|
||||
.required(false)
|
||||
.possible_values(opt3_vals),
|
||||
arg!([positional3] ... "tests specific values").possible_values(pos3_vals),
|
||||
arg!(--multvals "Tests multiple values, not mult occs")
|
||||
.value_names(&["one", "two"])
|
||||
.required(false),
|
||||
arg!(--multvalsmo ... "Tests multiple values, and mult occs")
|
||||
.value_names(&["one", "two"])
|
||||
.required(false),
|
||||
arg!(--minvals2 <minvals> "Tests 2 min vals")
|
||||
.required(false)
|
||||
.min_values(2),
|
||||
arg!(--maxvals3 <maxvals> "Tests 3 max vals")
|
||||
.required(false)
|
||||
.max_values(3),
|
||||
])
|
||||
.subcommand(
|
||||
App::new("subcmd")
|
||||
.about("tests subcommands")
|
||||
.version("0.1")
|
||||
.author("Kevin K. <kbknapp@gmail.com>")
|
||||
.arg(Arg::from_usage(
|
||||
"[option] -o --option [scoption]... 'tests options'",
|
||||
))
|
||||
.arg(Arg::from_usage(
|
||||
"-s --subcmdarg [subcmdarg] 'tests other args'",
|
||||
))
|
||||
.arg(Arg::from_usage("[scpositional] 'tests positionals'")),
|
||||
.arg(
|
||||
arg!(-o --option <scoption> "tests options")
|
||||
.required(false)
|
||||
.multiple_values(true),
|
||||
)
|
||||
.arg(arg!(-s --subcmdarg <subcmdarg> "tests other args").required(false))
|
||||
.arg(arg!([scpositional] "tests positionals")),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue