replace Arg::from_usage by Arg::from

This commit is contained in:
Corentin Henry 2018-04-21 11:59:19 -07:00
parent 9981bac22a
commit 4f602b7e86
32 changed files with 439 additions and 435 deletions

View file

@ -26,7 +26,7 @@ fn build_app(b: &mut Bencher) { b.iter(|| create_app!()); }
fn add_flag(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> { App::new("claptests") }
b.iter(|| build_app().arg(Arg::from_usage("-s, --some 'something'")));
b.iter(|| build_app().arg(Arg::from("-s, --some 'something'")));
}
#[bench]
@ -34,7 +34,7 @@ fn add_flag_ref(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> { App::new("claptests") }
b.iter(|| {
let arg = Arg::from_usage("-s, --some 'something'");
let arg = Arg::from("-s, --some 'something'");
build_app().arg(&arg)
});
}
@ -43,7 +43,7 @@ fn add_flag_ref(b: &mut Bencher) {
fn add_opt(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> { App::new("claptests") }
b.iter(|| build_app().arg(Arg::from_usage("-s, --some <FILE> 'something'")));
b.iter(|| build_app().arg(Arg::from("-s, --some <FILE> 'something'")));
}
#[bench]
@ -51,7 +51,7 @@ fn add_opt_ref(b: &mut Bencher) {
fn build_app() -> App<'static, 'static> { App::new("claptests") }
b.iter(|| {
let arg = Arg::from_usage("-s, --some <FILE> 'something'");
let arg = Arg::from("-s, --some <FILE> 'something'");
build_app().arg(&arg)
});
}

View file

@ -20,18 +20,18 @@ macro_rules! create_app {
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
.args_from_usage(ARGS)
.arg(Arg::from_usage("-f --flag... 'tests flags'")
.arg(Arg::from("-f --flag... 'tests flags'")
.setting(ArgSettings::Global))
.args(&[
Arg::from_usage("[flag2] -F 'tests flags with exclusions'").conflicts_with("flag").requires("option2"),
Arg::from_usage("--long-option-2 [option2] 'tests long options with exclusions'").conflicts_with("option").requires("positional2"),
Arg::from_usage("[positional2] 'tests positionals with exclusions'"),
Arg::from_usage("-O --Option [option3] 'tests options with specific value sets'").possible_values(&OPT3_VALS),
Arg::from_usage("[positional3]... 'tests positionals with specific values'").possible_values(&POS3_VALS),
Arg::from_usage("--multvals [one] [two] 'Tests mutliple values, not mult occs'"),
Arg::from_usage("--multvalsmo... [one] [two] 'Tests mutliple values, not 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::from("[flag2] -F 'tests flags with exclusions'").conflicts_with("flag").requires("option2"),
Arg::from("--long-option-2 [option2] 'tests long options with exclusions'").conflicts_with("option").requires("positional2"),
Arg::from("[positional2] 'tests positionals with exclusions'"),
Arg::from("-O --Option [option3] 'tests options with specific value sets'").possible_values(&OPT3_VALS),
Arg::from("[positional3]... 'tests positionals with specific values'").possible_values(&POS3_VALS),
Arg::from("--multvals [one] [two] 'Tests mutliple values, not mult occs'"),
Arg::from("--multvalsmo... [one] [two] 'Tests mutliple values, not mult occs'"),
Arg::from("--minvals2 [minvals]... 'Tests 2 min vals'").min_values(2),
Arg::from("--maxvals3 [maxvals]... 'Tests 3 max vals'").max_values(3)
])
.subcommand(SubCommand::with_name("subcmd")
.about("tests subcommands")

View file

@ -64,18 +64,18 @@ mod test {
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
.args_from_usage(args)
.arg(Arg::from_usage("-f --flag... 'tests flags'")
.arg(Arg::from("-f --flag... 'tests flags'")
.global(true))
.args(&[
Arg::from_usage("[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'").conflicts_with("option").requires("positional2"),
Arg::from_usage("[positional2] 'tests positionals with exclusions'"),
Arg::from_usage("-O --Option [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 mutliple values, not mult occs'"),
Arg::from_usage("--multvalsmo... [one] [two] 'Tests mutliple 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::from("[flag2] -F 'tests flags with exclusions'").conflicts_with("flag").requires("long-option-2"),
Arg::from("--long-option-2 [option2] 'tests long options with exclusions'").conflicts_with("option").requires("positional2"),
Arg::from("[positional2] 'tests positionals with exclusions'"),
Arg::from("-O --Option [option3] 'specific vals'").possible_values(&opt3_vals),
Arg::from("[positional3]... 'tests specific values'").possible_values(&pos3_vals),
Arg::from("--multvals [one] [two] 'Tests mutliple values, not mult occs'"),
Arg::from("--multvalsmo... [one] [two] 'Tests mutliple values, and mult occs'"),
Arg::from("--minvals2 [minvals]... 'Tests 2 min vals'").min_values(2),
Arg::from("--maxvals3 [maxvals]... 'Tests 3 max vals'").max_values(3)
])
.subcommand(SubCommand::with_name("subcmd")
.about("tests subcommands")

View file

@ -8,7 +8,7 @@ fn main() {
//
// The example below is functionally identical to the 01a_quick_example.rs and 01c_quick_example.rs
//
// *NOTE:* You can actually achieve the best of both worlds by using Arg::from_usage() (instead of Arg::with_name())
// *NOTE:* You can actually achieve the best of both worlds by using Arg::from() (instead of Arg::with_name())
// and *then* setting any additional properties.
//
// Create an application with 5 possible arguments (2 auto generated) and 2 subcommands (1 auto generated)

View file

@ -49,7 +49,7 @@ fn main() {
// *Note* the following two examples are convenience methods, if you wish
// to still get the full configurability of Arg::with_name() and the readability
// of arg_from_usage(), you can instantiate a new Arg with Arg::from_usage() and
// of arg_from_usage(), you can instantiate a new Arg with Arg::from() and
// still be able to set all the additional properties, just like Arg::with_name()
//
//

View file

@ -41,9 +41,9 @@ fn main() {
let enum_vals = ["fast", "slow"];
let m = App::new("myapp")
// Use a single positional argument that is required
.arg(Arg::from_usage("<foo> 'The Foo to use'")
.arg(Arg::from("<foo> 'The Foo to use'")
.possible_values(&Foo::variants()))
.arg(Arg::from_usage("<speed> 'The speed to use'")
.arg(Arg::from("<speed> 'The speed to use'")
// You can define a list of possible values if you want the values to be
// displayed in the help information. Whether you use possible_values() or
// not, the valid values will ALWAYS be displayed on a failed parse.

View file

@ -37,7 +37,7 @@ fn main() {
// Create the application like normal
let m = App::new("myapp")
// Use a single positional argument that is required
.arg(Arg::from_usage("<type> 'The type to use'")
.arg(Arg::from("<type> 'The type to use'")
// Define the list of possible values
.possible_values(&["Foo", "Bar", "Baz", "Qux"]))
.get_matches();

View file

@ -38,9 +38,9 @@ fn main() {
.args(&["ver", "major", "minor", "patch"]))
// 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'")
.arg(Arg::from("[INPUT_FILE] 'some regular input'")
.group("input"))
.arg(Arg::from_usage("--spec-in [SPEC_IN] 'some special input argument'")
.arg(Arg::from("--spec-in [SPEC_IN] 'some special input argument'")
.group("input"))
// Now let's assume we have a -c [config] argument which requires one of
// (but **not** both) the "input" arguments

View file

@ -628,9 +628,9 @@ impl<'a, 'b> App<'a, 'b> {
/// .help("turns on debugging mode")
/// )
/// // Adding a single "option" argument with a short, a long, and help text using the less
/// // verbose Arg::from_usage()
/// // verbose Arg::from()
/// .arg(
/// Arg::from_usage("-c --config=[CONFIG] 'Optionally sets a config file to use'")
/// Arg::from("-c --config=[CONFIG] 'Optionally sets a config file to use'")
/// )
/// # ;
/// ```
@ -668,7 +668,7 @@ impl<'a, 'b> App<'a, 'b> {
/// # use clap::{App, Arg};
/// App::new("myprog")
/// .args(&[
/// Arg::from_usage("[debug] -d 'turns on debugging info'"),
/// Arg::from("[debug] -d 'turns on debugging info'"),
/// Arg::with_name("input").index(1).help("the input file to use")
/// ])
/// # ;
@ -1862,7 +1862,7 @@ impl<'a, 'b> App<'a, 'b> {
/// **Deprecated:** Use
#[deprecated(since="2.30.0", note="Use `App::arg(Arg::from(&str)` instead. Will be removed in v3.0-beta")]
pub fn arg_from_usage(mut self, usage: &'a str) -> Self {
self.args.push(Arg::from_usage(usage));
self.args.push(Arg::from(usage));
self
}
@ -1874,7 +1874,7 @@ impl<'a, 'b> App<'a, 'b> {
if l.is_empty() {
continue;
}
self.args.push(Arg::from_usage(l));
self.args.push(Arg::from(l));
}
self
}

View file

@ -655,7 +655,7 @@ pub enum AppSettings {
/// # use clap::{App, Arg, AppSettings};
/// let m = App::new("myprog")
/// .setting(AppSettings::NoBinaryName)
/// .arg(Arg::from_usage("<cmd>... 'commands to run'"))
/// .arg(Arg::from("<cmd>... 'commands to run'"))
/// .get_matches_from(vec!["command", "set"]);
///
/// let cmds: Vec<&str> = m.values_of("cmd").unwrap().collect();
@ -686,7 +686,7 @@ pub enum AppSettings {
/// ```rust
/// # use clap::{App, Arg, AppSettings, SubCommand};
/// let m = App::new("myprog")
/// .arg(Arg::from_usage("[cmd] 'command to run'")
/// .arg(Arg::from("[cmd] 'command to run'")
/// .global(true))
/// .subcommand(SubCommand::with_name("foo"))
/// .get_matches_from(vec!["myprog", "set", "foo"]);
@ -702,7 +702,7 @@ pub enum AppSettings {
/// ```rust
/// # use clap::{App, Arg, AppSettings, SubCommand};
/// let m = App::new("myprog")
/// .arg(Arg::from_usage("[cmd] 'command to run'")
/// .arg(Arg::from("[cmd] 'command to run'")
/// .global(true))
/// .subcommand(SubCommand::with_name("foo"))
/// .get_matches_from(vec!["myprog", "set"]);
@ -851,7 +851,7 @@ pub enum AppSettings {
/// # use clap::{App, Arg, AppSettings};
/// let m = App::new("myprog")
/// .setting(AppSettings::TrailingVarArg)
/// .arg(Arg::from_usage("<cmd>... 'commands to run'"))
/// .arg(Arg::from("<cmd>... 'commands to run'"))
/// .get_matches_from(vec!["myprog", "arg1", "-r", "val1"]);
///
/// let trail: Vec<&str> = m.values_of("cmd").unwrap().collect();

View file

@ -39,7 +39,7 @@ use INTERNAL_ERROR_MSG;
/// .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::from("-i, --input=[FILE] 'Provides an input file to the program'");
/// ```
/// [`Arg`]: ./struct.Arg.html
#[allow(missing_debug_implementations)]
@ -867,13 +867,13 @@ impl<'a, 'b> Arg<'a, 'b> {
///
/// # Examples
///
/// ```rust
/// ```rust # use clap::{App, Arg};
/// # use clap::{App, Arg};
/// let m = App::new("prog")
/// .arg(Arg::from_usage("-f, --flag 'some flag'")
/// .arg(Arg::from("-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::from("-d, --debug 'other flag'"))
/// .arg(Arg::from("-c, --color 'third flag'")
/// .overrides_with("flag"))
/// .get_matches_from(vec![
/// "prog", "-f", "-d", "-c"]);
@ -895,7 +895,7 @@ impl<'a, 'b> Arg<'a, 'b> {
/// ```rust
/// # use clap::{App, Arg};
/// let m = App::new("posix")
/// .arg(Arg::from_usage("--flag 'some flag'").overrides_with("flag"))
/// .arg(Arg::from("--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);
@ -906,7 +906,7 @@ impl<'a, 'b> Arg<'a, 'b> {
/// ```
/// # use clap::{App, Arg};
/// let m = App::new("posix")
/// .arg(Arg::from_usage("--flag... 'some flag'").overrides_with("flag"))
/// .arg(Arg::from("--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);
@ -917,7 +917,7 @@ impl<'a, 'b> Arg<'a, 'b> {
/// ```
/// # use clap::{App, Arg};
/// let m = App::new("posix")
/// .arg(Arg::from_usage("--opt [val] 'some option'").overrides_with("opt"))
/// .arg(Arg::from("--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);
@ -930,7 +930,7 @@ impl<'a, 'b> Arg<'a, 'b> {
/// ```
/// # use clap::{App, Arg};
/// let m = App::new("posix")
/// .arg(Arg::from_usage("--opt [val]... 'some option'")
/// .arg(Arg::from("--opt [val]... 'some option'")
/// .overrides_with("opt"))
/// .get_matches_from(vec!["", "--opt", "first", "over", "--opt", "other", "val"]);
/// assert!(m.is_present("opt"));
@ -945,7 +945,7 @@ impl<'a, 'b> Arg<'a, 'b> {
/// ```
/// # use clap::{App, Arg};
/// let m = App::new("posix")
/// .arg(Arg::from_usage("--opt [val] 'some option'")
/// .arg(Arg::from("--opt [val] 'some option'")
/// .overrides_with("opt"))
/// .get_matches_from(vec!["", "--opt=some,other", "--opt=one,two"]);
/// assert!(m.is_present("opt"));
@ -975,10 +975,10 @@ impl<'a, 'b> Arg<'a, 'b> {
/// ```rust
/// # use clap::{App, Arg};
/// let m = App::new("prog")
/// .arg(Arg::from_usage("-f, --flag 'some flag'")
/// .arg(Arg::from("-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::from("-d, --debug 'other flag'"))
/// .arg(Arg::from("-c, --color 'third flag'")
/// .overrides_with_all(&["flag", "debug"]))
/// .get_matches_from(vec![
/// "prog", "-f", "-d", "-c"]);
@ -4074,6 +4074,10 @@ impl<'a, 'b, 'z> From<&'z Arg<'a, 'b>> for Arg<'a, 'b> {
fn from(a: &'z Arg<'a, 'b>) -> Self { a.clone() }
}
impl<'a, 'b> From<&'a str> for Arg<'a, 'b> {
fn from(s: &'a str) -> Self { Self::from_usage(s) }
}
impl<'n, 'e> PartialEq for Arg<'n, 'e> {
fn eq(&self, other: &Arg<'n, 'e>) -> bool { self.name == other.name }
}

View file

@ -139,7 +139,7 @@ impl<'a> ArgMatches<'a> {
/// use std::os::unix::ffi::{OsStrExt,OsStringExt};
///
/// let m = App::new("utf8")
/// .arg(Arg::from_usage("<arg> 'some arg'"))
/// .arg(Arg::from("<arg> 'some arg'"))
/// .get_matches_from(vec![OsString::from("myprog"),
/// // "Hi {0xe9}!"
/// OsString::from_vec(vec![b'H', b'i', b' ', 0xe9, b'!'])]);
@ -174,7 +174,7 @@ impl<'a> ArgMatches<'a> {
/// use std::os::unix::ffi::{OsStrExt,OsStringExt};
///
/// let m = App::new("utf8")
/// .arg(Arg::from_usage("<arg> 'some arg'"))
/// .arg(Arg::from("<arg> 'some arg'"))
/// .get_matches_from(vec![OsString::from("myprog"),
/// // "Hi {0xe9}!"
/// OsString::from_vec(vec![b'H', b'i', b' ', 0xe9, b'!'])]);
@ -237,7 +237,7 @@ impl<'a> ArgMatches<'a> {
/// use std::os::unix::ffi::OsStringExt;
///
/// let m = App::new("utf8")
/// .arg(Arg::from_usage("<arg>... 'some arg'"))
/// .arg(Arg::from("<arg>... 'some arg'"))
/// .get_matches_from(vec![OsString::from("myprog"),
/// // "Hi"
/// OsString::from_vec(vec![b'H', b'i']),
@ -275,7 +275,7 @@ impl<'a> ArgMatches<'a> {
/// use std::os::unix::ffi::{OsStrExt,OsStringExt};
///
/// let m = App::new("utf8")
/// .arg(Arg::from_usage("<arg>... 'some arg'"))
/// .arg(Arg::from("<arg>... 'some arg'"))
/// .get_matches_from(vec![OsString::from("myprog"),
/// // "Hi"
/// OsString::from_vec(vec![b'H', b'i']),
@ -834,7 +834,7 @@ impl<'a> Default for Values<'a> {
/// use std::os::unix::ffi::{OsStrExt,OsStringExt};
///
/// let m = App::new("utf8")
/// .arg(Arg::from_usage("<arg> 'some arg'"))
/// .arg(Arg::from("<arg> 'some arg'"))
/// .get_matches_from(vec![OsString::from("myprog"),
/// // "Hi {0xe9}!"
/// OsString::from_vec(vec![b'H', b'i', b' ', 0xe9, b'!'])]);

View file

@ -45,7 +45,7 @@ pub enum ErrorKind {
/// ```rust
/// # use clap::{App, Arg, ErrorKind};
/// let result = App::new("prog")
/// .arg(Arg::from_usage("--flag 'some flag'"))
/// .arg(Arg::from("--flag 'some flag'"))
/// .get_matches_from_safe(vec!["prog", "--other"]);
/// assert!(result.is_err());
/// assert_eq!(result.unwrap_err().kind, ErrorKind::UnknownArgument);

View file

@ -287,7 +287,7 @@ macro_rules! _clap_count_exprs {
/// // and implements std::str::FromStr to use with the value_t! macros
/// fn main() {
/// let m = App::new("app")
/// .arg(Arg::from_usage("<foo> 'the foo'")
/// .arg(Arg::from("<foo> 'the foo'")
/// .possible_values(&Foo::variants())
/// .case_insensitive(true))
/// .get_matches_from(vec![

View file

@ -221,7 +221,7 @@ mod test {
#[test]
fn create_flag_usage() {
let a = Arg::from_usage("[flag] -f 'some help info'");
let a = Arg::from("[flag] -f 'some help info'");
assert_eq!(a.name, "flag");
assert_eq!(a.short.unwrap(), 'f');
assert!(a.long.is_none());
@ -230,7 +230,7 @@ mod test {
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("[flag] --flag 'some help info'");
let a = Arg::from("[flag] --flag 'some help info'");
assert_eq!(a.name, "flag");
assert_eq!(a.long.unwrap(), "flag");
assert!(a.short.is_none());
@ -239,7 +239,7 @@ mod test {
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("--flag 'some help info'");
let a = Arg::from("--flag 'some help info'");
assert_eq!(a.name, "flag");
assert_eq!(a.long.unwrap(), "flag");
assert!(a.short.is_none());
@ -248,7 +248,7 @@ mod test {
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("[flag] -f --flag 'some help info'");
let a = Arg::from("[flag] -f --flag 'some help info'");
assert_eq!(a.name, "flag");
assert_eq!(a.short.unwrap(), 'f');
assert_eq!(a.long.unwrap(), "flag");
@ -257,7 +257,7 @@ mod test {
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("[flag] -f... 'some help info'");
let a = Arg::from("[flag] -f... 'some help info'");
assert_eq!(a.name, "flag");
assert_eq!(a.short.unwrap(), 'f');
assert!(a.long.is_none());
@ -266,7 +266,7 @@ mod test {
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("[flag] -f --flag... 'some help info'");
let a = Arg::from("[flag] -f --flag... 'some help info'");
assert_eq!(a.name, "flag");
assert_eq!(a.long.unwrap(), "flag");
assert_eq!(a.short.unwrap(), 'f');
@ -275,7 +275,7 @@ mod test {
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("-f --flag... 'some help info'");
let a = Arg::from("-f --flag... 'some help info'");
assert_eq!(a.name, "flag");
assert_eq!(a.long.unwrap(), "flag");
assert_eq!(a.short.unwrap(), 'f');
@ -284,33 +284,33 @@ mod test {
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("--flags");
let a = Arg::from("--flags");
assert_eq!(a.name, "flags");
assert_eq!(a.long.unwrap(), "flags");
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("--flags...");
let a = Arg::from("--flags...");
assert_eq!(a.name, "flags");
assert_eq!(a.long.unwrap(), "flags");
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("[flags] -f");
let a = Arg::from("[flags] -f");
assert_eq!(a.name, "flags");
assert_eq!(a.short.unwrap(), 'f');
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("[flags] -f...");
let a = Arg::from("[flags] -f...");
assert_eq!(a.name, "flags");
assert_eq!(a.short.unwrap(), 'f');
assert!(a.is_set(ArgSettings::MultipleOccurrences));
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("-f 'some help info'");
let a = Arg::from("-f 'some help info'");
assert_eq!(a.name, "f");
assert_eq!(a.short.unwrap(), 'f');
assert!(a.long.is_none());
@ -319,13 +319,13 @@ mod test {
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("-f");
let a = Arg::from("-f");
assert_eq!(a.name, "f");
assert_eq!(a.short.unwrap(), 'f');
assert!(a.val_names.is_none());
assert!(a.num_vals.is_none());
let a = Arg::from_usage("-f...");
let a = Arg::from("-f...");
assert_eq!(a.name, "f");
assert_eq!(a.short.unwrap(), 'f');
assert!(a.is_set(ArgSettings::MultipleOccurrences));
@ -336,7 +336,7 @@ mod test {
#[test]
fn create_option_usage0() {
// Short only
let a = Arg::from_usage("[option] -o [opt] 'some help info'");
let a = Arg::from("[option] -o [opt] 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.short.unwrap(), 'o');
assert!(a.long.is_none());
@ -351,7 +351,7 @@ mod test {
#[test]
fn create_option_usage1() {
let a = Arg::from_usage("-o [opt] 'some help info'");
let a = Arg::from("-o [opt] 'some help info'");
assert_eq!(a.name, "o");
assert_eq!(a.short.unwrap(), 'o');
assert!(a.long.is_none());
@ -366,7 +366,7 @@ mod test {
#[test]
fn create_option_usage2() {
let a = Arg::from_usage("<option> -o <opt> 'some help info'");
let a = Arg::from("<option> -o <opt> 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.short.unwrap(), 'o');
assert!(a.long.is_none());
@ -381,7 +381,7 @@ mod test {
#[test]
fn create_option_usage3() {
let a = Arg::from_usage("-o <opt> 'some help info'");
let a = Arg::from("-o <opt> 'some help info'");
assert_eq!(a.name, "o");
assert_eq!(a.short.unwrap(), 'o');
assert!(a.long.is_none());
@ -396,7 +396,7 @@ mod test {
#[test]
fn create_option_usage4() {
let a = Arg::from_usage("[option] -o [opt]... 'some help info'");
let a = Arg::from("[option] -o [opt]... 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.short.unwrap(), 'o');
assert!(a.long.is_none());
@ -411,7 +411,7 @@ mod test {
#[test]
fn create_option_usage5() {
let a = Arg::from_usage("[option]... -o [opt] 'some help info'");
let a = Arg::from("[option]... -o [opt] 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.short.unwrap(), 'o');
assert!(a.long.is_none());
@ -425,7 +425,7 @@ mod test {
#[test]
fn create_option_usage6() {
let a = Arg::from_usage("-o [opt]... 'some help info'");
let a = Arg::from("-o [opt]... 'some help info'");
assert_eq!(a.name, "o");
assert_eq!(a.short.unwrap(), 'o');
assert!(a.long.is_none());
@ -440,7 +440,7 @@ mod test {
#[test]
fn create_option_usage7() {
let a = Arg::from_usage("<option> -o <opt>... 'some help info'");
let a = Arg::from("<option> -o <opt>... 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.short.unwrap(), 'o');
assert!(a.long.is_none());
@ -455,7 +455,7 @@ mod test {
#[test]
fn create_option_usage8() {
let a = Arg::from_usage("<option>... -o <opt> 'some help info'");
let a = Arg::from("<option>... -o <opt> 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.short.unwrap(), 'o');
assert!(a.long.is_none());
@ -469,7 +469,7 @@ mod test {
#[test]
fn create_option_usage9() {
let a = Arg::from_usage("-o <opt>... 'some help info'");
let a = Arg::from("-o <opt>... 'some help info'");
assert_eq!(a.name, "o");
assert_eq!(a.short.unwrap(), 'o');
assert!(a.long.is_none());
@ -484,7 +484,7 @@ mod test {
#[test]
fn create_option_usage_long1() {
let a = Arg::from_usage("[option] --opt [opt] 'some help info'");
let a = Arg::from("[option] --opt [opt] 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -499,7 +499,7 @@ mod test {
#[test]
fn create_option_usage_long2() {
let a = Arg::from_usage("--opt [option] 'some help info'");
let a = Arg::from("--opt [option] 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -517,7 +517,7 @@ mod test {
#[test]
fn create_option_usage_long3() {
let a = Arg::from_usage("<option> --opt <opt> 'some help info'");
let a = Arg::from("<option> --opt <opt> 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -532,7 +532,7 @@ mod test {
#[test]
fn create_option_usage_long4() {
let a = Arg::from_usage("--opt <option> 'some help info'");
let a = Arg::from("--opt <option> 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -550,7 +550,7 @@ mod test {
#[test]
fn create_option_usage_long5() {
let a = Arg::from_usage("[option] --opt [opt]... 'some help info'");
let a = Arg::from("[option] --opt [opt]... 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -565,7 +565,7 @@ mod test {
#[test]
fn create_option_usage_long6() {
let a = Arg::from_usage("[option]... --opt [opt] 'some help info'");
let a = Arg::from("[option]... --opt [opt] 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -579,7 +579,7 @@ mod test {
#[test]
fn create_option_usage_long7() {
let a = Arg::from_usage("--opt [option]... 'some help info'");
let a = Arg::from("--opt [option]... 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -597,7 +597,7 @@ mod test {
#[test]
fn create_option_usage_long8() {
let a = Arg::from_usage("<option> --opt <opt>... 'some help info'");
let a = Arg::from("<option> --opt <opt>... 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -612,7 +612,7 @@ mod test {
#[test]
fn create_option_usage_long9() {
let a = Arg::from_usage("<option>... --opt <opt> 'some help info'");
let a = Arg::from("<option>... --opt <opt> 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -626,7 +626,7 @@ mod test {
#[test]
fn create_option_usage_long10() {
let a = Arg::from_usage("--opt <option>... 'some help info'");
let a = Arg::from("--opt <option>... 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -645,7 +645,7 @@ mod test {
#[test]
fn create_option_usage_long_equals1() {
let a = Arg::from_usage("[option] --opt=[opt] 'some help info'");
let a = Arg::from("[option] --opt=[opt] 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -661,7 +661,7 @@ mod test {
#[test]
fn create_option_usage_long_equals2() {
let a = Arg::from_usage("--opt=[option] 'some help info'");
let a = Arg::from("--opt=[option] 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -680,7 +680,7 @@ mod test {
#[test]
fn create_option_usage_long_equals3() {
let a = Arg::from_usage("<option> --opt=<opt> 'some help info'");
let a = Arg::from("<option> --opt=<opt> 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -696,7 +696,7 @@ mod test {
#[test]
fn create_option_usage_long_equals4() {
let a = Arg::from_usage("--opt=<option> 'some help info'");
let a = Arg::from("--opt=<option> 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -715,7 +715,7 @@ mod test {
#[test]
fn create_option_usage_long_equals5() {
let a = Arg::from_usage("[option] --opt=[opt]... 'some help info'");
let a = Arg::from("[option] --opt=[opt]... 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -731,7 +731,7 @@ mod test {
#[test]
fn create_option_usage_long_equals6() {
let a = Arg::from_usage("[option]... --opt=[opt] 'some help info'");
let a = Arg::from("[option]... --opt=[opt] 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -745,7 +745,7 @@ mod test {
#[test]
fn create_option_usage_long_equals7() {
let a = Arg::from_usage("--opt=[option]... 'some help info'");
let a = Arg::from("--opt=[option]... 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -764,7 +764,7 @@ mod test {
#[test]
fn create_option_usage_long_equals8() {
let a = Arg::from_usage("<option> --opt=<opt>... 'some help info'");
let a = Arg::from("<option> --opt=<opt>... 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -780,7 +780,7 @@ mod test {
#[test]
fn create_option_usage_long_equals9() {
let a = Arg::from_usage("<option>... --opt=<opt> 'some help info'");
let a = Arg::from("<option>... --opt=<opt> 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -794,7 +794,7 @@ mod test {
#[test]
fn create_option_usage_long_equals10() {
let a = Arg::from_usage("--opt=<option>... 'some help info'");
let a = Arg::from("--opt=<option>... 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert!(a.short.is_none());
@ -813,7 +813,7 @@ mod test {
#[test]
fn create_option_usage_both1() {
let a = Arg::from_usage("[option] -o --opt [option] 'some help info'");
let a = Arg::from("[option] -o --opt [option] 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -832,7 +832,7 @@ mod test {
#[test]
fn create_option_usage_both2() {
let a = Arg::from_usage("-o --opt [option] 'some help info'");
let a = Arg::from("-o --opt [option] 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -851,7 +851,7 @@ mod test {
#[test]
fn create_option_usage_both3() {
let a = Arg::from_usage("<option> -o --opt <opt> 'some help info'");
let a = Arg::from("<option> -o --opt <opt> 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -867,7 +867,7 @@ mod test {
#[test]
fn create_option_usage_both4() {
let a = Arg::from_usage("-o --opt <option> 'some help info'");
let a = Arg::from("-o --opt <option> 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -886,7 +886,7 @@ mod test {
#[test]
fn create_option_usage_both5() {
let a = Arg::from_usage("[option]... -o --opt [option] 'some help info'");
let a = Arg::from("[option]... -o --opt [option] 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -903,7 +903,7 @@ mod test {
#[test]
fn create_option_usage_both6() {
let a = Arg::from_usage("-o --opt [option]... 'some help info'");
let a = Arg::from("-o --opt [option]... 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -922,7 +922,7 @@ mod test {
#[test]
fn create_option_usage_both7() {
let a = Arg::from_usage("<option>... -o --opt <opt> 'some help info'");
let a = Arg::from("<option>... -o --opt <opt> 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -936,7 +936,7 @@ mod test {
#[test]
fn create_option_usage_both8() {
let a = Arg::from_usage("-o --opt <option>... 'some help info'");
let a = Arg::from("-o --opt <option>... 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -955,7 +955,7 @@ mod test {
#[test]
fn create_option_usage_both_equals1() {
let a = Arg::from_usage("[option] -o --opt=[option] 'some help info'");
let a = Arg::from("[option] -o --opt=[option] 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -974,7 +974,7 @@ mod test {
#[test]
fn create_option_usage_both_equals2() {
let a = Arg::from_usage("-o --opt=[option] 'some help info'");
let a = Arg::from("-o --opt=[option] 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -993,7 +993,7 @@ mod test {
#[test]
fn create_option_usage_both_equals3() {
let a = Arg::from_usage("<option> -o --opt=<opt> 'some help info'");
let a = Arg::from("<option> -o --opt=<opt> 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -1009,7 +1009,7 @@ mod test {
#[test]
fn create_option_usage_both_equals4() {
let a = Arg::from_usage("-o --opt=<option> 'some help info'");
let a = Arg::from("-o --opt=<option> 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -1028,7 +1028,7 @@ mod test {
#[test]
fn create_option_usage_both_equals5() {
let a = Arg::from_usage("[option]... -o --opt=[option] 'some help info'");
let a = Arg::from("[option]... -o --opt=[option] 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -1045,7 +1045,7 @@ mod test {
#[test]
fn create_option_usage_both_equals6() {
let a = Arg::from_usage("-o --opt=[option]... 'some help info'");
let a = Arg::from("-o --opt=[option]... 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -1064,7 +1064,7 @@ mod test {
#[test]
fn create_option_usage_both_equals7() {
let a = Arg::from_usage("<option>... -o --opt=<opt> 'some help info'");
let a = Arg::from("<option>... -o --opt=<opt> 'some help info'");
assert_eq!(a.name, "option");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -1078,7 +1078,7 @@ mod test {
#[test]
fn create_option_usage_both_equals8() {
let a = Arg::from_usage("-o --opt=<option>... 'some help info'");
let a = Arg::from("-o --opt=<option>... 'some help info'");
assert_eq!(a.name, "opt");
assert_eq!(a.long.unwrap(), "opt");
assert_eq!(a.short.unwrap(), 'o');
@ -1097,7 +1097,7 @@ mod test {
#[test]
fn create_option_with_vals1() {
let a = Arg::from_usage("-o <file> <mode> 'some help info'");
let a = Arg::from("-o <file> <mode> 'some help info'");
assert_eq!(a.name, "o");
assert!(a.long.is_none());
assert_eq!(a.short.unwrap(), 'o');
@ -1116,7 +1116,7 @@ mod test {
#[test]
fn create_option_with_vals2() {
let a = Arg::from_usage("-o <file> <mode>... 'some help info'");
let a = Arg::from("-o <file> <mode>... 'some help info'");
assert_eq!(a.name, "o");
assert!(a.long.is_none());
assert_eq!(a.short.unwrap(), 'o');
@ -1135,7 +1135,7 @@ mod test {
#[test]
fn create_option_with_vals3() {
let a = Arg::from_usage("--opt <file> <mode>... 'some help info'");
let a = Arg::from("--opt <file> <mode>... 'some help info'");
assert_eq!(a.name, "opt");
assert!(a.short.is_none());
assert_eq!(a.long.unwrap(), "opt");
@ -1154,7 +1154,7 @@ mod test {
#[test]
fn create_option_with_vals4() {
let a = Arg::from_usage("[myopt] --opt <file> <mode> 'some help info'");
let a = Arg::from("[myopt] --opt <file> <mode> 'some help info'");
assert_eq!(a.name, "myopt");
assert!(a.short.is_none());
assert_eq!(a.long.unwrap(), "opt");
@ -1173,7 +1173,7 @@ mod test {
#[test]
fn create_option_with_vals5() {
let a = Arg::from_usage("--opt <file> <mode> 'some help info'");
let a = Arg::from("--opt <file> <mode> 'some help info'");
assert_eq!(a.name, "opt");
assert!(a.short.is_none());
assert_eq!(a.long.unwrap(), "opt");
@ -1188,7 +1188,7 @@ mod test {
#[test]
fn create_positional_usage() {
let a = Arg::from_usage("[pos] 'some help info'");
let a = Arg::from("[pos] 'some help info'");
assert_eq!(a.name, "pos");
assert_eq!(a.help.unwrap(), "some help info");
assert!(
@ -1201,7 +1201,7 @@ mod test {
#[test]
fn create_positional_usage0() {
let a = Arg::from_usage("<pos> 'some help info'");
let a = Arg::from("<pos> 'some help info'");
assert_eq!(a.name, "pos");
assert_eq!(a.help.unwrap(), "some help info");
assert!(
@ -1214,7 +1214,7 @@ mod test {
#[test]
fn pos_mult_help() {
let a = Arg::from_usage("[pos]... 'some help info'");
let a = Arg::from("[pos]... 'some help info'");
assert_eq!(a.name, "pos");
assert_eq!(a.help.unwrap(), "some help info");
assert!(
@ -1227,7 +1227,7 @@ mod test {
#[test]
fn pos_help_lit_single_quote() {
let a = Arg::from_usage("[pos]... 'some help\' info'");
let a = Arg::from("[pos]... 'some help\' info'");
assert_eq!(a.name, "pos");
assert_eq!(a.help.unwrap(), "some help' info");
assert!(
@ -1240,7 +1240,7 @@ mod test {
#[test]
fn pos_help_double_lit_single_quote() {
let a = Arg::from_usage("[pos]... 'some \'help\' info'");
let a = Arg::from("[pos]... 'some \'help\' info'");
assert_eq!(a.name, "pos");
assert_eq!(a.help.unwrap(), "some 'help' info");
assert!(
@ -1253,7 +1253,7 @@ mod test {
#[test]
fn pos_help_newline() {
let a = Arg::from_usage(
let a = Arg::from(
"[pos]... 'some help{n}\
info'",
);
@ -1269,7 +1269,7 @@ mod test {
#[test]
fn pos_help_newline_lit_sq() {
let a = Arg::from_usage(
let a = Arg::from(
"[pos]... 'some help\' stuff{n}\
info'",
);
@ -1285,7 +1285,7 @@ mod test {
#[test]
fn pos_req_mult_help() {
let a = Arg::from_usage("<pos>... 'some help info'");
let a = Arg::from("<pos>... 'some help info'");
assert_eq!(a.name, "pos");
assert_eq!(a.help.unwrap(), "some help info");
assert!(
@ -1298,7 +1298,7 @@ mod test {
#[test]
fn pos_req() {
let a = Arg::from_usage("<pos>");
let a = Arg::from("<pos>");
assert_eq!(a.name, "pos");
assert!(
!(a.is_set(ArgSettings::MultipleValues) || a.is_set(ArgSettings::MultipleOccurrences))
@ -1310,7 +1310,7 @@ mod test {
#[test]
fn pos_mult() {
let a = Arg::from_usage("[pos]...");
let a = Arg::from("[pos]...");
assert_eq!(a.name, "pos");
assert!(
a.is_set(ArgSettings::MultipleValues) && a.is_set(ArgSettings::MultipleOccurrences)
@ -1322,24 +1322,24 @@ mod test {
#[test]
fn nonascii() {
let a = Arg::from_usage("<ASCII> 'üñíčöĐ€'");
let a = Arg::from("<ASCII> 'üñíčöĐ€'");
assert_eq!(a.name, "ASCII");
assert_eq!(a.help, Some("üñíčöĐ€"));
let a = Arg::from_usage("<üñíčöĐ€> 'ASCII'");
let a = Arg::from("<üñíčöĐ€> 'ASCII'");
assert_eq!(a.name, "üñíčöĐ€");
assert_eq!(a.help, Some("ASCII"));
let a = Arg::from_usage("<üñíčöĐ€> 'üñíčöĐ€'");
let a = Arg::from("<üñíčöĐ€> 'üñíčöĐ€'");
assert_eq!(a.name, "üñíčöĐ€");
assert_eq!(a.help, Some("üñíčöĐ€"));
let a = Arg::from_usage("-ø 'ø'");
let a = Arg::from("-ø 'ø'");
assert_eq!(a.name, "ø");
assert_eq!(a.short, Some('ø'));
assert_eq!(a.help, Some("ø"));
let a = Arg::from_usage("--üñíčöĐ€ 'Nōṫ ASCII'");
let a = Arg::from("--üñíčöĐ€ 'Nōṫ ASCII'");
assert_eq!(a.name, "üñíčöĐ€");
assert_eq!(a.long, Some("üñíčöĐ€"));
assert_eq!(a.help, Some("Nōṫ ASCII"));
let a = Arg::from_usage("[ñämê] --ôpt=[üñíčöĐ€] 'hælp'");
let a = Arg::from("[ñämê] --ôpt=[üñíčöĐ€] 'hælp'");
assert_eq!(a.name, "ñämê");
assert_eq!(a.long, Some("ôpt"));
assert_eq!(

View file

@ -269,8 +269,8 @@ 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::from("-o, --opt [opt] 'some option'").possible_values(&["one", "two"]),
Arg::from("[arg1] 'some pos arg'").possible_values(&["three", "four"]),
]);
assert!(test::compare_output(
@ -326,8 +326,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::from("-f [flag] 'some opt'"),
Arg::from("[arg]... 'some arg'"),
])
.get_matches_from_safe(vec!["", "--", "-f", "-g,x"]);
assert!(r.is_ok());
@ -345,7 +345,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::from("[opt]... 'some pos'"))
.get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"]);
assert!(m.is_present("opt"));
assert_eq!(
@ -358,8 +358,8 @@ fn dont_delim_values_trailingvararg() {
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'"),
Arg::from("-f [flag] 'some opt'"),
Arg::from("[arg]... 'some arg'"),
])
.get_matches_from_safe(vec!["", "--", "-f", "-g,x"]);
assert!(r.is_ok());
@ -376,7 +376,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::from("[opt]... 'some pos'"))
.get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"]);
assert!(m.is_present("opt"));
assert_eq!(
@ -389,8 +389,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::from("-f [flag] 'some opt'"),
Arg::from("[arg]... 'some arg'").use_delimiter(true),
])
.get_matches_from_safe(vec!["", "--", "-f", "-g,x"]);
assert!(r.is_ok());
@ -407,7 +407,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::from("[opt]... 'some pos'").use_delimiter(true))
.get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"]);
assert!(m.is_present("opt"));
assert_eq!(
@ -487,7 +487,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::from("[opt]... 'some pos'"))
.get_matches_from(vec!["", "--foo", "-Wl", "bar"]);
assert!(m.is_present("opt"));
assert_eq!(
@ -609,7 +609,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::from("[cmd] 'command to run'").global(true))
.subcommand(SubCommand::with_name("foo"))
.get_matches_from_safe(vec!["myprog", "set", "foo"]);
assert!(m.is_ok(), "{:?}", m.unwrap_err().kind);
@ -623,7 +623,7 @@ 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("[src] 'some file'").default_value("src"))
.arg_from_usage("<dest> 'some file'")
.get_matches_from_safe(vec!["test", "file"]);
assert!(m.is_ok(), "{:?}", m.unwrap_err().kind);
@ -636,7 +636,7 @@ 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("[src] 'some file'"))
.arg_from_usage("<dest> 'some file'")
.get_matches_from_safe(vec!["test", "file"]);
assert!(m.is_ok(), "{:?}", m.unwrap_err().kind);
@ -649,8 +649,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::from("[BENCH] 'some bench'"))
.arg(Arg::from("[ARGS]... 'some args'"))
.get_matches_from_safe(vec!["bench", "foo", "arg1", "arg2", "arg3"]);
assert!(r.is_ok(), "{:?}", r.unwrap_err().kind);
@ -667,8 +667,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::from("[BENCH] 'some bench'"))
.arg(Arg::from("[ARGS]... 'some args'"))
.get_matches_from_safe(vec!["bench", "--", "arg1", "arg2", "arg3"]);
assert!(r.is_ok(), "{:?}", r.unwrap_err().kind);
@ -685,10 +685,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::from("[BENCH1] 'some bench'"))
.arg(Arg::from("[BENCH2] 'some bench'"))
.arg(Arg::from("[BENCH3] 'some bench'"))
.arg(Arg::from("[ARGS]... 'some args'"))
.get_matches_from_safe(vec!["bench", "foo", "--", "arg1", "arg2", "arg3"]);
assert!(r.is_ok(), "{:?}", r.unwrap_err().kind);
@ -709,9 +709,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::from("[BENCH1] 'some bench'"))
.arg(Arg::from("<BENCH2> 'some bench'"))
.arg(Arg::from("[ARGS]... 'some args'"))
.get_matches_from_safe(vec!["bench", "foo", "--", "arg1", "arg2", "arg3"]);
assert!(r.is_err());
assert_eq!(r.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
@ -721,7 +721,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::from("--some-argument"))
.get_matches_from_safe(vec!["prog", "hello"]);
assert!(res.is_err());
@ -732,7 +732,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::from("--some-argument"))
.get_matches_from_safe(vec!["prog", "--hello"]);
assert!(res.is_err());
@ -743,7 +743,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::from("--some-argument=[val]"))
.get_matches_from_safe(vec!["prog", "-hello"]);
assert!(res.is_err());
@ -786,7 +786,7 @@ fn aaos_flags() {
// flags
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.arg(Arg::from_usage("--flag 'some flag'"))
.arg(Arg::from("--flag 'some flag'"))
.get_matches_from_safe(vec!["", "--flag", "--flag"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -799,7 +799,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::from("--flag... 'some flag'"))
.get_matches_from_safe(vec!["", "--flag", "--flag", "--flag", "--flag"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -812,7 +812,7 @@ fn aaos_opts() {
// opts
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.arg(Arg::from_usage("--opt [val] 'some option'"))
.arg(Arg::from("--opt [val] 'some option'"))
.get_matches_from_safe(vec!["", "--opt=some", "--opt=other"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -826,8 +826,8 @@ 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::from("--opt [val] 'some option'"))
.arg(Arg::from("--other [val] 'some other option'").overrides_with("opt"))
.get_matches_from_safe(vec!["", "--opt=some", "--other=test", "--opt=other"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -842,8 +842,8 @@ 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::from("--opt [val] 'some option'"))
.arg(Arg::from("--other [val] 'some other option'").overrides_with("opt"))
.get_matches_from_safe(vec!["", "--opt=some", "--opt=other", "--other=val"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -857,8 +857,8 @@ 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::from("--opt [val] 'some option'").overrides_with("other"))
.arg(Arg::from("--other [val] 'some other option'"))
.get_matches_from_safe(vec!["", "--opt=some", "--other=test", "--opt=other"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -873,8 +873,8 @@ 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::from("--opt [val] 'some option'").overrides_with("other"))
.arg(Arg::from("--other [val] 'some other option'"))
.get_matches_from_safe(vec!["", "--opt=some", "--opt=other", "--other=val"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -889,7 +889,7 @@ fn aaos_opts_mult() {
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.arg(
Arg::from_usage("--opt [val]... 'some option'")
Arg::from("--opt [val]... 'some option'")
.number_of_values(1)
.require_delimiter(true),
)
@ -909,7 +909,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::from("--opt [val]... 'some option'"))
.get_matches_from_safe(vec![
"", "--opt", "first", "overides", "--opt", "some", "other", "val"
]);
@ -928,7 +928,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::from("[val]... 'some pos'"))
.get_matches_from_safe(vec!["", "some", "other", "value"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -944,7 +944,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::from("--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);

View file

@ -170,7 +170,7 @@ fn invisible_arg_aliases_help_output() {
.takes_value(true)
.aliases(&["invisible", "als1", "more"]),
)
.arg(Arg::from_usage("-f, --flag").aliases(&["invisible", "flg1", "anyway"])),
.arg(Arg::from("-f, --flag").aliases(&["invisible", "flg1", "anyway"])),
);
assert!(test::compare_output(
app,

View file

@ -22,8 +22,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::from("-f, --flag 'some flag'").conflicts_with("other"))
.arg(Arg::from("-o, --other 'some flag'"))
.get_matches_from_safe(vec!["myprog", "-f", "-o"]);
assert!(result.is_err());
let err = result.err().unwrap();
@ -33,8 +33,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::from("-f, --flag 'some flag'").conflicts_with("other"))
.arg(Arg::from("-o, --other 'some flag'"))
.get_matches_from_safe(vec!["myprog", "-o", "-f"]);
assert!(result.is_err());
let err = result.err().unwrap();
@ -44,15 +44,15 @@ fn flag_conflict_2() {
#[test]
fn group_conflict() {
let result = App::new("group_conflict")
.arg(Arg::from_usage("-f, --flag 'some flag'").conflicts_with("gr"))
.arg(Arg::from("-f, --flag 'some flag'").conflicts_with("gr"))
.group(
ArgGroup::with_name("gr")
.required(true)
.arg("some")
.arg("other"),
)
.arg(Arg::from_usage("--some 'some arg'"))
.arg(Arg::from_usage("--other 'other arg'"))
.arg(Arg::from("--some 'some arg'"))
.arg(Arg::from("--other 'other arg'"))
.get_matches_from_safe(vec!["myprog", "--other", "-f"]);
assert!(result.is_err());
let err = result.err().unwrap();
@ -62,15 +62,15 @@ 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::from("-f, --flag 'some flag'").conflicts_with("gr"))
.group(
ArgGroup::with_name("gr")
.required(true)
.arg("some")
.arg("other"),
)
.arg(Arg::from_usage("--some 'some arg'"))
.arg(Arg::from_usage("--other 'other arg'"))
.arg(Arg::from("--some 'some arg'"))
.arg(Arg::from("--other 'other arg'"))
.get_matches_from_safe(vec!["myprog", "-f", "--some"]);
assert!(result.is_err());
let err = result.err().unwrap();
@ -100,8 +100,8 @@ fn conflict_output_rev() {
#[test]
fn conflict_with_unused_default_value() {
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::from("-o, --opt=[opt] 'some opt'").default_value("default"))
.arg(Arg::from("-f, --flag 'some flag'").conflicts_with("opt"))
.get_matches_from_safe(vec!["myprog", "-f"]);
assert!(result.is_ok());
let m = result.unwrap();

View file

@ -8,7 +8,7 @@ use clap::{App, Arg, ErrorKind};
#[test]
fn opts() {
let r = App::new("df")
.arg(Arg::from_usage("-o [opt] 'some opt'").default_value("default"))
.arg(Arg::from("-o [opt] 'some opt'").default_value("default"))
.get_matches_from_safe(vec![""]);
assert!(r.is_ok());
let m = r.unwrap();
@ -19,7 +19,7 @@ fn opts() {
#[test]
fn opt_user_override() {
let r = App::new("df")
.arg(Arg::from_usage("--opt [FILE] 'some arg'").default_value("default"))
.arg(Arg::from("--opt [FILE] 'some arg'").default_value("default"))
.get_matches_from_safe(vec!["", "--opt", "value"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -30,7 +30,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::from("[arg] 'some opt'").default_value("default"))
.get_matches_from_safe(vec![""]);
assert!(r.is_ok());
let m = r.unwrap();
@ -41,7 +41,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::from("[arg] 'some arg'").default_value("default"))
.get_matches_from_safe(vec!["", "value"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -57,7 +57,7 @@ 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::from("-o [opt] 'some opt'").default_value_os(expected))
.get_matches_from_safe(vec![""]);
assert!(r.is_ok());
let m = r.unwrap();
@ -71,7 +71,7 @@ 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::from("--opt [FILE] 'some arg'").default_value_os(default))
.get_matches_from_safe(vec!["", "--opt", "value"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -85,7 +85,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::from("[arg] 'some opt'").default_value_os(expected))
.get_matches_from_safe(vec![""]);
assert!(r.is_ok());
let m = r.unwrap();
@ -99,7 +99,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::from("[arg] 'some arg'").default_value_os(default))
.get_matches_from_safe(vec!["", "value"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -112,8 +112,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, "default"))
.arg(Arg::from("--opt [FILE] 'some arg'"))
.arg(Arg::from("[arg] 'some arg'").default_value_if("opt", None, "default"))
.get_matches_from_safe(vec!["", "--opt", "some"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -124,8 +124,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, "default"))
.arg(Arg::from("--opt [FILE] 'some arg'"))
.arg(Arg::from("[arg] 'some arg'").default_value_if("opt", None, "default"))
.get_matches_from_safe(vec!["", "--opt", "some", "other"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -136,9 +136,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::from("--opt [FILE] 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_if("opt", None, "default"),
)
@ -152,9 +152,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::from("--opt [FILE] 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_if("opt", None, "default"),
)
@ -168,9 +168,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::from("--opt [FILE] 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_if("opt", None, "default"),
)
@ -184,9 +184,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::from("--opt [FILE] 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_if("opt", None, "default"),
)
@ -202,8 +202,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"), "default"))
.arg(Arg::from("--opt [FILE] 'some arg'"))
.arg(Arg::from("[arg] 'some arg'").default_value_if("opt", Some("value"), "default"))
.get_matches_from_safe(vec!["", "--opt", "value"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -214,8 +214,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"), "default"))
.arg(Arg::from("--opt [FILE] 'some arg'"))
.arg(Arg::from("[arg] 'some arg'").default_value_if("opt", Some("value"), "default"))
.get_matches_from_safe(vec!["", "--opt", "other"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -226,8 +226,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"), "default"))
.arg(Arg::from("--opt [FILE] 'some arg'"))
.arg(Arg::from("[arg] 'some arg'").default_value_if("opt", Some("some"), "default"))
.get_matches_from_safe(vec!["", "--opt", "some", "other"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -238,9 +238,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::from("--opt [FILE] 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_if("opt", Some("some"), "default"),
)
@ -254,9 +254,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::from("--opt [FILE] 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_if("opt", Some("some"), "default"),
)
@ -270,9 +270,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::from("--opt [FILE] 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_if("opt", Some("some"), "default"),
)
@ -286,9 +286,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::from("--opt [FILE] 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_if("opt", Some("some"), "default"),
)
@ -302,9 +302,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::from("--opt [FILE] 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_if("opt", Some("some"), "default"),
)
@ -318,9 +318,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::from("--opt [FILE] 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_if("opt", Some("some"), "default"),
)
@ -336,10 +336,10 @@ fn default_if_arg_present_no_arg_with_value_with_default_user_override_fail() {
#[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::from("--opt [FILE] 'some arg'"))
.arg(Arg::from("--flag 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_ifs(&[("opt", Some("some"), "default"), ("flag", None, "flg")]),
)
@ -353,10 +353,10 @@ fn 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::from("--opt [FILE] 'some arg'"))
.arg(Arg::from("--flag 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_ifs(&[("opt", Some("some"), "default"), ("flag", None, "flg")]),
)
@ -370,10 +370,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::from("--opt [FILE] 'some arg'"))
.arg(Arg::from("--flag 'some arg'"))
.arg(
Arg::from_usage("[arg] 'some arg'")
Arg::from("[arg] 'some arg'")
.default_value("first")
.default_value_ifs(&[("opt", Some("some"), "default"), ("flag", None, "flg")]),
)

View file

@ -10,7 +10,7 @@ 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"))
.arg(Arg::from("[arg] 'some opt'").env("CLP_TEST_ENV"))
.get_matches_from_safe(vec![""]);
assert!(r.is_ok());
@ -25,7 +25,7 @@ fn env_os() {
env::set_var("CLP_TEST_ENV", "env");
let r = App::new("df")
.arg(Arg::from_usage("[arg] 'some opt'").env_os(OsStr::new("CLP_TEST_ENV")))
.arg(Arg::from("[arg] 'some opt'").env_os(OsStr::new("CLP_TEST_ENV")))
.get_matches_from_safe(vec![""]);
assert!(r.is_ok());
@ -42,7 +42,7 @@ fn no_env() {
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::from("[arg] 'some opt'").env("CLP_TEST_ENV_NONE"))
.get_matches_from_safe(vec![""]);
assert!(r.is_ok());
@ -58,7 +58,7 @@ fn with_default() {
let r = App::new("df")
.arg(
Arg::from_usage("[arg] 'some opt'")
Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV")
.default_value("default"),
)
@ -76,7 +76,7 @@ fn opt_user_override() {
env::set_var("CLP_TEST_ENV", "env");
let r = App::new("df")
.arg(Arg::from_usage("--arg [FILE] 'some arg'").env("CLP_TEST_ENV"))
.arg(Arg::from("--arg [FILE] 'some arg'").env("CLP_TEST_ENV"))
.get_matches_from_safe(vec!["", "--arg", "opt"]);
assert!(r.is_ok());
@ -91,7 +91,7 @@ fn positionals() {
env::set_var("CLP_TEST_ENV", "env");
let r = App::new("df")
.arg(Arg::from_usage("[arg] 'some opt'").env("CLP_TEST_ENV"))
.arg(Arg::from("[arg] 'some opt'").env("CLP_TEST_ENV"))
.get_matches_from_safe(vec![""]);
assert!(r.is_ok());
@ -106,7 +106,7 @@ fn positionals_user_override() {
env::set_var("CLP_TEST_ENV", "env");
let r = App::new("df")
.arg(Arg::from_usage("[arg] 'some opt'").env("CLP_TEST_ENV"))
.arg(Arg::from("[arg] 'some opt'").env("CLP_TEST_ENV"))
.get_matches_from_safe(vec!["", "opt"]);
assert!(r.is_ok());
@ -122,7 +122,7 @@ fn multiple_one() {
let r = App::new("df")
.arg(
Arg::from_usage("[arg] 'some opt'")
Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV")
.use_delimiter(true)
.multiple(true),
@ -142,7 +142,7 @@ fn multiple_three() {
let r = App::new("df")
.arg(
Arg::from_usage("[arg] 'some opt'")
Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV_MULTI1")
.use_delimiter(true)
.multiple(true),
@ -165,7 +165,7 @@ fn multiple_no_delimiter() {
let r = App::new("df")
.arg(
Arg::from_usage("[arg] 'some opt'")
Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV_MULTI2")
.multiple(true),
)
@ -187,7 +187,7 @@ fn possible_value() {
let r = App::new("df")
.arg(
Arg::from_usage("[arg] 'some opt'")
Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV")
.possible_value("env"),
)
@ -206,7 +206,7 @@ fn not_possible_value() {
let r = App::new("df")
.arg(
Arg::from_usage("[arg] 'some opt'")
Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV")
.possible_value("never"),
)
@ -221,7 +221,7 @@ fn validator() {
let r = App::new("df")
.arg(
Arg::from_usage("[arg] 'some opt'")
Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV")
.validator(|s| {
if s == "env" {
@ -246,7 +246,7 @@ fn validator_output() {
let r = App::new("df")
.arg(
Arg::from_usage("[arg] 'some opt'")
Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV")
.validator(|s| s.parse::<i32>())
)
@ -261,7 +261,7 @@ fn validator_invalid() {
let r = App::new("df")
.arg(
Arg::from_usage("[arg] 'some opt'")
Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV")
.validator(|s| {
if s != "env" {

View file

@ -6,8 +6,8 @@ use clap::{App, Arg, ArgSettings};
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::from("-f, --flag 'some flag'"),
Arg::from("-c, --color 'some other flag'"),
])
.get_matches_from(vec!["", "-f", "-c"]);
assert!(m.is_present("flag"));
@ -17,7 +17,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::from("-o... 'some flag'"))
.get_matches_from_safe(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",
@ -51,7 +51,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::from("-o... 'some flag'"))
.get_matches_from_safe(vec![
"",
"-oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo",
@ -70,8 +70,8 @@ fn lots_o_flags_combined() {
fn flag_using_long() {
let m = App::new("flag")
.args(&[
Arg::from_usage("--flag 'some flag'"),
Arg::from_usage("--color 'some other flag'"),
Arg::from("--flag 'some flag'"),
Arg::from("--color 'some other flag'"),
])
.get_matches_from(vec!["", "--flag", "--color"]);
assert!(m.is_present("flag"));
@ -82,8 +82,8 @@ fn flag_using_long() {
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::from("-f, --flag 'some flag'"),
Arg::from("-c, --color 'some other flag'"),
])
.get_matches_from(vec!["", "-f", "--color"]);
assert!(m.is_present("flag"));
@ -91,8 +91,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::from("-f, --flag 'some flag'"),
Arg::from("-c, --color 'some other flag'"),
])
.get_matches_from(vec!["", "--flag", "-c"]);
assert!(m.is_present("flag"));
@ -103,9 +103,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::from("-f, --flag 'some flag'"),
Arg::from("-c, --color 'some other flag'"),
Arg::from("-d, --debug 'another other flag'"),
])
.get_matches_from(vec!["", "-fcd"]);
assert!(m.is_present("flag"));
@ -115,7 +115,7 @@ fn multiple_flags_in_single() {
#[test]
fn short_flag_misspel() {
let a = Arg::from_usage("-f1, --flag 'some flag'");
let a = Arg::from("-f1, --flag 'some flag'");
assert_eq!(a.name, "flag");
assert_eq!(a.short.unwrap(), 'f');
assert_eq!(a.long.unwrap(), "flag");
@ -127,7 +127,7 @@ fn short_flag_misspel() {
#[test]
fn short_flag_name_missing() {
let a = Arg::from_usage("-f 'some flag'");
let a = Arg::from("-f 'some flag'");
assert_eq!(a.name, "f");
assert_eq!(a.short.unwrap(), 'f');
assert!(a.long.is_none());

View file

@ -151,7 +151,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::from("-f, --flag 'some flag'"))
.group(ArgGroup::with_name("vers").required(true))
.get_matches_from_safe(vec!["empty_prog"]);
assert!(r.is_err());
@ -183,8 +183,8 @@ 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(
.arg(Arg::from("[base] 'Base commit'").conflicts_with("delete"))
.arg(Arg::from(
"-d, --delete 'Remove the base commit information'",
))
.group(

View file

@ -1230,8 +1230,8 @@ fn issue_1112_setup() -> App<'static, 'static> {
.author("Kevin K.")
.about("tests stuff")
.version("1.3")
.arg(Arg::from_usage("-h, --help 'some help'"))
.subcommand(SubCommand::with_name("foo").arg(Arg::from_usage("-h, --help 'some help'")))
.arg(Arg::from("-h, --help 'some help'"))
.subcommand(SubCommand::with_name("foo").arg(Arg::from("-h, --help 'some help'")))
}
#[test]
@ -1283,7 +1283,7 @@ fn issue_1052_require_delim_help() {
.about("tests stuff")
.version("1.3")
.arg(
Arg::from_usage("-f, --fake <some> <val> 'some help'")
Arg::from("-f, --fake <some> <val> 'some help'")
.require_delimiter(true)
.value_delimiter(":"),
);
@ -1370,7 +1370,7 @@ fn custom_headers_headers() {
.author("Will M.")
.about("does stuff")
.version("1.4")
.arg(Arg::from_usage("-f, --fake <some> <val> 'some help'")
.arg(Arg::from("-f, --fake <some> <val> 'some help'")
.require_delimiter(true)
.value_delimiter(":"),
)
@ -1416,7 +1416,7 @@ fn multiple_custom_help_headers() {
.author("Will M.")
.about("does stuff")
.version("1.4")
.arg(Arg::from_usage("-f, --fake <some> <val> 'some help'")
.arg(Arg::from("-f, --fake <some> <val> 'some help'")
.require_delimiter(true)
.value_delimiter(":"),
)
@ -1427,7 +1427,7 @@ fn multiple_custom_help_headers() {
.help("Do not use system proxy settings")
)
.help_heading("SPECIAL")
.arg(Arg::from_usage("-b, --birthday-song <song> 'Change which song is played for birthdays'"))
.arg(Arg::from("-b, --birthday-song <song> 'Change which song is played for birthdays'"))
.stop_custom_headings()
.arg(Arg::with_name("speed")
.long("speed")

View file

@ -27,9 +27,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::from("-f, --flag 'some flag'").hidden(true),
Arg::from("-F, --flag2 'some other flag'"),
Arg::from("--option [opt] 'some option'"),
Arg::with_name("DUMMY").hidden(true),
]);
assert!(test::compare_output(app, "test --help", HIDDEN_ARGS, false));

View file

@ -6,10 +6,10 @@ use clap::{App, Arg, ArgSettings};
fn multiple_occurrences_of_flags_long() {
let m = App::new("mo_flags_long")
.arg(
Arg::from_usage("--multflag 'allowed multiple flag'")
Arg::from("--multflag 'allowed multiple flag'")
.setting(ArgSettings::MultipleOccurrences),
)
.arg(Arg::from_usage("--flag 'disallowed multiple flag'"))
.arg(Arg::from("--flag 'disallowed multiple flag'"))
.get_matches_from(vec!["", "--multflag", "--flag", "--multflag"]);
assert!(m.is_present("multflag"));
assert_eq!(m.occurrences_of("multflag"), 2);
@ -21,10 +21,10 @@ fn multiple_occurrences_of_flags_long() {
fn multiple_occurrences_of_flags_short() {
let m = App::new("mo_flags_short")
.arg(
Arg::from_usage("-m --multflag 'allowed multiple flag'")
Arg::from("-m --multflag 'allowed multiple flag'")
.setting(ArgSettings::MultipleOccurrences),
)
.arg(Arg::from_usage("-f --flag 'disallowed multiple flag'"))
.arg(Arg::from("-f --flag 'disallowed multiple flag'"))
.get_matches_from(vec!["", "-m", "-f", "-m"]);
assert!(m.is_present("multflag"));
assert_eq!(m.occurrences_of("multflag"), 2);
@ -36,14 +36,14 @@ fn multiple_occurrences_of_flags_short() {
fn multiple_occurrences_of_flags_mixed() {
let m = App::new("mo_flags_mixed")
.arg(
Arg::from_usage("-m, --multflag1 'allowed multiple flag'")
Arg::from("-m, --multflag1 'allowed multiple flag'")
.setting(ArgSettings::MultipleOccurrences),
)
.arg(
Arg::from_usage("-n, --multflag2 'another allowed multiple flag'")
Arg::from("-n, --multflag2 'another allowed multiple flag'")
.setting(ArgSettings::MultipleOccurrences),
)
.arg(Arg::from_usage("-f, --flag 'disallowed multiple flag'"))
.arg(Arg::from("-f, --flag 'disallowed multiple flag'"))
.get_matches_from(vec![
"",
"-m",
@ -69,7 +69,7 @@ fn multiple_occurrences_of_flags_large_quantity() {
.collect();
let m = App::new("mo_flags_larg_qty")
.arg(
Arg::from_usage("-m --multflag 'allowed multiple flag'")
Arg::from("-m --multflag 'allowed multiple flag'")
.setting(ArgSettings::MultipleOccurrences),
)
.get_matches_from(args);

View file

@ -101,7 +101,7 @@ fn require_equals_pass() {
#[test]
fn stdin_char() {
let r = App::new("opts")
.arg(Arg::from_usage("-f [flag] 'some flag'"))
.arg(Arg::from("-f [flag] 'some flag'"))
.try_get_matches_from(vec!["", "-f", "-"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -113,8 +113,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::from("-f [flag] 'some flag'"),
Arg::from("-c [color] 'some other flag'"),
])
.try_get_matches_from(vec!["", "-f", "some", "-c", "other"]);
assert!(r.is_ok());
@ -128,7 +128,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::from("-o [opt]... 'some opt'"))
.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",
@ -169,8 +169,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::from("--flag [flag] 'some flag'"),
Arg::from("--color [color] 'some other flag'"),
])
.try_get_matches_from(vec!["", "--flag", "some", "--color", "other"]);
assert!(r.is_ok());
@ -185,8 +185,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::from("--flag [flag] 'some flag'"),
Arg::from("--color [color] 'some other flag'"),
])
.try_get_matches_from(vec!["", "--flag=some", "--color=other"]);
assert!(r.is_ok());
@ -201,8 +201,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::from("-f, --flag [flag] 'some flag'"),
Arg::from("-c, --color [color] 'some other flag'"),
])
.try_get_matches_from(vec!["", "-f", "some", "--color", "other"]);
assert!(r.is_ok());
@ -217,8 +217,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::from("-f, --flag [flag] 'some flag'"),
Arg::from("-c, --color [color] 'some other flag'"),
])
.try_get_matches_from(vec!["", "--flag=some", "-c", "other"]);
assert!(r.is_ok());
@ -232,7 +232,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::from("-o [opt] 'some opt'").default_value("default"))
.try_get_matches_from(vec!["", "-o", "value"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -243,8 +243,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::from("-o [opt]... 'some opt'"))
.arg(Arg::from("[file] 'some file'"))
.try_get_matches_from(vec!["", "-o=1", "some"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -257,8 +257,8 @@ 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::from("-o [opt]... 'some opt'").setting(ArgSettings::UseValueDelimiter))
.arg(Arg::from("[file] 'some file'"))
.try_get_matches_from(vec!["", "-o", "1,2", "some"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -271,8 +271,8 @@ fn multiple_vals_pos_arg_delim() {
#[test]
fn require_delims_no_delim() {
let r = App::new("mvae")
.arg(Arg::from_usage("-o [opt]... 'some opt'").setting(ArgSettings::RequireDelimiter))
.arg(Arg::from_usage("[file] 'some file'"))
.arg(Arg::from("-o [opt]... 'some opt'").setting(ArgSettings::RequireDelimiter))
.arg(Arg::from("[file] 'some file'"))
.try_get_matches_from(vec!["mvae", "-o", "1", "2", "some"]);
assert!(r.is_err());
let err = r.unwrap_err();
@ -282,8 +282,8 @@ fn require_delims_no_delim() {
#[test]
fn require_delims() {
let r = App::new("mvae")
.arg(Arg::from_usage("-o [opt]... 'some opt'").setting(ArgSettings::RequireDelimiter))
.arg(Arg::from_usage("[file] 'some file'"))
.arg(Arg::from("-o [opt]... 'some opt'").setting(ArgSettings::RequireDelimiter))
.arg(Arg::from("[file] 'some file'"))
.try_get_matches_from(vec!["", "-o", "1,2", "some"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -296,7 +296,7 @@ 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::from("-o [opt]... 'some opt'").setting(ArgSettings::AllowHyphenValues))
.try_get_matches_from(vec!["", "-o", "-2", "3"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -307,7 +307,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::from("-o [opt] 'some opt'"))
.try_get_matches_from(vec!["", "-o", "-2"]);
assert!(r.is_err());
let m = r.unwrap_err();
@ -317,7 +317,7 @@ 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("-o [opt]... 'some opt'").setting(ArgSettings::AllowHyphenValues))
.arg_from_usage("-f 'some flag'")
.try_get_matches_from(vec!["", "-o", "-2", "-f"]);
assert!(r.is_ok());
@ -330,7 +330,7 @@ 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("-o [opt]... 'some opt'").setting(ArgSettings::AllowHyphenValues))
.arg_from_usage("-f 'some flag'")
.try_get_matches_from(vec!["", "-f", "-o", "-2"]);
assert!(r.is_ok());
@ -344,7 +344,7 @@ 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::from("-o [opt]... 'some opt'")
.number_of_values(1)
.setting(ArgSettings::AllowHyphenValues),
)
@ -372,7 +372,7 @@ fn did_you_mean() {
fn issue_665() {
let res = App::new("tester")
.arg_from_usage("-v, --reroll-count=[N] 'Mark the patch series as PATCH vN'")
.arg(Arg::from_usage(
.arg(Arg::from(
"--subject-prefix [Subject-Prefix] 'Use [Subject-Prefix] instead of the standard [PATCH] prefix'") )
.try_get_matches_from(vec!["test", "--subject-prefix", "-v", "2"]);
@ -399,10 +399,10 @@ fn issue_1047_min_zero_vals_default_val() {
fn issue_1105_setup(argv: Vec<&'static str>) -> Result<ArgMatches<'static>, clap::Error> {
App::new("opts")
.arg(
Arg::from_usage("-o, --option [opt] 'some option'")
Arg::from("-o, --option [opt] 'some option'")
.setting(ArgSettings::AllowEmptyValues),
)
.arg(Arg::from_usage("--flag 'some flag'"))
.arg(Arg::from("--flag 'some flag'"))
.try_get_matches_from(argv)
}

View file

@ -6,8 +6,8 @@ use clap::{App, Arg, ErrorKind};
fn only_pos_follow() {
let r = App::new("onlypos")
.args(&[
Arg::from_usage("-f [flag] 'some opt'"),
Arg::from_usage("[arg] 'some arg'"),
Arg::from("-f [flag] 'some opt'"),
Arg::from("[arg] 'some arg'"),
])
.get_matches_from_safe(vec!["", "--", "-f"]);
assert!(r.is_ok());
@ -40,7 +40,7 @@ fn issue_946() {
fn positional() {
let r = App::new("positional")
.args(&[
Arg::from_usage("-f, --flag 'some flag'"),
Arg::from("-f, --flag 'some flag'"),
Arg::with_name("positional").index(1),
])
.get_matches_from_safe(vec!["", "-f", "test"]);
@ -52,7 +52,7 @@ fn positional() {
let m = App::new("positional")
.args(&[
Arg::from_usage("-f, --flag 'some flag'"),
Arg::from("-f, --flag 'some flag'"),
Arg::with_name("positional").index(1),
])
.get_matches_from(vec!["", "test", "--flag"]);
@ -64,7 +64,7 @@ fn positional() {
#[test]
fn lots_o_vals() {
let r = App::new("opts")
.arg(Arg::from_usage("[opt]... 'some pos'"))
.arg(Arg::from("[opt]... 'some pos'"))
.get_matches_from_safe(vec![
"", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
"some", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some",
@ -105,7 +105,7 @@ fn lots_o_vals() {
fn positional_multiple() {
let r = App::new("positional_multiple")
.args(&[
Arg::from_usage("-f, --flag 'some flag'"),
Arg::from("-f, --flag 'some flag'"),
Arg::with_name("positional").index(1).multiple(true),
])
.get_matches_from_safe(vec!["", "-f", "test1", "test2", "test3"]);
@ -123,7 +123,7 @@ fn positional_multiple() {
fn positional_multiple_3() {
let r = App::new("positional_multiple")
.args(&[
Arg::from_usage("-f, --flag 'some flag'"),
Arg::from("-f, --flag 'some flag'"),
Arg::with_name("positional").index(1).multiple(true),
])
.get_matches_from_safe(vec!["", "test1", "test2", "test3", "--flag"]);
@ -141,7 +141,7 @@ fn positional_multiple_3() {
fn positional_multiple_2() {
let result = App::new("positional_multiple")
.args(&[
Arg::from_usage("-f, --flag 'some flag'"),
Arg::from("-f, --flag 'some flag'"),
Arg::with_name("positional").index(1),
])
.get_matches_from_safe(vec!["", "-f", "test1", "test2", "test3"]);
@ -154,7 +154,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::from("-f, --flag 'some flag'"),
Arg::with_name("positional")
.index(1)
.possible_value("test123"),
@ -252,7 +252,7 @@ fn last_positional() {
let r = App::new("test")
.arg_from_usage("<TARGET> 'some target'")
.arg_from_usage("[CORPUS] 'some corpus'")
.arg(Arg::from_usage("[ARGS]... 'some file'").last(true))
.arg(Arg::from("[ARGS]... 'some file'").last(true))
.get_matches_from_safe(vec!["test", "tgt", "--", "arg"]);
assert!(r.is_ok());
let m = r.unwrap();
@ -264,7 +264,7 @@ fn last_positional_no_double_dash() {
let r = App::new("test")
.arg_from_usage("<TARGET> 'some target'")
.arg_from_usage("[CORPUS] 'some corpus'")
.arg(Arg::from_usage("[ARGS]... 'some file'").last(true))
.arg(Arg::from("[ARGS]... 'some file'").last(true))
.get_matches_from_safe(vec!["test", "tgt", "crp", "arg"]);
assert!(r.is_err());
assert_eq!(r.unwrap_err().kind, ErrorKind::UnknownArgument);
@ -275,7 +275,7 @@ fn last_positional_second_to_last_mult() {
let r = App::new("test")
.arg_from_usage("<TARGET> 'some target'")
.arg_from_usage("[CORPUS]... 'some corpus'")
.arg(Arg::from_usage("[ARGS]... 'some file'").last(true))
.arg(Arg::from("[ARGS]... 'some file'").last(true))
.get_matches_from_safe(vec!["test", "tgt", "crp1", "crp2", "--", "arg"]);
assert!(r.is_ok(), "{:?}", r.unwrap_err().kind);
}

View file

@ -4,7 +4,7 @@ use clap::{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::from("--flag 'some flag'").overrides_with("flag"))
.get_matches_from_safe(vec!["", "--flag", "--flag"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -15,7 +15,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::from("--flag... 'some flag'").overrides_with("flag"))
.get_matches_from_safe(vec!["", "--flag", "--flag", "--flag", "--flag"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -26,7 +26,7 @@ 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::from("--opt [val] 'some option'").overrides_with("opt"))
.get_matches_from_safe(vec!["", "--opt=some", "--opt=other"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -38,7 +38,7 @@ fn option_overrides_itself() {
#[test]
fn mult_option_require_delim_overrides_itself() {
let res = App::new("posix")
.arg(Arg::from_usage("--opt [val]... 'some option'")
.arg(Arg::from("--opt [val]... 'some option'")
.overrides_with("opt")
.number_of_values(1)
.require_delimiter(true))
@ -53,7 +53,7 @@ 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'")
.arg(Arg::from("--opt [val]... 'some option'")
.overrides_with("opt"))
.get_matches_from_safe(vec!["", "--opt", "first", "overides", "--opt", "some", "other", "val"]);
assert!(res.is_ok());
@ -67,7 +67,7 @@ fn mult_option_overrides_itself() {
fn option_use_delim_false_override_itself() {
let m = App::new("posix")
.arg(Arg::from_usage("--opt [val] 'some option'")
.arg(Arg::from("--opt [val] 'some option'")
.overrides_with("opt"))
.get_matches_from(vec!["", "--opt=some,other", "--opt=one,two"]);
assert!(m.is_present("opt"));
@ -79,7 +79,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::from("[val]... 'some pos'").overrides_with("val"))
.get_matches_from_safe(vec!["", "some", "other", "value"]);
assert!(res.is_ok());
let m = res.unwrap();
@ -90,8 +90,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::from("--flag 'some flag'").overrides_with("color"))
.arg(Arg::from("--color 'some other flag'"))
.get_matches_from(vec!["", "--flag", "--color"]);
assert!(m.is_present("color"));
assert!(!m.is_present("flag"));
@ -100,8 +100,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::from("--flag 'some flag'").overrides_with("color"))
.arg(Arg::from("--color 'some other flag'"))
.get_matches_from(vec!["", "--color", "--flag"]);
assert!(!m.is_present("color"));
assert!(m.is_present("flag"));
@ -110,8 +110,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::from("-f, --flag 'some flag'").overrides_with("color"))
.arg(Arg::from("-c, --color 'some other flag'"))
.get_matches_from(vec!["", "-f", "-c"]);
assert!(m.is_present("color"));
assert!(!m.is_present("flag"));
@ -120,8 +120,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::from("-f, --flag 'some flag'").overrides_with("color"))
.arg(Arg::from("-c, --color 'some other flag'"))
.get_matches_from(vec!["", "-c", "-f"]);
assert!(!m.is_present("color"));
assert!(m.is_present("flag"));
@ -130,8 +130,8 @@ 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::from("--flag [flag] 'some flag'").overrides_with("color"))
.arg(Arg::from("--color [color] 'some other flag'"))
.get_matches_from(vec!["", "--flag", "some", "--color", "other"]);
assert!(m.is_present("color"));
assert_eq!(m.value_of("color").unwrap(), "other");
@ -141,8 +141,8 @@ 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::from("--flag [flag] 'some flag'").overrides_with("color"))
.arg(Arg::from("--color [color] 'some other flag'"))
.get_matches_from(vec!["", "--color", "some", "--flag", "other"]);
assert!(!m.is_present("color"));
assert!(m.is_present("flag"));
@ -152,8 +152,8 @@ 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::from("--flag [flag] 'some flag'").overrides_with("color"))
.arg(Arg::from("--color [color] 'some other flag'"))
.get_matches_from(vec!["", "--flag=some", "--color=other"]);
assert!(m.is_present("color"));
assert_eq!(m.value_of("color").unwrap(), "other");
@ -163,8 +163,8 @@ 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::from("--flag [flag] 'some flag'").overrides_with("color"))
.arg(Arg::from("--color [color] 'some other flag'"))
.get_matches_from(vec!["", "--color=some", "--flag=other"]);
assert!(!m.is_present("color"));
assert!(m.is_present("flag"));
@ -174,8 +174,8 @@ 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::from("-f [flag] 'some flag'").overrides_with("c"))
.arg(Arg::from("-c [color] 'some other flag'"))
.get_matches_from(vec!["", "-f", "some", "-c", "other"]);
assert!(m.is_present("c"));
assert_eq!(m.value_of("c").unwrap(), "other");
@ -185,8 +185,8 @@ 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::from("-f [flag] 'some flag'").overrides_with("c"))
.arg(Arg::from("-c [color] 'some other flag'"))
.get_matches_from(vec!["", "-c", "some", "-f", "other"]);
assert!(!m.is_present("c"));
assert!(m.is_present("f"));
@ -196,9 +196,9 @@ fn posix_compatible_opts_short_rev() {
#[test]
fn conflict_overriden() {
let m = App::new("conflict_overriden")
.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::from("-f, --flag 'some flag'").conflicts_with("debug"))
.arg(Arg::from("-d, --debug 'other flag'"))
.arg(Arg::from("-c, --color 'third flag'").overrides_with("flag"))
.get_matches_from(vec!["", "-f", "-c", "-d"]);
assert!(m.is_present("color"));
assert!(!m.is_present("flag"));
@ -208,9 +208,9 @@ fn conflict_overriden() {
#[test]
fn conflict_overriden_2() {
let result = App::new("conflict_overriden")
.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::from("-f, --flag 'some flag'").conflicts_with("debug"))
.arg(Arg::from("-d, --debug 'other flag'"))
.arg(Arg::from("-c, --color 'third flag'").overrides_with("flag"))
.get_matches_from_safe(vec!["", "-f", "-d", "-c"]);
assert!(result.is_ok());
let m = result.unwrap();
@ -222,9 +222,9 @@ fn conflict_overriden_2() {
#[test]
fn conflict_overriden_3() {
let result = App::new("conflict_overriden")
.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::from("-f, --flag 'some flag'").conflicts_with("debug"))
.arg(Arg::from("-d, --debug 'other flag'"))
.arg(Arg::from("-c, --color 'third flag'").overrides_with("flag"))
.get_matches_from_safe(vec!["", "-d", "-c", "-f"]);
assert!(result.is_err());
let err = result.err().unwrap();
@ -234,9 +234,9 @@ fn conflict_overriden_3() {
#[test]
fn conflict_overriden_4() {
let m = App::new("conflict_overriden")
.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::from("-f, --flag 'some flag'").conflicts_with("debug"))
.arg(Arg::from("-d, --debug 'other flag'"))
.arg(Arg::from("-c, --color 'third flag'").overrides_with("flag"))
.get_matches_from(vec!["", "-d", "-f", "-c"]);
assert!(m.is_present("color"));
assert!(!m.is_present("flag"));
@ -247,7 +247,7 @@ fn conflict_overriden_4() {
fn pos_required_overridden_by_flag() {
let result = App::new("require_overriden")
.arg(Arg::with_name("pos").index(1).required(true))
.arg(Arg::from_usage("-c, --color 'some flag'").overrides_with("pos"))
.arg(Arg::from("-c, --color 'some flag'").overrides_with("pos"))
.get_matches_from_safe(vec!["", "test", "-c"]);
assert!(result.is_ok(), "{:?}", result.unwrap_err());
}
@ -256,7 +256,7 @@ fn pos_required_overridden_by_flag() {
fn require_overriden_2() {
let m = App::new("require_overriden")
.arg(Arg::with_name("req_pos").required(true))
.arg(Arg::from_usage("-c, --color 'other flag'").overrides_with("req_pos"))
.arg(Arg::from("-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"));
@ -265,9 +265,9 @@ fn require_overriden_2() {
#[test]
fn require_overriden_3() {
let m = App::new("require_overriden")
.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::from("-f, --flag 'some flag'").requires("debug"))
.arg(Arg::from("-d, --debug 'other flag'"))
.arg(Arg::from("-c, --color 'third flag'").overrides_with("flag"))
.get_matches_from(vec!["", "-f", "-c"]);
assert!(m.is_present("color"));
assert!(!m.is_present("flag"));
@ -277,9 +277,9 @@ fn require_overriden_3() {
#[test]
fn require_overriden_4() {
let result = App::new("require_overriden")
.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::from("-f, --flag 'some flag'").requires("debug"))
.arg(Arg::from("-d, --debug 'other flag'"))
.arg(Arg::from("-c, --color 'third flag'").overrides_with("flag"))
.get_matches_from_safe(vec!["", "-c", "-f"]);
assert!(result.is_err());
let err = result.err().unwrap();

View file

@ -34,8 +34,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::from("-f, --flag 'some flag'").requires("color"))
.arg(Arg::from("-c, --color 'third flag'"))
.get_matches_from_safe(vec!["", "-f"]);
assert!(result.is_err());
let err = result.err().unwrap();
@ -45,8 +45,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::from("-f, --flag 'some flag'").requires("color"))
.arg(Arg::from("-c, --color 'third flag'"))
.get_matches_from(vec!["", "-f", "-c"]);
assert!(m.is_present("color"));
assert!(m.is_present("flag"));
@ -55,8 +55,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::from("-f [flag] 'some flag'").requires("c"))
.arg(Arg::from("-c [color] 'third flag'"))
.get_matches_from_safe(vec!["", "-f", "val"]);
assert!(result.is_err());
let err = result.err().unwrap();
@ -66,8 +66,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::from("-f [flag] 'some flag'").requires("c"))
.arg(Arg::from("-c [color] 'third flag'"))
.get_matches_from(vec!["", "-f", "val", "-c", "other_val"]);
assert!(m.is_present("c"));
assert_eq!(m.value_of("c").unwrap(), "other_val");
@ -97,15 +97,15 @@ fn positional_required_2() {
#[test]
fn group_required() {
let result = App::new("group_required")
.arg(Arg::from_usage("-f, --flag 'some flag'"))
.arg(Arg::from("-f, --flag 'some flag'"))
.group(
ArgGroup::with_name("gr")
.required(true)
.arg("some")
.arg("other"),
)
.arg(Arg::from_usage("--some 'some arg'"))
.arg(Arg::from_usage("--other 'other arg'"))
.arg(Arg::from("--some 'some arg'"))
.arg(Arg::from("--other 'other arg'"))
.get_matches_from_safe(vec!["", "-f"]);
assert!(result.is_err());
let err = result.err().unwrap();
@ -115,15 +115,15 @@ fn group_required() {
#[test]
fn group_required_2() {
let m = App::new("group_required")
.arg(Arg::from_usage("-f, --flag 'some flag'"))
.arg(Arg::from("-f, --flag 'some flag'"))
.group(
ArgGroup::with_name("gr")
.required(true)
.arg("some")
.arg("other"),
)
.arg(Arg::from_usage("--some 'some arg'"))
.arg(Arg::from_usage("--other 'other arg'"))
.arg(Arg::from("--some 'some arg'"))
.arg(Arg::from("--other 'other arg'"))
.get_matches_from(vec!["", "-f", "--some"]);
assert!(m.is_present("some"));
assert!(!m.is_present("other"));
@ -133,15 +133,15 @@ 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::from("-f, --flag 'some flag'"))
.group(
ArgGroup::with_name("gr")
.required(true)
.arg("some")
.arg("other"),
)
.arg(Arg::from_usage("--some 'some arg'"))
.arg(Arg::from_usage("--other 'other arg'"))
.arg(Arg::from("--some 'some arg'"))
.arg(Arg::from("--other 'other arg'"))
.get_matches_from(vec!["", "-f", "--other"]);
assert!(!m.is_present("some"));
assert!(m.is_present("other"));
@ -151,10 +151,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::from("-f, --flag 'some flag'").requires("gr"))
.group(ArgGroup::with_name("gr").arg("some").arg("other"))
.arg(Arg::from_usage("--some 'some arg'"))
.arg(Arg::from_usage("--other 'other arg'"))
.arg(Arg::from("--some 'some arg'"))
.arg(Arg::from("--other 'other arg'"))
.get_matches_from_safe(vec!["", "-f"]);
assert!(result.is_err());
let err = result.err().unwrap();
@ -164,10 +164,10 @@ fn arg_require_group() {
#[test]
fn arg_require_group_2() {
let m = App::new("arg_require_group")
.arg(Arg::from_usage("-f, --flag 'some flag'").requires("gr"))
.arg(Arg::from("-f, --flag 'some flag'").requires("gr"))
.group(ArgGroup::with_name("gr").arg("some").arg("other"))
.arg(Arg::from_usage("--some 'some arg'"))
.arg(Arg::from_usage("--other 'other arg'"))
.arg(Arg::from("--some 'some arg'"))
.arg(Arg::from("--other 'other arg'"))
.get_matches_from(vec!["", "-f", "--some"]);
assert!(m.is_present("some"));
assert!(!m.is_present("other"));
@ -177,10 +177,10 @@ fn arg_require_group_2() {
#[test]
fn arg_require_group_3() {
let m = App::new("arg_require_group")
.arg(Arg::from_usage("-f, --flag 'some flag'").requires("gr"))
.arg(Arg::from("-f, --flag 'some flag'").requires("gr"))
.group(ArgGroup::with_name("gr").arg("some").arg("other"))
.arg(Arg::from_usage("--some 'some arg'"))
.arg(Arg::from_usage("--other 'other arg'"))
.arg(Arg::from("--some 'some arg'"))
.arg(Arg::from("--other 'other arg'"))
.get_matches_from(vec!["", "-f", "--other"]);
assert!(!m.is_present("some"));
assert!(m.is_present("other"));
@ -192,24 +192,24 @@ fn arg_require_group_3() {
#[test]
fn issue_753() {
let m = App::new("test")
.arg(Arg::from_usage(
.arg(Arg::from(
"-l, --list 'List available interfaces (and stop there)'",
))
.arg(
Arg::from_usage(
Arg::from(
"-i, --iface=[INTERFACE] 'Ethernet interface for fetching NTP packets'",
).required_unless("list"),
)
.arg(
Arg::from_usage("-f, --file=[TESTFILE] 'Fetch NTP packets from pcap file'")
Arg::from("-f, --file=[TESTFILE] 'Fetch NTP packets from pcap file'")
.conflicts_with("iface")
.required_unless("list"),
)
.arg(
Arg::from_usage("-s, --server=[SERVER_IP] 'NTP server IP address'")
Arg::from("-s, --server=[SERVER_IP] 'NTP server IP address'")
.required_unless("list"),
)
.arg(Arg::from_usage("-p, --port=[SERVER_PORT] 'NTP server port'").default_value("123"))
.arg(Arg::from("-p, --port=[SERVER_PORT] 'NTP server port'").default_value("123"))
.get_matches_from_safe(vec!["test", "--list"]);
assert!(m.is_ok());
}

View file

@ -191,7 +191,7 @@ fn invisible_aliases_help_output() {
#[test]
fn issue_1031_args_with_same_name() {
let res = App::new("prog")
.arg(Arg::from_usage("--ui-path=<PATH>"))
.arg(Arg::from("--ui-path=<PATH>"))
.subcommand(SubCommand::with_name("signer"))
.get_matches_from_safe(vec!["prog", "--ui-path", "signer"]);
@ -203,7 +203,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::from("--ui-path=<PATH>"))
.subcommand(SubCommand::with_name("signer"))
.get_matches_from_safe(vec!["prog", "--ui-path", "value", "signer"]);

View file

@ -9,7 +9,7 @@ use clap::{App, AppSettings, Arg, ErrorKind};
#[test]
fn invalid_utf8_strict_positional() {
let m = App::new("bad_utf8")
.arg(Arg::from_usage("<arg> 'some arg'"))
.arg(Arg::from("<arg> 'some arg'"))
.setting(AppSettings::StrictUtf8)
.get_matches_from_safe(vec![OsString::from(""), OsString::from_vec(vec![0xe9])]);
assert!(m.is_err());
@ -19,7 +19,7 @@ fn invalid_utf8_strict_positional() {
#[test]
fn invalid_utf8_strict_option_short_space() {
let m = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.setting(AppSettings::StrictUtf8)
.get_matches_from_safe(vec![
OsString::from(""),
@ -33,7 +33,7 @@ fn invalid_utf8_strict_option_short_space() {
#[test]
fn invalid_utf8_strict_option_short_equals() {
let m = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.setting(AppSettings::StrictUtf8)
.get_matches_from_safe(vec![
OsString::from(""),
@ -46,7 +46,7 @@ fn invalid_utf8_strict_option_short_equals() {
#[test]
fn invalid_utf8_strict_option_short_no_space() {
let m = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.setting(AppSettings::StrictUtf8)
.get_matches_from_safe(vec![
OsString::from(""),
@ -59,7 +59,7 @@ fn invalid_utf8_strict_option_short_no_space() {
#[test]
fn invalid_utf8_strict_option_long_space() {
let m = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.setting(AppSettings::StrictUtf8)
.get_matches_from_safe(vec![
OsString::from(""),
@ -73,7 +73,7 @@ fn invalid_utf8_strict_option_long_space() {
#[test]
fn invalid_utf8_strict_option_long_equals() {
let m = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.setting(AppSettings::StrictUtf8)
.get_matches_from_safe(vec![
OsString::from(""),
@ -86,7 +86,7 @@ fn invalid_utf8_strict_option_long_equals() {
#[test]
fn invalid_utf8_lossy_positional() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("<arg> 'some arg'"))
.arg(Arg::from("<arg> 'some arg'"))
.get_matches_from_safe(vec![OsString::from(""), OsString::from_vec(vec![0xe9])]);
assert!(r.is_ok());
let m = r.unwrap();
@ -97,7 +97,7 @@ fn invalid_utf8_lossy_positional() {
#[test]
fn invalid_utf8_lossy_option_short_space() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.get_matches_from_safe(vec![
OsString::from(""),
OsString::from("-a"),
@ -112,7 +112,7 @@ fn invalid_utf8_lossy_option_short_space() {
#[test]
fn invalid_utf8_lossy_option_short_equals() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.get_matches_from_safe(vec![
OsString::from(""),
OsString::from_vec(vec![0x2d, 0x61, 0x3d, 0xe9]),
@ -126,7 +126,7 @@ fn invalid_utf8_lossy_option_short_equals() {
#[test]
fn invalid_utf8_lossy_option_short_no_space() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.get_matches_from_safe(vec![
OsString::from(""),
OsString::from_vec(vec![0x2d, 0x61, 0xe9]),
@ -140,7 +140,7 @@ fn invalid_utf8_lossy_option_short_no_space() {
#[test]
fn invalid_utf8_lossy_option_long_space() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.get_matches_from_safe(vec![
OsString::from(""),
OsString::from("--arg"),
@ -155,7 +155,7 @@ fn invalid_utf8_lossy_option_long_space() {
#[test]
fn invalid_utf8_lossy_option_long_equals() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.get_matches_from_safe(vec![
OsString::from(""),
OsString::from_vec(vec![0x2d, 0x2d, 0x61, 0x72, 0x67, 0x3d, 0xe9]),
@ -169,7 +169,7 @@ fn invalid_utf8_lossy_option_long_equals() {
#[test]
fn invalid_utf8_positional() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("<arg> 'some arg'"))
.arg(Arg::from("<arg> 'some arg'"))
.get_matches_from_safe(vec![OsString::from(""), OsString::from_vec(vec![0xe9])]);
assert!(r.is_ok());
let m = r.unwrap();
@ -183,7 +183,7 @@ fn invalid_utf8_positional() {
#[test]
fn invalid_utf8_option_short_space() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.get_matches_from_safe(vec![
OsString::from(""),
OsString::from("-a"),
@ -201,7 +201,7 @@ fn invalid_utf8_option_short_space() {
#[test]
fn invalid_utf8_option_short_equals() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.get_matches_from_safe(vec![
OsString::from(""),
OsString::from_vec(vec![0x2d, 0x61, 0x3d, 0xe9]),
@ -218,7 +218,7 @@ fn invalid_utf8_option_short_equals() {
#[test]
fn invalid_utf8_option_short_no_space() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.get_matches_from_safe(vec![
OsString::from(""),
OsString::from_vec(vec![0x2d, 0x61, 0xe9]),
@ -235,7 +235,7 @@ fn invalid_utf8_option_short_no_space() {
#[test]
fn invalid_utf8_option_long_space() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.get_matches_from_safe(vec![
OsString::from(""),
OsString::from("--arg"),
@ -253,7 +253,7 @@ fn invalid_utf8_option_long_space() {
#[test]
fn invalid_utf8_option_long_equals() {
let r = App::new("bad_utf8")
.arg(Arg::from_usage("-a, --arg <arg> 'some arg'"))
.arg(Arg::from("-a, --arg <arg> 'some arg'"))
.get_matches_from_safe(vec![
OsString::from(""),
OsString::from_vec(vec![0x2d, 0x2d, 0x61, 0x72, 0x67, 0x3d, 0xe9]),

View file

@ -50,7 +50,7 @@ fn override_ver() {
.author("Kevin K.")
.about("tests stuff")
.version("1.3")
.arg(Arg::from_usage("-v, --version 'some version'"))
.arg(Arg::from("-v, --version 'some version'"))
.get_matches_from_safe(vec!["test", "--version"]);
assert!(m.is_ok());