diff --git a/README.md b/README.md index 4cf89ca61db..796507a8b9b 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ Why use the procedural [Builder API](https://github.com/clap-rs/clap/blob/v3.0.1 - [wild](https://crates.io/crates/wild) for supporting wildcards (`*`) on Windows like you do Linux - [argfile](https://crates.io/crates/argfile) for loading additional arguments from a file (aka response files) -- [shadow-rs](https://crates.io/crates/shadow-rs) for generating `App::long_version` +- [shadow-rs](https://crates.io/crates/shadow-rs) for generating `Command::long_version` - [clap_mangen](https://crates.io/crates/clap_mangen) for generating man page source (roff) - [clap_complete](https://crates.io/crates/clap_complete) for shell completion support - [clap-verbosity-flag](https://crates.io/crates/clap-verbosity-flag) @@ -150,8 +150,8 @@ Why use the procedural [Builder API](https://github.com/clap-rs/clap/blob/v3.0.1 **Warning:** These may contain breaking changes between minor releases. -* **unstable-replace**: Enable [`App::replace`](https://github.com/clap-rs/clap/issues/2836) -* **unstable-multicall**: Enable [`App::multicall`](https://github.com/clap-rs/clap/issues/2861) +* **unstable-replace**: Enable [`Command::replace`](https://github.com/clap-rs/clap/issues/2836) +* **unstable-multicall**: Enable [`Command::multicall`](https://github.com/clap-rs/clap/issues/2861) * **unstable-grouped**: Enable [`ArgMatches::grouped_values_of`](https://github.com/clap-rs/clap/issues/2924) ## Sponsors diff --git a/benches/01_default.rs b/benches/01_default.rs index 07e3ad218f8..620b32b818f 100644 --- a/benches/01_default.rs +++ b/benches/01_default.rs @@ -1,13 +1,13 @@ -use clap::App; +use clap::Command; use criterion::{criterion_group, criterion_main, Criterion}; pub fn build_empty(c: &mut Criterion) { - c.bench_function("build_empty", |b| b.iter(|| App::new("claptests"))); + c.bench_function("build_empty", |b| b.iter(|| Command::new("claptests"))); } pub fn parse_empty(c: &mut Criterion) { c.bench_function("parse_empty", |b| { - b.iter(|| App::new("claptests").get_matches_from(vec![""])) + b.iter(|| Command::new("claptests").get_matches_from(vec![""])) }); } diff --git a/benches/02_simple.rs b/benches/02_simple.rs index 46a725bbb5e..667d02f873c 100644 --- a/benches/02_simple.rs +++ b/benches/02_simple.rs @@ -1,9 +1,9 @@ -use clap::{arg, App, Arg}; +use clap::{arg, Arg, Command}; use criterion::{criterion_group, criterion_main, Criterion}; macro_rules! create_app { () => {{ - App::new("claptests") + Command::new("claptests") .version("0.1") .about("tests clap library") .author("Kevin K. ") @@ -19,7 +19,7 @@ pub fn build_simple(c: &mut Criterion) { pub fn build_with_flag(c: &mut Criterion) { c.bench_function("build_with_flag", |b| { - b.iter(|| App::new("claptests").arg(arg!(-s --some "something"))) + b.iter(|| Command::new("claptests").arg(arg!(-s --some "something"))) }); } @@ -27,14 +27,14 @@ pub fn build_with_flag_ref(c: &mut Criterion) { c.bench_function("build_with_flag_ref", |b| { b.iter(|| { let arg = arg!(-s --some "something"); - App::new("claptests").arg(&arg) + Command::new("claptests").arg(&arg) }) }); } pub fn build_with_opt(c: &mut Criterion) { c.bench_function("build_with_opt", |b| { - b.iter(|| App::new("claptests").arg(arg!(-s --some "something"))) + b.iter(|| Command::new("claptests").arg(arg!(-s --some "something"))) }); } @@ -42,14 +42,14 @@ pub fn build_with_opt_ref(c: &mut Criterion) { c.bench_function("build_with_opt_ref", |b| { b.iter(|| { let arg = arg!(-s --some "something"); - App::new("claptests").arg(&arg) + Command::new("claptests").arg(&arg) }) }); } pub fn build_with_pos(c: &mut Criterion) { c.bench_function("build_with_pos", |b| { - b.iter(|| App::new("claptests").arg(Arg::new("some"))) + b.iter(|| Command::new("claptests").arg(Arg::new("some"))) }); } @@ -57,7 +57,7 @@ pub fn build_with_pos_ref(c: &mut Criterion) { c.bench_function("build_with_pos_ref", |b| { b.iter(|| { let arg = Arg::new("some"); - App::new("claptests").arg(&arg) + Command::new("claptests").arg(&arg) }) }); } diff --git a/benches/03_complex.rs b/benches/03_complex.rs index 0e08a225d24..3ac81bb15dc 100644 --- a/benches/03_complex.rs +++ b/benches/03_complex.rs @@ -1,4 +1,4 @@ -use clap::{arg, App, Arg}; +use clap::{arg, Arg, Command}; use criterion::{criterion_group, criterion_main, Criterion}; static OPT3_VALS: [&str; 2] = ["fast", "slow"]; @@ -6,7 +6,7 @@ static POS3_VALS: [&str; 2] = ["vi", "emacs"]; macro_rules! create_app { () => {{ - App::new("claptests") + Command::new("claptests") .version("0.1") .about("tests clap library") .author("Kevin K. ") @@ -35,7 +35,7 @@ macro_rules! create_app { arg!(--maxvals3 ... "Tests 3 max vals").max_values(3).multiple_values(true).required(false), ]) .subcommand( - App::new("subcmd") + Command::new("subcmd") .about("tests subcommands") .version("0.1") .author("Kevin K. ") @@ -48,7 +48,7 @@ macro_rules! create_app { pub fn build_from_builder(c: &mut Criterion) { c.bench_function("build_from_builder", |b| { b.iter(|| { - App::new("claptests") + Command::new("claptests") .version("0.1") .about("tests clap library") .author("Kevin K. ") @@ -141,7 +141,7 @@ pub fn build_from_builder(c: &mut Criterion) { .max_values(3), ) .subcommand( - App::new("subcmd") + Command::new("subcmd") .about("tests subcommands") .version("0.1") .author("Kevin K. ") diff --git a/benches/04_new_help.rs b/benches/04_new_help.rs index 7a8717304a3..83b14fb7068 100644 --- a/benches/04_new_help.rs +++ b/benches/04_new_help.rs @@ -1,17 +1,17 @@ -use clap::App; +use clap::Command; use clap::{arg, Arg}; use criterion::{criterion_group, criterion_main, Criterion}; use std::io::Cursor; -fn build_help(app: &mut App) -> String { +fn build_help(cmd: &mut Command) -> String { let mut buf = Cursor::new(Vec::with_capacity(50)); - app.write_help(&mut buf).unwrap(); + cmd.write_help(&mut buf).unwrap(); let content = buf.into_inner(); String::from_utf8(content).unwrap() } -fn app_example1<'c>() -> App<'c> { - App::new("MyApp") +fn app_example1<'c>() -> Command<'c> { + Command::new("MyApp") .version("1.0") .author("Kevin K. ") .about("Does awesome things") @@ -24,21 +24,21 @@ fn app_example1<'c>() -> App<'c> { .arg(arg!( "Sets an optional output file")) .arg(arg!(d: -d ... "Turn debugging information on")) .subcommand( - App::new("test") + Command::new("test") .about("does testing things") .arg(arg!(-l --list "lists test values")), ) } -fn app_example2<'c>() -> App<'c> { - App::new("MyApp") +fn app_example2<'c>() -> Command<'c> { + Command::new("MyApp") .version("1.0") .author("Kevin K. ") .about("Does awesome things") } -fn app_example3<'c>() -> App<'c> { - App::new("MyApp") +fn app_example3<'c>() -> Command<'c> { + Command::new("MyApp") .arg( Arg::new("debug") .help("turn on debugging information") @@ -64,8 +64,8 @@ fn app_example3<'c>() -> App<'c> { ) } -fn app_example4<'c>() -> App<'c> { - App::new("MyApp") +fn app_example4<'c>() -> Command<'c> { + Command::new("MyApp") .about("Parses an input file to do awesome things") .version("1.0") .author("Kevin K. ") @@ -89,8 +89,8 @@ fn app_example4<'c>() -> App<'c> { ) } -fn app_example5<'c>() -> App<'c> { - App::new("MyApp").arg( +fn app_example5<'c>() -> Command<'c> { + Command::new("MyApp").arg( Arg::new("awesome") .help("turns up the awesome") .short('a') @@ -99,8 +99,8 @@ fn app_example5<'c>() -> App<'c> { ) } -fn app_example6<'c>() -> App<'c> { - App::new("MyApp") +fn app_example6<'c>() -> Command<'c> { + Command::new("MyApp") .arg( Arg::new("input") .help("the input file to use") @@ -111,8 +111,8 @@ fn app_example6<'c>() -> App<'c> { .arg(Arg::new("config").help("the config file to use").index(2)) } -fn app_example7<'c>() -> App<'c> { - App::new("MyApp") +fn app_example7<'c>() -> Command<'c> { + Command::new("MyApp") .arg(Arg::new("config")) .arg(Arg::new("output")) .arg( @@ -129,8 +129,8 @@ fn app_example7<'c>() -> App<'c> { ) } -fn app_example8<'c>() -> App<'c> { - App::new("MyApp") +fn app_example8<'c>() -> Command<'c> { + Command::new("MyApp") .arg(Arg::new("config")) .arg(Arg::new("output")) .arg( @@ -147,8 +147,8 @@ fn app_example8<'c>() -> App<'c> { ) } -fn app_example10<'c>() -> App<'c> { - App::new("myapp").about("does awesome things").arg( +fn app_example10<'c>() -> Command<'c> { + Command::new("myapp").about("does awesome things").arg( Arg::new("CONFIG") .help("The config file to use (default is \"config.json\")") .short('c') @@ -157,53 +157,53 @@ fn app_example10<'c>() -> App<'c> { } pub fn example1(c: &mut Criterion) { - let mut app = app_example1(); - c.bench_function("example1", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_example1(); + c.bench_function("example1", |b| b.iter(|| build_help(&mut cmd))); } pub fn example2(c: &mut Criterion) { - let mut app = app_example2(); - c.bench_function("example2", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_example2(); + c.bench_function("example2", |b| b.iter(|| build_help(&mut cmd))); } pub fn example3(c: &mut Criterion) { - let mut app = app_example3(); - c.bench_function("example3", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_example3(); + c.bench_function("example3", |b| b.iter(|| build_help(&mut cmd))); } pub fn example4(c: &mut Criterion) { - let mut app = app_example4(); - c.bench_function("example4", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_example4(); + c.bench_function("example4", |b| b.iter(|| build_help(&mut cmd))); } pub fn example5(c: &mut Criterion) { - let mut app = app_example5(); - c.bench_function("example5", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_example5(); + c.bench_function("example5", |b| b.iter(|| build_help(&mut cmd))); } pub fn example6(c: &mut Criterion) { - let mut app = app_example6(); - c.bench_function("example6", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_example6(); + c.bench_function("example6", |b| b.iter(|| build_help(&mut cmd))); } pub fn example7(c: &mut Criterion) { - let mut app = app_example7(); - c.bench_function("example7", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_example7(); + c.bench_function("example7", |b| b.iter(|| build_help(&mut cmd))); } pub fn example8(c: &mut Criterion) { - let mut app = app_example8(); - c.bench_function("example8", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_example8(); + c.bench_function("example8", |b| b.iter(|| build_help(&mut cmd))); } pub fn example10(c: &mut Criterion) { - let mut app = app_example10(); - c.bench_function("example10", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_example10(); + c.bench_function("example10", |b| b.iter(|| build_help(&mut cmd))); } pub fn example4_template(c: &mut Criterion) { - let mut app = app_example4().help_template("{bin} {version}\n{author}\n{about}\n\nUSAGE:\n {usage}\n\nOPTIONS:\n{options}\n\nARGS:\n{args}\n"); - c.bench_function("example4_template", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_example4().help_template("{bin} {version}\n{author}\n{about}\n\nUSAGE:\n {usage}\n\nOPTIONS:\n{options}\n\nARGS:\n{args}\n"); + c.bench_function("example4_template", |b| b.iter(|| build_help(&mut cmd))); } criterion_group!( diff --git a/benches/05_ripgrep.rs b/benches/05_ripgrep.rs index 3a7e4de6b4e..7d5cab69649 100644 --- a/benches/05_ripgrep.rs +++ b/benches/05_ripgrep.rs @@ -3,7 +3,7 @@ // // CLI used is adapted from ripgrep 48a8a3a691220f9e5b2b08f4051abe8655ea7e8a -use clap::{App, Arg}; +use clap::{Arg, Command}; use criterion::{criterion_group, criterion_main, Criterion}; use std::collections::HashMap; use std::io::Cursor; @@ -19,13 +19,13 @@ pub fn build_rg_with_long_help(c: &mut Criterion) { } pub fn write_rg_short_help(c: &mut Criterion) { - let mut app = app_short(); - c.bench_function("write_rg_short_help", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_short(); + c.bench_function("write_rg_short_help", |b| b.iter(|| build_help(&mut cmd))); } pub fn write_rg_long_help(c: &mut Criterion) { - let mut app = app_long(); - c.bench_function("write_rg_long_help", |b| b.iter(|| build_help(&mut app))); + let mut cmd = app_long(); + c.bench_function("write_rg_long_help", |b| b.iter(|| build_help(&mut cmd))); } pub fn parse_rg(c: &mut Criterion) { @@ -270,19 +270,19 @@ OPTIONS: {options}"; /// Build a clap application with short help strings. -fn app_short() -> App<'static> { - app(false, |k| USAGES[k].short) +fn app_short() -> Command<'static> { + cmd(false, |k| USAGES[k].short) } /// Build a clap application with long help strings. -fn app_long() -> App<'static> { - app(true, |k| USAGES[k].long) +fn app_long() -> Command<'static> { + cmd(true, |k| USAGES[k].long) } /// Build the help text of an application. -fn build_help(app: &mut App) -> String { +fn build_help(cmd: &mut Command) -> String { let mut buf = Cursor::new(Vec::with_capacity(50)); - app.write_help(&mut buf).unwrap(); + cmd.write_help(&mut buf).unwrap(); let content = buf.into_inner(); String::from_utf8(content).unwrap() } @@ -290,18 +290,18 @@ fn build_help(app: &mut App) -> String { /// Build a clap application parameterized by usage strings. /// /// The function given should take a clap argument name and return a help -/// string. `app` will panic if a usage string is not defined. +/// string. `cmd` will panic if a usage string is not defined. /// /// This is an intentionally stand-alone module so that it can be used easily /// in a `build.rs` script to build shell completion files. -fn app(_next_line_help: bool, doc: F) -> App<'static> +fn cmd(_next_line_help: bool, doc: F) -> Command<'static> where F: Fn(&'static str) -> &'static str, { let arg = |name| Arg::new(name).help(doc(name)); let flag = |name| arg(name).long(name); - App::new("ripgrep") + Command::new("ripgrep") .author("BurntSushi") // simulating since it's only a bench .version("0.4.0") // Simulating .about(ABOUT) diff --git a/benches/06_rustup.rs b/benches/06_rustup.rs index dba5be60f3f..8d9c406e40d 100644 --- a/benches/06_rustup.rs +++ b/benches/06_rustup.rs @@ -2,7 +2,7 @@ // // CLI used is from rustup 408ed84f0e50511ed44a405dd91365e5da588790 -use clap::{App, AppSettings, Arg, ArgGroup}; +use clap::{AppSettings, Arg, ArgGroup, Command}; use criterion::{criterion_group, criterion_main, Criterion}; pub fn build_rustup(c: &mut Criterion) { @@ -21,8 +21,8 @@ pub fn parse_rustup_with_sc(c: &mut Criterion) { }); } -fn build_cli() -> App<'static> { - App::new("rustup") +fn build_cli() -> Command<'static> { + Command::new("rustup") .version("0.9.0") // Simulating .about("The Rust toolchain installer") .after_help(RUSTUP_HELP) @@ -35,19 +35,19 @@ fn build_cli() -> App<'static> { .long("verbose"), ) .subcommand( - App::new("show") + Command::new("show") .about("Show the active and installed toolchains") .after_help(SHOW_HELP), ) .subcommand( - App::new("install") + Command::new("install") .about("Update Rust toolchains") .after_help(TOOLCHAIN_INSTALL_HELP) .hide(true) // synonym for 'toolchain install' .arg(Arg::new("toolchain").required(true)), ) .subcommand( - App::new("update") + Command::new("update") .about("Update Rust toolchains") .after_help(UPDATE_HELP) .arg(Arg::new("toolchain").required(true)) @@ -59,104 +59,104 @@ fn build_cli() -> App<'static> { ), ) .subcommand( - App::new("default") + Command::new("default") .about("Set the default toolchain") .after_help(DEFAULT_HELP) .arg(Arg::new("toolchain").required(true)), ) .subcommand( - App::new("toolchain") + Command::new("toolchain") .about("Modify or query the installed toolchains") .after_help(TOOLCHAIN_HELP) .setting(AppSettings::DeriveDisplayOrder) // .setting(AppSettings::SubcommandRequiredElseHelp) - .subcommand(App::new("list").about("List installed toolchains")) + .subcommand(Command::new("list").about("List installed toolchains")) .subcommand( - App::new("install") + Command::new("install") .about("Install or update a given toolchain") .arg(Arg::new("toolchain").required(true)), ) .subcommand( - App::new("uninstall") + Command::new("uninstall") .about("Uninstall a toolchain") .arg(Arg::new("toolchain").required(true)), ) .subcommand( - App::new("link") + Command::new("link") .about("Create a custom toolchain by symlinking to a directory") .arg(Arg::new("toolchain").required(true)) .arg(Arg::new("path").required(true)), ) .subcommand( - App::new("update") + Command::new("update") .hide(true) // synonym for 'install' .arg(Arg::new("toolchain").required(true)), ) .subcommand( - App::new("add") + Command::new("add") .hide(true) // synonym for 'install' .arg(Arg::new("toolchain").required(true)), ) .subcommand( - App::new("remove") + Command::new("remove") .hide(true) // synonym for 'uninstall' .arg(Arg::new("toolchain").required(true)), ), ) .subcommand( - App::new("target") + Command::new("target") .about("Modify a toolchain's supported targets") .setting(AppSettings::DeriveDisplayOrder) // .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand( - App::new("list") + Command::new("list") .about("List installed and available targets") .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), ) .subcommand( - App::new("add") + Command::new("add") .about("Add a target to a Rust toolchain") .arg(Arg::new("target").required(true)) .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), ) .subcommand( - App::new("remove") + Command::new("remove") .about("Remove a target from a Rust toolchain") .arg(Arg::new("target").required(true)) .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), ) .subcommand( - App::new("install") + Command::new("install") .hide(true) // synonym for 'add' .arg(Arg::new("target").required(true)) .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), ) .subcommand( - App::new("uninstall") + Command::new("uninstall") .hide(true) // synonym for 'remove' .arg(Arg::new("target").required(true)) .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), ), ) .subcommand( - App::new("component") + Command::new("component") .about("Modify a toolchain's installed components") .setting(AppSettings::DeriveDisplayOrder) // .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand( - App::new("list") + Command::new("list") .about("List installed and available components") .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), ) .subcommand( - App::new("add") + Command::new("add") .about("Add a component to a Rust toolchain") .arg(Arg::new("component").required(true)) .arg(Arg::new("toolchain").long("toolchain").takes_value(true)) .arg(Arg::new("target").long("target").takes_value(true)), ) .subcommand( - App::new("remove") + Command::new("remove") .about("Remove a component from a Rust toolchain") .arg(Arg::new("component").required(true)) .arg(Arg::new("toolchain").long("toolchain").takes_value(true)) @@ -164,19 +164,19 @@ fn build_cli() -> App<'static> { ), ) .subcommand( - App::new("override") + Command::new("override") .about("Modify directory toolchain overrides") .after_help(OVERRIDE_HELP) .setting(AppSettings::DeriveDisplayOrder) // .setting(AppSettings::SubcommandRequiredElseHelp) - .subcommand(App::new("list").about("List directory toolchain overrides")) + .subcommand(Command::new("list").about("List directory toolchain overrides")) .subcommand( - App::new("set") + Command::new("set") .about("Set the override toolchain for a directory") .arg(Arg::new("toolchain").required(true)), ) .subcommand( - App::new("unset") + Command::new("unset") .about("Remove the override toolchain for a directory") .after_help(OVERRIDE_UNSET_HELP) .arg( @@ -192,12 +192,12 @@ fn build_cli() -> App<'static> { ), ) .subcommand( - App::new("add") + Command::new("add") .hide(true) // synonym for 'set' .arg(Arg::new("toolchain").required(true)), ) .subcommand( - App::new("remove") + Command::new("remove") .hide(true) // synonym for 'unset' .about("Remove the override toolchain for a directory") .arg(Arg::new("path").long("path").takes_value(true)) @@ -209,7 +209,7 @@ fn build_cli() -> App<'static> { ), ) .subcommand( - App::new("run") + Command::new("run") .about("Run a command with an environment configured for a given toolchain") .after_help(RUN_HELP) .trailing_var_arg(true) @@ -223,12 +223,12 @@ fn build_cli() -> App<'static> { ), ) .subcommand( - App::new("which") + Command::new("which") .about("Display which binary will be run for a given command") .arg(Arg::new("command").required(true)), ) .subcommand( - App::new("doc") + Command::new("doc") .about("Open the documentation for the current toolchain") .after_help(DOC_HELP) .arg( @@ -244,38 +244,42 @@ fn build_cli() -> App<'static> { .group(ArgGroup::new("page").args(&["book", "std"])), ) .subcommand( - App::new("man") + Command::new("man") .about("View the man page for a given command") .arg(Arg::new("command").required(true)) .arg(Arg::new("toolchain").long("toolchain").takes_value(true)), ) .subcommand( - App::new("self") + Command::new("self") .about("Modify the rustup installation") .setting(AppSettings::DeriveDisplayOrder) - .subcommand(App::new("update").about("Download and install updates to rustup")) + .subcommand(Command::new("update").about("Download and install updates to rustup")) .subcommand( - App::new("uninstall") + Command::new("uninstall") .about("Uninstall rustup.") .arg(Arg::new("no-prompt").short('y')), ) - .subcommand(App::new("upgrade-data").about("Upgrade the internal data format.")), + .subcommand( + Command::new("upgrade-data").about("Upgrade the internal data format."), + ), ) .subcommand( - App::new("telemetry") + Command::new("telemetry") .about("rustup telemetry commands") .hide(true) .setting(AppSettings::DeriveDisplayOrder) - .subcommand(App::new("enable").about("Enable rustup telemetry")) - .subcommand(App::new("disable").about("Disable rustup telemetry")) - .subcommand(App::new("analyze").about("Analyze stored telemetry")), + .subcommand(Command::new("enable").about("Enable rustup telemetry")) + .subcommand(Command::new("disable").about("Disable rustup telemetry")) + .subcommand(Command::new("analyze").about("Analyze stored telemetry")), ) .subcommand( - App::new("set").about("Alter rustup settings").subcommand( - App::new("default-host") - .about("The triple used to identify toolchains when not specified") - .arg(Arg::new("host_triple").required(true)), - ), + Command::new("set") + .about("Alter rustup settings") + .subcommand( + Command::new("default-host") + .about("The triple used to identify toolchains when not specified") + .arg(Arg::new("host_triple").required(true)), + ), ) } diff --git a/clap_complete/Cargo.toml b/clap_complete/Cargo.toml index 850fd08be13..4f0fc141a8c 100644 --- a/clap_complete/Cargo.toml +++ b/clap_complete/Cargo.toml @@ -8,7 +8,7 @@ include = [ "LICENSE-*", "README.md" ] -description = "Generate shell completion scripts for your clap::App" +description = "Generate shell completion scripts for your clap::Command" repository = "https://github.com/clap-rs/clap/tree/master/clap_complete" documentation = "https://docs.rs/clap_complete" keywords = [ diff --git a/clap_complete/examples/bash_completion.rs b/clap_complete/examples/bash_completion.rs index 57c060ccefc..d7c71da542f 100644 --- a/clap_complete/examples/bash_completion.rs +++ b/clap_complete/examples/bash_completion.rs @@ -1,11 +1,11 @@ -use clap::App; +use clap::Command; use clap_complete::{generate, shells::Bash}; use std::io; fn main() { - let mut app = App::new("myapp") - .subcommand(App::new("test").subcommand(App::new("config"))) - .subcommand(App::new("hello")); + let mut cmd = Command::new("myapp") + .subcommand(Command::new("test").subcommand(Command::new("config"))) + .subcommand(Command::new("hello")); - generate(Bash, &mut app, "myapp", &mut io::stdout()); + generate(Bash, &mut cmd, "myapp", &mut io::stdout()); } diff --git a/clap_complete/examples/value_hints.rs b/clap_complete/examples/value_hints.rs index 5281f78b8bd..4b061f746e5 100644 --- a/clap_complete/examples/value_hints.rs +++ b/clap_complete/examples/value_hints.rs @@ -12,12 +12,12 @@ //! . ./value_hints.fish //! ./target/debug/examples/value_hints -- //! ``` -use clap::{App, Arg, ValueHint}; +use clap::{Arg, Command, ValueHint}; use clap_complete::{generate, Generator, Shell}; use std::io; -fn build_cli() -> App<'static> { - App::new("value_hints") +fn build_cli() -> Command<'static> { + Command::new("value_hints") // AppSettings::TrailingVarArg is required to use ValueHint::CommandWithArguments .trailing_var_arg(true) .arg( @@ -92,16 +92,16 @@ fn build_cli() -> App<'static> { ) } -fn print_completions(gen: G, app: &mut App) { - generate(gen, app, app.get_name().to_string(), &mut io::stdout()); +fn print_completions(gen: G, cmd: &mut Command) { + generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout()); } fn main() { let matches = build_cli().get_matches(); if let Ok(generator) = matches.value_of_t::("generator") { - let mut app = build_cli(); + let mut cmd = build_cli(); eprintln!("Generating completion file for {}...", generator); - print_completions(generator, &mut app); + print_completions(generator, &mut cmd); } } diff --git a/clap_complete/examples/value_hints_derive.rs b/clap_complete/examples/value_hints_derive.rs index 2cbcaadd1e6..2d069c284f0 100644 --- a/clap_complete/examples/value_hints_derive.rs +++ b/clap_complete/examples/value_hints_derive.rs @@ -12,7 +12,7 @@ //! . ./value_hints_derive.fish //! ./target/debug/examples/value_hints_derive -- //! ``` -use clap::{App, IntoApp, Parser, ValueHint}; +use clap::{Command, IntoApp, Parser, ValueHint}; use clap_complete::{generate, Generator, Shell}; use std::ffi::OsString; use std::io; @@ -21,7 +21,7 @@ use std::path::PathBuf; #[derive(Parser, Debug, PartialEq)] #[clap( name = "value_hints_derive", - // App::trailing_var_ar is required to use ValueHint::CommandWithArguments + // Command::trailing_var_ar is required to use ValueHint::CommandWithArguments trailing_var_arg = true, )] struct Opt { @@ -57,17 +57,17 @@ struct Opt { email: Option, } -fn print_completions(gen: G, app: &mut App) { - generate(gen, app, app.get_name().to_string(), &mut io::stdout()); +fn print_completions(gen: G, cmd: &mut Command) { + generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout()); } fn main() { let opt = Opt::parse(); if let Some(generator) = opt.generator { - let mut app = Opt::into_app(); + let mut cmd = Opt::into_app(); eprintln!("Generating completion file for {:?}...", generator); - print_completions(generator, &mut app); + print_completions(generator, &mut cmd); } else { println!("{:#?}", opt); } diff --git a/clap_complete/src/generator/mod.rs b/clap_complete/src/generator/mod.rs index e5f3d239548..2d00c281df6 100644 --- a/clap_complete/src/generator/mod.rs +++ b/clap_complete/src/generator/mod.rs @@ -8,7 +8,7 @@ use std::io::Error; use std::io::Write; use std::path::PathBuf; -use clap::App; +use clap::Command; /// Generator trait which can be used to write generators pub trait Generator { @@ -22,13 +22,13 @@ pub trait Generator { /// /// ``` /// # use std::io::Write; - /// # use clap::App; + /// # use clap::Command; /// use clap_complete::Generator; /// /// pub struct Fish; /// /// impl Generator for Fish { - /// # fn generate(&self, app: &App, buf: &mut dyn Write) {} + /// # fn generate(&self, cmd: &Command, buf: &mut dyn Write) {} /// fn file_name(&self, name: &str) -> String { /// format!("{}.fish", name) /// } @@ -36,7 +36,7 @@ pub trait Generator { /// ``` fn file_name(&self, name: &str) -> String; - /// Generates output out of [`clap::App`](App). + /// Generates output out of [`clap::Command`](Command). /// /// # Panics /// @@ -44,26 +44,26 @@ pub trait Generator { /// /// # Examples /// - /// The following example generator displays the [`clap::App`](App) + /// The following example generator displays the [`clap::Command`](Command) /// as if it is printed using [`std::println`]. /// /// ``` /// use std::{io::Write, fmt::write}; - /// use clap::App; + /// use clap::Command; /// use clap_complete::Generator; /// /// pub struct ClapDebug; /// /// impl Generator for ClapDebug { - /// fn generate(&self, app: &App, buf: &mut dyn Write) { - /// write!(buf, "{}", app).unwrap(); + /// fn generate(&self, cmd: &Command, buf: &mut dyn Write) { + /// write!(buf, "{}", cmd).unwrap(); /// } /// # fn file_name(&self, name: &str) -> String { /// # name.into() /// # } /// } /// ``` - fn generate(&self, app: &App, buf: &mut dyn Write); + fn generate(&self, cmd: &Command, buf: &mut dyn Write); } /// Generate a completions file for a specified shell at compile-time. @@ -78,20 +78,20 @@ pub trait Generator { /// args. Real applications could be many multiple levels deep in subcommands, and have tens or /// potentially hundreds of arguments. /// -/// First, it helps if we separate out our `App` definition into a separate file. Whether you -/// do this as a function, or bare App definition is a matter of personal preference. +/// First, it helps if we separate out our `Command` definition into a separate file. Whether you +/// do this as a function, or bare Command definition is a matter of personal preference. /// /// ``` /// // src/cli.rs /// -/// use clap::{App, Arg}; +/// use clap::{Command, Arg}; /// -/// pub fn build_cli() -> App<'static> { -/// App::new("compl") +/// pub fn build_cli() -> Command<'static> { +/// Command::new("compl") /// .about("Tests completions") /// .arg(Arg::new("file") /// .help("some input file")) -/// .subcommand(App::new("test") +/// .subcommand(Command::new("test") /// .about("tests things") /// .arg(Arg::new("case") /// .long("case") @@ -144,10 +144,10 @@ pub trait Generator { /// Some(outdir) => outdir, /// }; /// -/// let mut app = build_cli(); +/// let mut cmd = build_cli(); /// let path = generate_to( /// Bash, -/// &mut app, // We need to specify what generator to use +/// &mut cmd, // We need to specify what generator to use /// "myapp", // We need to specify the bin name manually /// outdir, // We need to specify where to write to /// )?; @@ -166,7 +166,7 @@ pub trait Generator { /// to see the name of the files generated. pub fn generate_to( gen: G, - app: &mut clap::App, + cmd: &mut clap::Command, bin_name: S, out_dir: T, ) -> Result @@ -175,15 +175,15 @@ where S: Into, T: Into, { - app.set_bin_name(bin_name); + cmd.set_bin_name(bin_name); let out_dir = PathBuf::from(out_dir.into()); - let file_name = gen.file_name(app.get_bin_name().unwrap()); + let file_name = gen.file_name(cmd.get_bin_name().unwrap()); let path = out_dir.join(file_name); let mut file = File::create(&path)?; - _generate::(gen, app, &mut file); + _generate::(gen, cmd, &mut file); Ok(path) } @@ -222,21 +222,21 @@ where /// ```shell /// $ myapp generate-bash-completions > /usr/share/bash-completion/completions/myapp.bash /// ``` -pub fn generate(gen: G, app: &mut clap::App, bin_name: S, buf: &mut dyn Write) +pub fn generate(gen: G, cmd: &mut clap::Command, bin_name: S, buf: &mut dyn Write) where G: Generator, S: Into, { - app.set_bin_name(bin_name); - _generate::(gen, app, buf) + cmd.set_bin_name(bin_name); + _generate::(gen, cmd, buf) } -fn _generate(gen: G, app: &mut clap::App, buf: &mut dyn Write) +fn _generate(gen: G, cmd: &mut clap::Command, buf: &mut dyn Write) where G: Generator, S: Into, { - app._build_all(); + cmd._build_all(); - gen.generate(app, buf) + gen.generate(cmd, buf) } diff --git a/clap_complete/src/generator/utils.rs b/clap_complete/src/generator/utils.rs index f707b18e8ab..b8aaa4bd578 100644 --- a/clap_complete/src/generator/utils.rs +++ b/clap_complete/src/generator/utils.rs @@ -1,42 +1,42 @@ //! Helpers for writing generators -use clap::{App, Arg}; +use clap::{Arg, Command}; /// Gets all subcommands including child subcommands in the form of `("name", "bin_name")`. /// /// Subcommand `rustup toolchain install` would be converted to /// `("install", "rustup toolchain install")`. -pub fn all_subcommands(app: &App) -> Vec<(String, String)> { - let mut subcmds: Vec<_> = subcommands(app); +pub fn all_subcommands(cmd: &Command) -> Vec<(String, String)> { + let mut subcmds: Vec<_> = subcommands(cmd); - for sc_v in app.get_subcommands().map(all_subcommands) { + for sc_v in cmd.get_subcommands().map(all_subcommands) { subcmds.extend(sc_v); } subcmds } -/// Finds the subcommand [`clap::App`] from the given [`clap::App`] with the given path. +/// Finds the subcommand [`clap::Command`] from the given [`clap::Command`] with the given path. /// /// **NOTE:** `path` should not contain the root `bin_name`. -pub fn find_subcommand_with_path<'help, 'app>( - p: &'app App<'help>, +pub fn find_subcommand_with_path<'help, 'cmd>( + p: &'cmd Command<'help>, path: Vec<&str>, -) -> &'app App<'help> { - let mut app = p; +) -> &'cmd Command<'help> { + let mut cmd = p; for sc in path { - app = app.find_subcommand(sc).unwrap(); + cmd = cmd.find_subcommand(sc).unwrap(); } - app + cmd } -/// Gets subcommands of [`clap::App`] in the form of `("name", "bin_name")`. +/// Gets subcommands of [`clap::Command`] in the form of `("name", "bin_name")`. /// /// Subcommand `rustup toolchain install` would be converted to /// `("install", "rustup toolchain install")`. -pub fn subcommands(p: &App) -> Vec<(String, String)> { +pub fn subcommands(p: &Command) -> Vec<(String, String)> { debug!("subcommands: name={}", p.get_name()); debug!("subcommands: Has subcommands...{:?}", p.has_subcommands()); @@ -61,9 +61,9 @@ pub fn subcommands(p: &App) -> Vec<(String, String)> { subcmds } -/// Gets all the short options, their visible aliases and flags of a [`clap::App`]. +/// Gets all the short options, their visible aliases and flags of a [`clap::Command`]. /// Includes `h` and `V` depending on the [`clap::AppSettings`]. -pub fn shorts_and_visible_aliases(p: &App) -> Vec { +pub fn shorts_and_visible_aliases(p: &Command) -> Vec { debug!("shorts: name={}", p.get_name()); p.get_arguments() @@ -86,9 +86,9 @@ pub fn shorts_and_visible_aliases(p: &App) -> Vec { .collect() } -/// Gets all the long options, their visible aliases and flags of a [`clap::App`]. +/// Gets all the long options, their visible aliases and flags of a [`clap::Command`]. /// Includes `help` and `version` depending on the [`clap::AppSettings`]. -pub fn longs_and_visible_aliases(p: &App) -> Vec { +pub fn longs_and_visible_aliases(p: &Command) -> Vec { debug!("longs: name={}", p.get_name()); p.get_arguments() @@ -116,9 +116,9 @@ pub fn longs_and_visible_aliases(p: &App) -> Vec { .collect() } -/// Gets all the flags of a [`clap::App`](App). +/// Gets all the flags of a [`clap::Command`](Command). /// Includes `help` and `version` depending on the [`clap::AppSettings`]. -pub fn flags<'help>(p: &App<'help>) -> Vec> { +pub fn flags<'help>(p: &Command<'help>) -> Vec> { debug!("flags: name={}", p.get_name()); p.get_arguments() .filter(|a| !a.is_takes_value_set() && !a.is_positional()) @@ -132,10 +132,10 @@ mod tests { use clap::Arg; use pretty_assertions::assert_eq; - fn common_app() -> App<'static> { - App::new("myapp") + fn common_app() -> Command<'static> { + Command::new("myapp") .subcommand( - App::new("test").subcommand(App::new("config")).arg( + Command::new("test").subcommand(Command::new("config")).arg( Arg::new("file") .short('f') .short_alias('c') @@ -144,72 +144,72 @@ mod tests { .visible_alias("path"), ), ) - .subcommand(App::new("hello")) - .bin_name("my-app") + .subcommand(Command::new("hello")) + .bin_name("my-cmd") } - fn built() -> App<'static> { - let mut app = common_app(); + fn built() -> Command<'static> { + let mut cmd = common_app(); - app._build_all(); - app + cmd._build_all(); + cmd } - fn built_with_version() -> App<'static> { - let mut app = common_app().version("3.0"); + fn built_with_version() -> Command<'static> { + let mut cmd = common_app().version("3.0"); - app._build_all(); - app + cmd._build_all(); + cmd } #[test] fn test_subcommands() { - let app = built_with_version(); + let cmd = built_with_version(); assert_eq!( - subcommands(&app), + subcommands(&cmd), vec![ - ("test".to_string(), "my-app test".to_string()), - ("hello".to_string(), "my-app hello".to_string()), - ("help".to_string(), "my-app help".to_string()), + ("test".to_string(), "my-cmd test".to_string()), + ("hello".to_string(), "my-cmd hello".to_string()), + ("help".to_string(), "my-cmd help".to_string()), ] ); } #[test] fn test_all_subcommands() { - let app = built_with_version(); + let cmd = built_with_version(); assert_eq!( - all_subcommands(&app), + all_subcommands(&cmd), vec![ - ("test".to_string(), "my-app test".to_string()), - ("hello".to_string(), "my-app hello".to_string()), - ("help".to_string(), "my-app help".to_string()), - ("config".to_string(), "my-app test config".to_string()), - ("help".to_string(), "my-app test help".to_string()), + ("test".to_string(), "my-cmd test".to_string()), + ("hello".to_string(), "my-cmd hello".to_string()), + ("help".to_string(), "my-cmd help".to_string()), + ("config".to_string(), "my-cmd test config".to_string()), + ("help".to_string(), "my-cmd test help".to_string()), ] ); } #[test] fn test_find_subcommand_with_path() { - let app = built_with_version(); - let sc_app = find_subcommand_with_path(&app, "test config".split(' ').collect()); + let cmd = built_with_version(); + let sc_app = find_subcommand_with_path(&cmd, "test config".split(' ').collect()); assert_eq!(sc_app.get_name(), "config"); } #[test] fn test_flags() { - let app = built_with_version(); - let actual_flags = flags(&app); + let cmd = built_with_version(); + let actual_flags = flags(&cmd); assert_eq!(actual_flags.len(), 2); assert_eq!(actual_flags[0].get_long(), Some("help")); assert_eq!(actual_flags[1].get_long(), Some("version")); - let sc_flags = flags(find_subcommand_with_path(&app, vec!["test"])); + let sc_flags = flags(find_subcommand_with_path(&cmd, vec!["test"])); assert_eq!(sc_flags.len(), 2); assert_eq!(sc_flags[0].get_long(), Some("file")); @@ -218,13 +218,13 @@ mod tests { #[test] fn test_flag_subcommand() { - let app = built(); - let actual_flags = flags(&app); + let cmd = built(); + let actual_flags = flags(&cmd); assert_eq!(actual_flags.len(), 1); assert_eq!(actual_flags[0].get_long(), Some("help")); - let sc_flags = flags(find_subcommand_with_path(&app, vec!["test"])); + let sc_flags = flags(find_subcommand_with_path(&cmd, vec!["test"])); assert_eq!(sc_flags.len(), 2); assert_eq!(sc_flags[0].get_long(), Some("file")); @@ -233,14 +233,14 @@ mod tests { #[test] fn test_shorts() { - let app = built_with_version(); - let shorts = shorts_and_visible_aliases(&app); + let cmd = built_with_version(); + let shorts = shorts_and_visible_aliases(&cmd); assert_eq!(shorts.len(), 2); assert_eq!(shorts[0], 'h'); assert_eq!(shorts[1], 'V'); - let sc_shorts = shorts_and_visible_aliases(find_subcommand_with_path(&app, vec!["test"])); + let sc_shorts = shorts_and_visible_aliases(find_subcommand_with_path(&cmd, vec!["test"])); assert_eq!(sc_shorts.len(), 3); assert_eq!(sc_shorts[0], 'p'); @@ -250,14 +250,14 @@ mod tests { #[test] fn test_longs() { - let app = built_with_version(); - let longs = longs_and_visible_aliases(&app); + let cmd = built_with_version(); + let longs = longs_and_visible_aliases(&cmd); assert_eq!(longs.len(), 2); assert_eq!(longs[0], "help"); assert_eq!(longs[1], "version"); - let sc_longs = longs_and_visible_aliases(find_subcommand_with_path(&app, vec!["test"])); + let sc_longs = longs_and_visible_aliases(find_subcommand_with_path(&cmd, vec!["test"])); assert_eq!(sc_longs.len(), 3); assert_eq!(sc_longs[0], "path"); diff --git a/clap_complete/src/lib.rs b/clap_complete/src/lib.rs index a349efd93e7..a22ff9ac395 100644 --- a/clap_complete/src/lib.rs +++ b/clap_complete/src/lib.rs @@ -22,12 +22,12 @@ //! ## Example //! //! ```rust,no_run -//! use clap::{App, AppSettings, Arg, ValueHint}; +//! use clap::{Command, AppSettings, Arg, ValueHint}; //! use clap_complete::{generate, Generator, Shell}; //! use std::io; //! -//! fn build_cli() -> App<'static> { -//! App::new("example") +//! fn build_cli() -> Command<'static> { +//! Command::new("example") //! .arg(Arg::new("file") //! .help("some input file") //! .value_hint(ValueHint::AnyPath), @@ -39,17 +39,17 @@ //! ) //! } //! -//! fn print_completions(gen: G, app: &mut App) { -//! generate(gen, app, app.get_name().to_string(), &mut io::stdout()); +//! fn print_completions(gen: G, cmd: &mut Command) { +//! generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout()); //! } //! //! fn main() { //! let matches = build_cli().get_matches(); //! //! if let Ok(generator) = matches.value_of_t::("generator") { -//! let mut app = build_cli(); +//! let mut cmd = build_cli(); //! eprintln!("Generating completion file for {}...", generator); -//! print_completions(generator, &mut app); +//! print_completions(generator, &mut cmd); //! } //! } //! ``` diff --git a/clap_complete/src/shells/bash.rs b/clap_complete/src/shells/bash.rs index 3848437aeeb..1625d0ce9c0 100644 --- a/clap_complete/src/shells/bash.rs +++ b/clap_complete/src/shells/bash.rs @@ -13,8 +13,8 @@ impl Generator for Bash { format!("{}.bash", name) } - fn generate(&self, app: &App, buf: &mut dyn Write) { - let bin_name = app + fn generate(&self, cmd: &Command, buf: &mut dyn Write) { + let bin_name = cmd .get_bin_name() .expect("crate::generate should have set the bin_name"); @@ -62,21 +62,21 @@ complete -F _{name} -o bashdefault -o default {name} ", name = bin_name, cmd = bin_name.replace('-', "__"), - name_opts = all_options_for_path(app, bin_name), - name_opts_details = option_details_for_path(app, bin_name), - subcmds = all_subcommands(app), - subcmd_details = subcommand_details(app) + name_opts = all_options_for_path(cmd, bin_name), + name_opts_details = option_details_for_path(cmd, bin_name), + subcmds = all_subcommands(cmd), + subcmd_details = subcommand_details(cmd) ) .as_bytes() ); } } -fn all_subcommands(app: &App) -> String { +fn all_subcommands(cmd: &Command) -> String { debug!("all_subcommands"); let mut subcmds = vec![String::new()]; - let mut scs = utils::all_subcommands(app) + let mut scs = utils::all_subcommands(cmd) .iter() .map(|x| x.0.clone()) .collect::>(); @@ -97,11 +97,11 @@ fn all_subcommands(app: &App) -> String { subcmds.join("\n ") } -fn subcommand_details(app: &App) -> String { +fn subcommand_details(cmd: &Command) -> String { debug!("subcommand_details"); let mut subcmd_dets = vec![String::new()]; - let mut scs = utils::all_subcommands(app) + let mut scs = utils::all_subcommands(cmd) .iter() .map(|x| x.1.replace(' ', "__")) .collect::>(); @@ -125,19 +125,19 @@ fn subcommand_details(app: &App) -> String { return 0 ;;", subcmd = sc.replace('-', "__"), - sc_opts = all_options_for_path(app, &*sc), + sc_opts = all_options_for_path(cmd, &*sc), level = sc.split("__").map(|_| 1).sum::(), - opts_details = option_details_for_path(app, &*sc) + opts_details = option_details_for_path(cmd, &*sc) ) })); subcmd_dets.join("\n ") } -fn option_details_for_path(app: &App, path: &str) -> String { +fn option_details_for_path(cmd: &Command, path: &str) -> String { debug!("option_details_for_path: path={}", path); - let p = utils::find_subcommand_with_path(app, path.split("__").skip(1).collect()); + let p = utils::find_subcommand_with_path(cmd, path.split("__").skip(1).collect()); let mut opts = vec![String::new()]; for o in p.get_opts() { @@ -187,10 +187,10 @@ fn vals_for(o: &Arg) -> String { } } -fn all_options_for_path(app: &App, path: &str) -> String { +fn all_options_for_path(cmd: &Command, path: &str) -> String { debug!("all_options_for_path: path={}", path); - let p = utils::find_subcommand_with_path(app, path.split("__").skip(1).collect()); + let p = utils::find_subcommand_with_path(cmd, path.split("__").skip(1).collect()); let mut opts = String::new(); for short in utils::shorts_and_visible_aliases(p) { diff --git a/clap_complete/src/shells/elvish.rs b/clap_complete/src/shells/elvish.rs index 7ad4b4b4830..959372087d4 100644 --- a/clap_complete/src/shells/elvish.rs +++ b/clap_complete/src/shells/elvish.rs @@ -14,13 +14,13 @@ impl Generator for Elvish { format!("{}.elv", name) } - fn generate(&self, app: &App, buf: &mut dyn Write) { - let bin_name = app + fn generate(&self, cmd: &Command, buf: &mut dyn Write) { + let bin_name = cmd .get_bin_name() .expect("crate::generate should have set the bin_name"); let mut names = vec![]; - let subcommands_cases = generate_inner(app, "", &mut names); + let subcommands_cases = generate_inner(cmd, "", &mut names); let result = format!( r#" @@ -67,7 +67,7 @@ fn get_tooltip(help: Option<&str>, data: T) -> String { } fn generate_inner<'help>( - p: &App<'help>, + p: &Command<'help>, previous_command_name: &str, names: &mut Vec<&'help str>, ) -> String { diff --git a/clap_complete/src/shells/fish.rs b/clap_complete/src/shells/fish.rs index 3327dbc10d7..9b516084b9f 100644 --- a/clap_complete/src/shells/fish.rs +++ b/clap_complete/src/shells/fish.rs @@ -15,13 +15,13 @@ impl Generator for Fish { format!("{}.fish", name) } - fn generate(&self, app: &App, buf: &mut dyn Write) { - let bin_name = app + fn generate(&self, cmd: &Command, buf: &mut dyn Write) { + let bin_name = cmd .get_bin_name() .expect("crate::generate should have set the bin_name"); let mut buffer = String::new(); - gen_fish_inner(bin_name, &[], app, &mut buffer); + gen_fish_inner(bin_name, &[], cmd, &mut buffer); w!(buf, buffer.as_bytes()); } } @@ -31,7 +31,12 @@ fn escape_string(string: &str) -> String { string.replace('\\', "\\\\").replace('\'', "\\'") } -fn gen_fish_inner(root_command: &str, parent_commands: &[&str], app: &App, buffer: &mut String) { +fn gen_fish_inner( + root_command: &str, + parent_commands: &[&str], + cmd: &Command, + buffer: &mut String, +) { debug!("gen_fish_inner"); // example : // @@ -49,7 +54,7 @@ fn gen_fish_inner(root_command: &str, parent_commands: &[&str], app: &App, buffe let mut basic_template = format!("complete -c {}", root_command); if parent_commands.is_empty() { - if app.has_subcommands() { + if cmd.has_subcommands() { basic_template.push_str(" -n \"__fish_use_subcommand\""); } } else { @@ -60,7 +65,7 @@ fn gen_fish_inner(root_command: &str, parent_commands: &[&str], app: &App, buffe .iter() .map(|command| format!("__fish_seen_subcommand_from {}", command)) .chain( - app.get_subcommands() + cmd.get_subcommands() .map(|command| format!("not __fish_seen_subcommand_from {}", command)) ) .collect::>() @@ -72,7 +77,7 @@ fn gen_fish_inner(root_command: &str, parent_commands: &[&str], app: &App, buffe debug!("gen_fish_inner: parent_commands={:?}", parent_commands); - for option in app.get_opts() { + for option in cmd.get_opts() { let mut template = basic_template.clone(); if let Some(shorts) = option.get_short_and_visible_aliases() { @@ -97,7 +102,7 @@ fn gen_fish_inner(root_command: &str, parent_commands: &[&str], app: &App, buffe buffer.push('\n'); } - for flag in utils::flags(app) { + for flag in utils::flags(cmd) { let mut template = basic_template.clone(); if let Some(shorts) = flag.get_short_and_visible_aliases() { @@ -120,7 +125,7 @@ fn gen_fish_inner(root_command: &str, parent_commands: &[&str], app: &App, buffe buffer.push('\n'); } - for subcommand in app.get_subcommands() { + for subcommand in cmd.get_subcommands() { let mut template = basic_template.clone(); template.push_str(" -f"); @@ -135,7 +140,7 @@ fn gen_fish_inner(root_command: &str, parent_commands: &[&str], app: &App, buffe } // generate options of subcommands - for subcommand in app.get_subcommands() { + for subcommand in cmd.get_subcommands() { let mut parent_commands: Vec<_> = parent_commands.into(); parent_commands.push(subcommand.get_name()); gen_fish_inner(root_command, &parent_commands, subcommand, buffer); diff --git a/clap_complete/src/shells/powershell.rs b/clap_complete/src/shells/powershell.rs index 77a007e41e9..d35e61c7d47 100644 --- a/clap_complete/src/shells/powershell.rs +++ b/clap_complete/src/shells/powershell.rs @@ -14,13 +14,13 @@ impl Generator for PowerShell { format!("_{}.ps1", name) } - fn generate(&self, app: &App, buf: &mut dyn Write) { - let bin_name = app + fn generate(&self, cmd: &Command, buf: &mut dyn Write) { + let bin_name = cmd .get_bin_name() .expect("crate::generate should have set the bin_name"); let mut names = vec![]; - let subcommands_cases = generate_inner(app, "", &mut names); + let subcommands_cases = generate_inner(cmd, "", &mut names); let result = format!( r#" @@ -72,7 +72,7 @@ fn get_tooltip(help: Option<&str>, data: T) -> String { } fn generate_inner<'help>( - p: &App<'help>, + p: &Command<'help>, previous_command_name: &str, names: &mut Vec<&'help str>, ) -> String { diff --git a/clap_complete/src/shells/shell.rs b/clap_complete/src/shells/shell.rs index 09ad4965592..63063bb7c8b 100644 --- a/clap_complete/src/shells/shell.rs +++ b/clap_complete/src/shells/shell.rs @@ -87,13 +87,13 @@ impl Generator for Shell { } } - fn generate(&self, app: &clap::App, buf: &mut dyn std::io::Write) { + fn generate(&self, cmd: &clap::Command, buf: &mut dyn std::io::Write) { match self { - Shell::Bash => shells::Bash.generate(app, buf), - Shell::Elvish => shells::Elvish.generate(app, buf), - Shell::Fish => shells::Fish.generate(app, buf), - Shell::PowerShell => shells::PowerShell.generate(app, buf), - Shell::Zsh => shells::Zsh.generate(app, buf), + Shell::Bash => shells::Bash.generate(cmd, buf), + Shell::Elvish => shells::Elvish.generate(cmd, buf), + Shell::Fish => shells::Fish.generate(cmd, buf), + Shell::PowerShell => shells::PowerShell.generate(cmd, buf), + Shell::Zsh => shells::Zsh.generate(cmd, buf), } } } diff --git a/clap_complete/src/shells/zsh.rs b/clap_complete/src/shells/zsh.rs index e5887134868..2b785c60c7e 100644 --- a/clap_complete/src/shells/zsh.rs +++ b/clap_complete/src/shells/zsh.rs @@ -14,8 +14,8 @@ impl Generator for Zsh { format!("_{}", name) } - fn generate(&self, app: &App, buf: &mut dyn Write) { - let bin_name = app + fn generate(&self, cmd: &Command, buf: &mut dyn Write) { + let bin_name = cmd .get_bin_name() .expect("crate::generate should have set the bin_name"); @@ -46,9 +46,9 @@ _{name}() {{ _{name} \"$@\" ", name = bin_name, - initial_args = get_args_of(app, None), - subcommands = get_subcommands_of(app), - subcommand_details = subcommand_details(app) + initial_args = get_args_of(cmd, None), + subcommands = get_subcommands_of(cmd), + subcommand_details = subcommand_details(cmd) ) .as_bytes() ); @@ -82,7 +82,7 @@ _{name} \"$@\" // ) // _describe -t commands 'rustup commands' commands "$@" // -fn subcommand_details(p: &App) -> String { +fn subcommand_details(p: &Command) -> String { debug!("subcommand_details"); let bin_name = p @@ -142,12 +142,12 @@ _{bin_name_underscore}_commands() {{ // A snippet from rustup: // 'show:Show the active and installed toolchains' // 'update:Update Rust toolchains' -fn subcommands_of(p: &App) -> String { +fn subcommands_of(p: &Command) -> String { debug!("subcommands_of"); let mut segments = vec![]; - fn add_subcommands(subcommand: &App, name: &str, ret: &mut Vec) { + fn add_subcommands(subcommand: &Command, name: &str, ret: &mut Vec) { debug!("add_subcommands"); let text = format!( @@ -212,7 +212,7 @@ fn subcommands_of(p: &App) -> String { // [name_hyphen] = The full space delineated bin_name, but replace spaces with hyphens // [repeat] = From the same recursive calls, but for all subcommands // [subcommand_args] = The same as zsh::get_args_of -fn get_subcommands_of(parent: &App) -> String { +fn get_subcommands_of(parent: &Command) -> String { debug!( "get_subcommands_of: Has subcommands...{:?}", parent.has_subcommands() @@ -276,11 +276,14 @@ esac", ) } -// Get the App for a given subcommand tree. +// Get the Command for a given subcommand tree. // -// Given the bin_name "a b c" and the App for "a" this returns the "c" App. -// Given the bin_name "a b c" and the App for "b" this returns the "c" App. -fn parser_of<'help, 'app>(parent: &'app App<'help>, bin_name: &str) -> Option<&'app App<'help>> { +// Given the bin_name "a b c" and the Command for "a" this returns the "c" Command. +// Given the bin_name "a b c" and the Command for "b" this returns the "c" Command. +fn parser_of<'help, 'cmd>( + parent: &'cmd Command<'help>, + bin_name: &str, +) -> Option<&'cmd Command<'help>> { debug!("parser_of: p={}, bin_name={}", parent.get_name(), bin_name); if bin_name == parent.get_bin_name().unwrap_or(&String::new()) { @@ -316,7 +319,7 @@ fn parser_of<'help, 'app>(parent: &'app App<'help>, bin_name: &str) -> Option<&' // -C: modify the $context internal variable // -s: Allow stacking of short args (i.e. -a -b -c => -abc) // -S: Do not complete anything after '--' and treat those as argument values -fn get_args_of(parent: &App, p_global: Option<&App>) -> String { +fn get_args_of(parent: &Command, p_global: Option<&Command>) -> String { debug!("get_args_of"); let mut segments = vec![String::from("_arguments \"${_arguments_options[@]}\" \\")]; @@ -436,7 +439,7 @@ fn escape_value(string: &str) -> String { .replace(' ', "\\ ") } -fn write_opts_of(p: &App, p_global: Option<&App>) -> String { +fn write_opts_of(p: &Command, p_global: Option<&Command>) -> String { debug!("write_opts_of"); let mut ret = vec![]; @@ -501,7 +504,7 @@ fn write_opts_of(p: &App, p_global: Option<&App>) -> String { ret.join("\n") } -fn arg_conflicts(app: &App, arg: &Arg, app_global: Option<&App>) -> String { +fn arg_conflicts(cmd: &Command, arg: &Arg, app_global: Option<&Command>) -> String { fn push_conflicts(conflicts: &[&Arg], res: &mut Vec) { for conflict in conflicts { if let Some(s) = conflict.get_short() { @@ -526,7 +529,7 @@ fn arg_conflicts(app: &App, arg: &Arg, app_global: Option<&App>) -> String { push_conflicts(&conflicts, &mut res); } (_, _) => { - let conflicts = app.get_arg_conflicts_with(arg); + let conflicts = cmd.get_arg_conflicts_with(arg); if conflicts.is_empty() { return String::new(); @@ -539,7 +542,7 @@ fn arg_conflicts(app: &App, arg: &Arg, app_global: Option<&App>) -> String { format!("({})", res.join(" ")) } -fn write_flags_of(p: &App, p_global: Option<&App>) -> String { +fn write_flags_of(p: &Command, p_global: Option<&Command>) -> String { debug!("write_flags_of;"); let mut ret = vec![]; @@ -620,7 +623,7 @@ fn write_flags_of(p: &App, p_global: Option<&App>) -> String { ret.join("\n") } -fn write_positionals_of(p: &App) -> String { +fn write_positionals_of(p: &Command) -> String { debug!("write_positionals_of;"); let mut ret = vec![]; diff --git a/clap_complete/tests/completions/bash.rs b/clap_complete/tests/completions/bash.rs index eff83f480df..38f443b58f2 100644 --- a/clap_complete/tests/completions/bash.rs +++ b/clap_complete/tests/completions/bash.rs @@ -1,11 +1,11 @@ use super::*; -fn build_app() -> App<'static> { +fn build_app() -> Command<'static> { build_app_with_name("myapp") } -fn build_app_with_name(s: &'static str) -> App<'static> { - App::new(s) +fn build_app_with_name(s: &'static str) -> Command<'static> { + Command::new(s) .version("3.0") .propagate_version(true) .about("Tests completions") @@ -16,7 +16,7 @@ fn build_app_with_name(s: &'static str) -> App<'static> { ) .arg(Arg::new("choice").possible_values(["first", "second"])) .subcommand( - App::new("test").about("tests things").arg( + Command::new("test").about("tests things").arg( Arg::new("case") .long("case") .takes_value(true) @@ -27,8 +27,8 @@ fn build_app_with_name(s: &'static str) -> App<'static> { #[test] fn bash() { - let mut app = build_app(); - common(Bash, &mut app, "myapp", BASH); + let mut cmd = build_app(); + common(Bash, &mut cmd, "myapp", BASH); } static BASH: &str = r#"_myapp() { @@ -111,21 +111,21 @@ complete -F _myapp -o bashdefault -o default myapp #[test] fn bash_with_special_commands() { - let mut app = build_app_special_commands(); - common(Bash, &mut app, "my_app", BASH_SPECIAL_CMDS); + let mut cmd = build_app_special_commands(); + common(Bash, &mut cmd, "my_app", BASH_SPECIAL_CMDS); } -fn build_app_special_commands() -> App<'static> { +fn build_app_special_commands() -> Command<'static> { build_app_with_name("my_app") .subcommand( - App::new("some_cmd").about("tests other things").arg( + Command::new("some_cmd").about("tests other things").arg( Arg::new("config") .long("--config") .takes_value(true) .help("the other case to test"), ), ) - .subcommand(App::new("some-cmd-with-hyphens").alias("hyphen")) + .subcommand(Command::new("some-cmd-with-hyphens").alias("hyphen")) } static BASH_SPECIAL_CMDS: &str = r#"_my_app() { @@ -246,12 +246,12 @@ complete -F _my_app -o bashdefault -o default my_app #[test] fn bash_with_aliases() { - let mut app = build_app_with_aliases(); - common(Bash, &mut app, "cmd", BASH_ALIASES); + let mut cmd = build_app_with_aliases(); + common(Bash, &mut cmd, "cmd", BASH_ALIASES); } -fn build_app_with_aliases() -> App<'static> { - App::new("cmd") +fn build_app_with_aliases() -> Command<'static> { + Command::new("cmd") .version("3.0") .about("testing bash completions") .arg( diff --git a/clap_complete/tests/completions/elvish.rs b/clap_complete/tests/completions/elvish.rs index 0926a1606f8..87d743e7a7e 100644 --- a/clap_complete/tests/completions/elvish.rs +++ b/clap_complete/tests/completions/elvish.rs @@ -1,11 +1,11 @@ use super::*; -fn build_app() -> App<'static> { +fn build_app() -> Command<'static> { build_app_with_name("myapp") } -fn build_app_with_name(s: &'static str) -> App<'static> { - App::new(s) +fn build_app_with_name(s: &'static str) -> Command<'static> { + Command::new(s) .version("3.0") .propagate_version(true) .about("Tests completions") @@ -15,7 +15,7 @@ fn build_app_with_name(s: &'static str) -> App<'static> { .help("some input file"), ) .subcommand( - App::new("test").about("tests things").arg( + Command::new("test").about("tests things").arg( Arg::new("case") .long("case") .takes_value(true) @@ -26,8 +26,8 @@ fn build_app_with_name(s: &'static str) -> App<'static> { #[test] fn elvish() { - let mut app = build_app(); - common(Elvish, &mut app, "my_app", ELVISH); + let mut cmd = build_app(); + common(Elvish, &mut cmd, "my_app", ELVISH); } static ELVISH: &str = r#" @@ -73,21 +73,21 @@ set edit:completion:arg-completer[my_app] = {|@words| #[test] fn elvish_with_special_commands() { - let mut app = build_app_special_commands(); - common(Elvish, &mut app, "my_app", ELVISH_SPECIAL_CMDS); + let mut cmd = build_app_special_commands(); + common(Elvish, &mut cmd, "my_app", ELVISH_SPECIAL_CMDS); } -fn build_app_special_commands() -> App<'static> { +fn build_app_special_commands() -> Command<'static> { build_app_with_name("my_app") .subcommand( - App::new("some_cmd").about("tests other things").arg( + Command::new("some_cmd").about("tests other things").arg( Arg::new("config") .long("--config") .takes_value(true) .help("the other case to test"), ), ) - .subcommand(App::new("some-cmd-with-hyphens").alias("hyphen")) + .subcommand(Command::new("some-cmd-with-hyphens").alias("hyphen")) } static ELVISH_SPECIAL_CMDS: &str = r#" @@ -148,12 +148,12 @@ set edit:completion:arg-completer[my_app] = {|@words| #[test] fn elvish_with_aliases() { - let mut app = build_app_with_aliases(); - common(Elvish, &mut app, "cmd", ELVISH_ALIASES); + let mut cmd = build_app_with_aliases(); + common(Elvish, &mut cmd, "cmd", ELVISH_ALIASES); } -fn build_app_with_aliases() -> App<'static> { - App::new("cmd") +fn build_app_with_aliases() -> Command<'static> { + Command::new("cmd") .version("3.0") .about("testing bash completions") .arg( diff --git a/clap_complete/tests/completions/fish.rs b/clap_complete/tests/completions/fish.rs index beb0ae39c6e..2ef930e8ef9 100644 --- a/clap_complete/tests/completions/fish.rs +++ b/clap_complete/tests/completions/fish.rs @@ -2,12 +2,12 @@ use clap::PossibleValue; use super::*; -fn build_app() -> App<'static> { +fn build_app() -> Command<'static> { build_app_with_name("myapp") } -fn build_app_with_name(s: &'static str) -> App<'static> { - App::new(s) +fn build_app_with_name(s: &'static str) -> Command<'static> { + Command::new(s) .version("3.0") .propagate_version(true) .about("Tests completions") @@ -17,7 +17,7 @@ fn build_app_with_name(s: &'static str) -> App<'static> { .help("some input file"), ) .subcommand( - App::new("test").about("tests things").arg( + Command::new("test").about("tests things").arg( Arg::new("case") .long("case") .takes_value(true) @@ -28,8 +28,8 @@ fn build_app_with_name(s: &'static str) -> App<'static> { #[test] fn fish() { - let mut app = build_app(); - common(Fish, &mut app, "myapp", FISH); + let mut cmd = build_app(); + common(Fish, &mut cmd, "myapp", FISH); } static FISH: &str = r#"complete -c myapp -n "__fish_use_subcommand" -s h -l help -d 'Print help information' @@ -43,21 +43,21 @@ complete -c myapp -n "__fish_seen_subcommand_from test" -s V -l version -d 'Prin #[test] fn fish_with_special_commands() { - let mut app = build_app_special_commands(); - common(Fish, &mut app, "my_app", FISH_SPECIAL_CMDS); + let mut cmd = build_app_special_commands(); + common(Fish, &mut cmd, "my_app", FISH_SPECIAL_CMDS); } -fn build_app_special_commands() -> App<'static> { +fn build_app_special_commands() -> Command<'static> { build_app_with_name("my_app") .subcommand( - App::new("some_cmd").about("tests other things").arg( + Command::new("some_cmd").about("tests other things").arg( Arg::new("config") .long("--config") .takes_value(true) .help("the other case to test"), ), ) - .subcommand(App::new("some-cmd-with-hyphens").alias("hyphen")) + .subcommand(Command::new("some-cmd-with-hyphens").alias("hyphen")) } static FISH_SPECIAL_CMDS: &str = r#"complete -c my_app -n "__fish_use_subcommand" -s h -l help -d 'Print help information' @@ -78,12 +78,12 @@ complete -c my_app -n "__fish_seen_subcommand_from some-cmd-with-hyphens" -s V - #[test] fn fish_with_special_help() { - let mut app = build_app_special_help(); - common(Fish, &mut app, "my_app", FISH_SPECIAL_HELP); + let mut cmd = build_app_special_help(); + common(Fish, &mut cmd, "my_app", FISH_SPECIAL_HELP); } -fn build_app_special_help() -> App<'static> { - App::new("my_app") +fn build_app_special_help() -> Command<'static> { + Command::new("my_app") .version("3.0") .arg( Arg::new("single-quotes") @@ -125,12 +125,12 @@ complete -c my_app -l expansions -d 'Execute the shell command with $SHELL' #[test] fn fish_with_aliases() { - let mut app = build_app_with_aliases(); - common(Fish, &mut app, "cmd", FISH_ALIASES); + let mut cmd = build_app_with_aliases(); + common(Fish, &mut cmd, "cmd", FISH_ALIASES); } -fn build_app_with_aliases() -> App<'static> { - App::new("cmd") +fn build_app_with_aliases() -> Command<'static> { + Command::new("cmd") .version("3.0") .about("testing bash completions") .arg( @@ -161,16 +161,16 @@ complete -c cmd -s f -s F -l flag -l flg -d 'cmd flag' #[test] fn fish_with_sub_subcommands() { - let mut app = build_app_sub_subcommands(); - common(Fish, &mut app, "my_app", FISH_SUB_SUBCMDS); + let mut cmd = build_app_sub_subcommands(); + common(Fish, &mut cmd, "my_app", FISH_SUB_SUBCMDS); } -fn build_app_sub_subcommands() -> App<'static> { +fn build_app_sub_subcommands() -> Command<'static> { build_app_with_name("my_app").subcommand( - App::new("some_cmd") + Command::new("some_cmd") .about("top level subcommand") .subcommand( - App::new("sub_cmd").about("sub-subcommand").arg( + Command::new("sub_cmd").about("sub-subcommand").arg( Arg::new("config") .long("--config") .takes_value(true) diff --git a/clap_complete/tests/completions/mod.rs b/clap_complete/tests/completions/mod.rs index f3b947a8938..2f326c47e93 100644 --- a/clap_complete/tests/completions/mod.rs +++ b/clap_complete/tests/completions/mod.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg, ValueHint}; +use clap::{Arg, Command, ValueHint}; use clap_complete::{generate, shells::*, Generator}; use std::fmt; @@ -23,9 +23,9 @@ macro_rules! assert_eq { }; } -pub fn common(gen: G, app: &mut App, name: &str, fixture: &str) { +pub fn common(gen: G, cmd: &mut Command, name: &str, fixture: &str) { let mut buf = vec![]; - generate(gen, app, name, &mut buf); + generate(gen, cmd, name, &mut buf); let string = String::from_utf8(buf).unwrap(); assert_eq!(&string, fixture); diff --git a/clap_complete/tests/completions/powershell.rs b/clap_complete/tests/completions/powershell.rs index 914ba89def3..290eeb7d613 100644 --- a/clap_complete/tests/completions/powershell.rs +++ b/clap_complete/tests/completions/powershell.rs @@ -1,11 +1,11 @@ use super::*; -fn build_app() -> App<'static> { +fn build_app() -> Command<'static> { build_app_with_name("myapp") } -fn build_app_with_name(s: &'static str) -> App<'static> { - App::new(s) +fn build_app_with_name(s: &'static str) -> Command<'static> { + Command::new(s) .version("3.0") .propagate_version(true) .about("Tests completions") @@ -23,7 +23,7 @@ fn build_app_with_name(s: &'static str) -> App<'static> { .visible_alias("conf"), ) .subcommand( - App::new("test").about("tests things").arg( + Command::new("test").about("tests things").arg( Arg::new("case") .long("case") .takes_value(true) @@ -34,8 +34,8 @@ fn build_app_with_name(s: &'static str) -> App<'static> { #[test] fn powershell() { - let mut app = build_app(); - common(PowerShell, &mut app, "my_app", POWERSHELL); + let mut cmd = build_app(); + common(PowerShell, &mut cmd, "my_app", POWERSHELL); } static POWERSHELL: &str = r#" @@ -93,21 +93,21 @@ Register-ArgumentCompleter -Native -CommandName 'my_app' -ScriptBlock { #[test] fn powershell_with_special_commands() { - let mut app = build_app_special_commands(); - common(PowerShell, &mut app, "my_app", POWERSHELL_SPECIAL_CMDS); + let mut cmd = build_app_special_commands(); + common(PowerShell, &mut cmd, "my_app", POWERSHELL_SPECIAL_CMDS); } -fn build_app_special_commands() -> App<'static> { +fn build_app_special_commands() -> Command<'static> { build_app_with_name("my_app") .subcommand( - App::new("some_cmd").about("tests other things").arg( + Command::new("some_cmd").about("tests other things").arg( Arg::new("config") .long("--config") .takes_value(true) .help("the other case to test"), ), ) - .subcommand(App::new("some-cmd-with-hyphens").alias("hyphen")) + .subcommand(Command::new("some-cmd-with-hyphens").alias("hyphen")) } static POWERSHELL_SPECIAL_CMDS: &str = r#" @@ -182,12 +182,12 @@ Register-ArgumentCompleter -Native -CommandName 'my_app' -ScriptBlock { #[test] fn powershell_with_aliases() { - let mut app = build_app_with_aliases(); - common(PowerShell, &mut app, "cmd", POWERSHELL_ALIASES); + let mut cmd = build_app_with_aliases(); + common(PowerShell, &mut cmd, "cmd", POWERSHELL_ALIASES); } -fn build_app_with_aliases() -> App<'static> { - App::new("cmd") +fn build_app_with_aliases() -> Command<'static> { + Command::new("cmd") .version("3.0") .about("testing bash completions") .arg( diff --git a/clap_complete/tests/completions/zsh.rs b/clap_complete/tests/completions/zsh.rs index 73dbc43bcc8..6bec6195b90 100644 --- a/clap_complete/tests/completions/zsh.rs +++ b/clap_complete/tests/completions/zsh.rs @@ -1,11 +1,11 @@ use super::*; -fn build_app() -> App<'static> { +fn build_app() -> Command<'static> { build_app_with_name("myapp") } -fn build_app_with_name(s: &'static str) -> App<'static> { - App::new(s) +fn build_app_with_name(s: &'static str) -> Command<'static> { + Command::new(s) .version("3.0") .propagate_version(true) .about("Test test's completions") @@ -15,7 +15,7 @@ fn build_app_with_name(s: &'static str) -> App<'static> { .help("some input's file"), ) .subcommand( - App::new("test").about("test test's things").arg( + Command::new("test").about("test test's things").arg( Arg::new("case") .long("case") .takes_value(true) @@ -26,8 +26,8 @@ fn build_app_with_name(s: &'static str) -> App<'static> { #[test] fn zsh() { - let mut app = build_app(); - common(Zsh, &mut app, "myapp", ZSH); + let mut cmd = build_app(); + common(Zsh, &mut cmd, "myapp", ZSH); } static ZSH: &str = r#"#compdef myapp @@ -104,23 +104,23 @@ _myapp "$@" #[test] fn zsh_with_special_commands() { - let mut app = build_app_special_commands(); - common(Zsh, &mut app, "my_app", ZSH_SPECIAL_CMDS); + let mut cmd = build_app_special_commands(); + common(Zsh, &mut cmd, "my_app", ZSH_SPECIAL_CMDS); } -fn build_app_special_commands() -> App<'static> { +fn build_app_special_commands() -> Command<'static> { build_app_with_name("my_app") .subcommand( - App::new("some_cmd").about("tests other things").arg( + Command::new("some_cmd").about("tests other things").arg( Arg::new("config") .long("--config") .takes_value(true) .help("the other case to test"), ), ) - .subcommand(App::new("some-cmd-with-hypens").alias("hyphen")) + .subcommand(Command::new("some-cmd-with-hypens").alias("hyphen")) .subcommand( - App::new("some_cmd_with_special_characters") + Command::new("some_cmd_with_special_characters") .about("This 'is' a \"special\" [character] string \\"), ) } @@ -242,12 +242,12 @@ _my_app "$@" #[test] fn zsh_with_special_help() { - let mut app = build_app_special_help(); - common(Zsh, &mut app, "my_app", ZSH_SPECIAL_HELP); + let mut cmd = build_app_special_help(); + common(Zsh, &mut cmd, "my_app", ZSH_SPECIAL_HELP); } -fn build_app_special_help() -> App<'static> { - App::new("my_app") +fn build_app_special_help() -> Command<'static> { + Command::new("my_app") .version("3.0") .arg( Arg::new("single-quotes") @@ -318,14 +318,14 @@ _my_app "$@" #[test] fn zsh_with_nested_subcommands() { - let mut app = build_app_nested_subcommands(); - common(Zsh, &mut app, "my_app", ZSH_NESTED_SUBCOMMANDS); + let mut cmd = build_app_nested_subcommands(); + common(Zsh, &mut cmd, "my_app", ZSH_NESTED_SUBCOMMANDS); } -fn build_app_nested_subcommands() -> App<'static> { - App::new("first") +fn build_app_nested_subcommands() -> Command<'static> { + Command::new("first") .version("3.0") - .subcommand(App::new("second").subcommand(App::new("third"))) + .subcommand(Command::new("second").subcommand(Command::new("third"))) } static ZSH_NESTED_SUBCOMMANDS: &str = r#"#compdef my_app @@ -438,12 +438,12 @@ _my_app "$@" #[test] fn zsh_with_aliases() { - let mut app = build_app_with_aliases(); - common(Zsh, &mut app, "cmd", ZSH_ALIASES); + let mut cmd = build_app_with_aliases(); + common(Zsh, &mut cmd, "cmd", ZSH_ALIASES); } -fn build_app_with_aliases() -> App<'static> { - App::new("cmd") +fn build_app_with_aliases() -> Command<'static> { + Command::new("cmd") .version("3.0") .about("testing bash completions") .arg( @@ -510,12 +510,12 @@ _cmd "$@" #[test] fn zsh_with_files_and_dirs() { - let mut app = build_app_with_files_and_dirs(); - common(Zsh, &mut app, "my_app", ZSH_PATHS); + let mut cmd = build_app_with_files_and_dirs(); + common(Zsh, &mut cmd, "my_app", ZSH_PATHS); } -fn build_app_with_files_and_dirs() -> App<'static> { - App::new("my_app") +fn build_app_with_files_and_dirs() -> Command<'static> { + Command::new("my_app") .version("3.0") .about("testing zsh completions") .arg( diff --git a/clap_complete/tests/generate_completions.rs b/clap_complete/tests/generate_completions.rs index cfafe477ce5..f71ceb35a8f 100644 --- a/clap_complete/tests/generate_completions.rs +++ b/clap_complete/tests/generate_completions.rs @@ -1,23 +1,23 @@ use std::io; -use clap::{App, Arg}; +use clap::{Arg, Command}; use clap_complete::{generate, shells::*}; #[test] fn generate_completions() { - let mut app = App::new("test_app") + let mut cmd = Command::new("test_app") .arg(Arg::new("config").short('c').global(true)) .arg(Arg::new("v").short('v').conflicts_with("config")) .subcommand( - App::new("test") + Command::new("test") .about("Subcommand") .arg(Arg::new("debug").short('d')), ); - generate(Bash, &mut app, "test_app", &mut io::sink()); - generate(Fish, &mut app, "test_app", &mut io::sink()); - generate(PowerShell, &mut app, "test_app", &mut io::sink()); - generate(Elvish, &mut app, "test_app", &mut io::sink()); - generate(Zsh, &mut app, "test_app", &mut io::sink()); + generate(Bash, &mut cmd, "test_app", &mut io::sink()); + generate(Fish, &mut cmd, "test_app", &mut io::sink()); + generate(PowerShell, &mut cmd, "test_app", &mut io::sink()); + generate(Elvish, &mut cmd, "test_app", &mut io::sink()); + generate(Zsh, &mut cmd, "test_app", &mut io::sink()); } diff --git a/clap_complete/tests/value_hints.rs b/clap_complete/tests/value_hints.rs index 60b586b15e8..55ea9af6a9e 100644 --- a/clap_complete/tests/value_hints.rs +++ b/clap_complete/tests/value_hints.rs @@ -1,12 +1,12 @@ mod completions; -use clap::{App, Arg, ValueHint}; +use clap::{Arg, Command, ValueHint}; use clap_complete::shells::*; use completions::common; -pub fn build_app_with_value_hints() -> App<'static> { - App::new("my_app") +pub fn build_app_with_value_hints() -> Command<'static> { + Command::new("my_app") .trailing_var_arg(true) .arg( Arg::new("choice") @@ -149,12 +149,12 @@ complete -c my_app -l help -d 'Print help information' #[test] fn zsh_with_value_hints() { - let mut app = build_app_with_value_hints(); - common(Zsh, &mut app, "my_app", ZSH_VALUE_HINTS); + let mut cmd = build_app_with_value_hints(); + common(Zsh, &mut cmd, "my_app", ZSH_VALUE_HINTS); } #[test] fn fish_with_value_hints() { - let mut app = build_app_with_value_hints(); - common(Fish, &mut app, "my_app", FISH_VALUE_HINTS); + let mut cmd = build_app_with_value_hints(); + common(Fish, &mut cmd, "my_app", FISH_VALUE_HINTS); } diff --git a/clap_complete_fig/examples/fig_completion.rs b/clap_complete_fig/examples/fig_completion.rs index d3907b74e5b..e6d57b0aa2f 100644 --- a/clap_complete_fig/examples/fig_completion.rs +++ b/clap_complete_fig/examples/fig_completion.rs @@ -1,12 +1,12 @@ -use clap::App; +use clap::Command; use clap_complete::generate; use clap_complete_fig::Fig; use std::io; fn main() { - let mut app = App::new("myapp") - .subcommand(App::new("test").subcommand(App::new("config"))) - .subcommand(App::new("hello")); + let mut cmd = Command::new("myapp") + .subcommand(Command::new("test").subcommand(Command::new("config"))) + .subcommand(Command::new("hello")); - generate(Fig, &mut app, "myapp", &mut io::stdout()); + generate(Fig, &mut cmd, "myapp", &mut io::stdout()); } diff --git a/clap_complete_fig/src/fig.rs b/clap_complete_fig/src/fig.rs index 95c3ef467f5..ea2e18e9f63 100644 --- a/clap_complete_fig/src/fig.rs +++ b/clap_complete_fig/src/fig.rs @@ -13,8 +13,8 @@ impl Generator for Fig { format!("{}.ts", name) } - fn generate(&self, app: &App, buf: &mut dyn Write) { - let command = app.get_bin_name().unwrap(); + fn generate(&self, cmd: &Command, buf: &mut dyn Write) { + let command = cmd.get_bin_name().unwrap(); let mut buffer = String::new(); buffer.push_str(&format!( @@ -24,10 +24,10 @@ impl Generator for Fig { buffer.push_str(&format!( " description: \"{}\",\n", - app.get_about().unwrap_or_default() + cmd.get_about().unwrap_or_default() )); - gen_fig_inner(command, &[], 2, app, &mut buffer); + gen_fig_inner(command, &[], 2, cmd, &mut buffer); buffer.push_str("};\n\nexport default completion;\n"); @@ -45,13 +45,13 @@ fn gen_fig_inner( root_command: &str, parent_commands: &[&str], indent: usize, - app: &App, + cmd: &Command, buffer: &mut String, ) { - if app.has_subcommands() { + if cmd.has_subcommands() { buffer.push_str(&format!("{:indent$}subcommands: [\n", "", indent = indent)); // generate subcommands - for subcommand in app.get_subcommands() { + for subcommand in cmd.get_subcommands() { buffer.push_str(&format!( "{:indent$}{{\n{:indent$} name: \"{}\",\n", "", @@ -84,9 +84,9 @@ fn gen_fig_inner( buffer.push_str(&format!("{:indent$}],\n", "", indent = indent)); } - buffer.push_str(&gen_options(app, indent)); + buffer.push_str(&gen_options(cmd, indent)); - let args = app.get_positionals().collect::>(); + let args = cmd.get_positionals().collect::>(); match args.len() { 0 => {} @@ -105,12 +105,12 @@ fn gen_fig_inner( }; } -fn gen_options(app: &App, indent: usize) -> String { +fn gen_options(cmd: &Command, indent: usize) -> String { let mut buffer = String::new(); buffer.push_str(&format!("{:indent$}options: [\n", "", indent = indent)); - for option in app.get_opts() { + for option in cmd.get_opts() { buffer.push_str(&format!("{:indent$}{{\n", "", indent = indent + 2)); let mut names = vec![]; @@ -160,7 +160,7 @@ fn gen_options(app: &App, indent: usize) -> String { buffer.push_str(&format!("{:indent$}}},\n", "", indent = indent + 2)); } - for flag in generator::utils::flags(app) { + for flag in generator::utils::flags(cmd) { buffer.push_str(&format!("{:indent$}{{\n", "", indent = indent + 2)); let mut flags = vec![]; diff --git a/clap_complete_fig/tests/completions/fig.rs b/clap_complete_fig/tests/completions/fig.rs index 4e7860ea425..e06790b9558 100644 --- a/clap_complete_fig/tests/completions/fig.rs +++ b/clap_complete_fig/tests/completions/fig.rs @@ -1,12 +1,12 @@ use super::*; use crate::Fig; -fn build_app() -> App<'static> { +fn build_app() -> Command<'static> { build_app_with_name("myapp") } -fn build_app_with_name(s: &'static str) -> App<'static> { - App::new(s) +fn build_app_with_name(s: &'static str) -> Command<'static> { + Command::new(s) .version("3.0") .propagate_version(true) .about("Tests completions") @@ -16,7 +16,7 @@ fn build_app_with_name(s: &'static str) -> App<'static> { .help("some input file"), ) .subcommand( - App::new("test").about("tests things").arg( + Command::new("test").about("tests things").arg( Arg::new("case") .long("case") .takes_value(true) @@ -27,8 +27,8 @@ fn build_app_with_name(s: &'static str) -> App<'static> { #[test] fn fig() { - let mut app = build_app(); - common(Fig, &mut app, "myapp", FIG); + let mut cmd = build_app(); + common(Fig, &mut cmd, "myapp", FIG); } static FIG: &str = r#"const completion: Fig.Spec = { @@ -90,21 +90,21 @@ export default completion; #[test] fn fig_with_special_commands() { - let mut app = build_app_special_commands(); - common(Fig, &mut app, "my_app", FIG_SPECIAL_CMDS); + let mut cmd = build_app_special_commands(); + common(Fig, &mut cmd, "my_app", FIG_SPECIAL_CMDS); } -fn build_app_special_commands() -> App<'static> { +fn build_app_special_commands() -> Command<'static> { build_app_with_name("my_app") .subcommand( - App::new("some_cmd").about("tests other things").arg( + Command::new("some_cmd").about("tests other things").arg( Arg::new("config") .long("--config") .takes_value(true) .help("the other case to test"), ), ) - .subcommand(App::new("some-cmd-with-hyphens").alias("hyphen")) + .subcommand(Command::new("some-cmd-with-hyphens").alias("hyphen")) } static FIG_SPECIAL_CMDS: &str = r#"const completion: Fig.Spec = { @@ -201,12 +201,12 @@ export default completion; #[test] fn fig_with_special_help() { - let mut app = build_app_special_help(); - common(Fig, &mut app, "my_app", FIG_SPECIAL_HELP); + let mut cmd = build_app_special_help(); + common(Fig, &mut cmd, "my_app", FIG_SPECIAL_HELP); } -fn build_app_special_help() -> App<'static> { - App::new("my_app") +fn build_app_special_help() -> Command<'static> { + Command::new("my_app") .version("3.0") .arg( Arg::new("single-quotes") @@ -280,12 +280,12 @@ export default completion; #[test] fn fig_with_aliases() { - let mut app = build_app_with_aliases(); - common(Fig, &mut app, "cmd", FIG_ALIASES); + let mut cmd = build_app_with_aliases(); + common(Fig, &mut cmd, "cmd", FIG_ALIASES); } -fn build_app_with_aliases() -> App<'static> { - App::new("cmd") +fn build_app_with_aliases() -> Command<'static> { + Command::new("cmd") .version("3.0") .about("testing bash completions") .arg( @@ -344,16 +344,16 @@ export default completion; #[test] fn fig_with_sub_subcommands() { - let mut app = build_app_sub_subcommands(); - common(Fig, &mut app, "my_app", FIG_SUB_SUBCMDS); + let mut cmd = build_app_sub_subcommands(); + common(Fig, &mut cmd, "my_app", FIG_SUB_SUBCMDS); } -fn build_app_sub_subcommands() -> App<'static> { +fn build_app_sub_subcommands() -> Command<'static> { build_app_with_name("my_app").subcommand( - App::new("some_cmd") + Command::new("some_cmd") .about("top level subcommand") .subcommand( - App::new("sub_cmd").about("sub-subcommand").arg( + Command::new("sub_cmd").about("sub-subcommand").arg( Arg::new("config") .long("--config") .takes_value(true) diff --git a/clap_complete_fig/tests/completions/mod.rs b/clap_complete_fig/tests/completions/mod.rs index f2923d8c2ff..4368c063a3c 100644 --- a/clap_complete_fig/tests/completions/mod.rs +++ b/clap_complete_fig/tests/completions/mod.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg, ValueHint}; +use clap::{Arg, Command, ValueHint}; use clap_complete::{generate, Generator}; use std::fmt; @@ -19,9 +19,9 @@ macro_rules! assert_eq { }; } -pub fn common(gen: G, app: &mut App, name: &str, fixture: &str) { +pub fn common(gen: G, cmd: &mut Command, name: &str, fixture: &str) { let mut buf = vec![]; - generate(gen, app, name, &mut buf); + generate(gen, cmd, name, &mut buf); let string = String::from_utf8(buf).unwrap(); assert_eq!(&string, fixture); diff --git a/clap_complete_fig/tests/generate_completions.rs b/clap_complete_fig/tests/generate_completions.rs index 3e6d9cc2f1d..99a7f665b22 100644 --- a/clap_complete_fig/tests/generate_completions.rs +++ b/clap_complete_fig/tests/generate_completions.rs @@ -1,18 +1,18 @@ -use clap::{App, Arg}; +use clap::{Arg, Command}; use clap_complete::generate; use clap_complete_fig::Fig; use std::io; #[test] fn generate_completions() { - let mut app = App::new("test_app") + let mut cmd = Command::new("test_app") .arg(Arg::new("config").short('c').global(true)) .arg(Arg::new("v").short('v').conflicts_with("config")) .subcommand( - App::new("test") + Command::new("test") .about("Subcommand") .arg(Arg::new("debug").short('d')), ); - generate(Fig, &mut app, "test_app", &mut io::sink()); + generate(Fig, &mut cmd, "test_app", &mut io::sink()); } diff --git a/clap_complete_fig/tests/value_hints.rs b/clap_complete_fig/tests/value_hints.rs index 15fa4e235aa..08388f082ce 100644 --- a/clap_complete_fig/tests/value_hints.rs +++ b/clap_complete_fig/tests/value_hints.rs @@ -1,11 +1,11 @@ -use clap::{App, Arg, ValueHint}; +use clap::{Arg, Command, ValueHint}; use clap_complete_fig::Fig; use completions::common; mod completions; -pub fn build_app_with_value_hints() -> App<'static> { - App::new("my_app") +pub fn build_app_with_value_hints() -> Command<'static> { + Command::new("my_app") .disable_version_flag(true) .trailing_var_arg(true) .arg( @@ -210,6 +210,6 @@ export default completion; #[test] fn fig_with_value_hints() { - let mut app = build_app_with_value_hints(); - common(Fig, &mut app, "my_app", FIG_VALUE_HINTS); + let mut cmd = build_app_with_value_hints(); + common(Fig, &mut cmd, "my_app", FIG_VALUE_HINTS); } diff --git a/clap_derive/src/derives/args.rs b/clap_derive/src/derives/args.rs index 3bdd32010ee..077fe4a64dd 100644 --- a/clap_derive/src/derives/args.rs +++ b/clap_derive/src/derives/args.rs @@ -87,10 +87,10 @@ pub fn gen_for_struct( )] #[deny(clippy::correctness)] impl #impl_generics clap::Args for #struct_name #ty_generics #where_clause { - fn augment_args<'b>(#app_var: clap::App<'b>) -> clap::App<'b> { + fn augment_args<'b>(#app_var: clap::Command<'b>) -> clap::Command<'b> { #augmentation } - fn augment_args_for_update<'b>(#app_var: clap::App<'b>) -> clap::App<'b> { + fn augment_args_for_update<'b>(#app_var: clap::Command<'b>) -> clap::Command<'b> { #augmentation_update } } @@ -145,7 +145,7 @@ pub fn gen_from_arg_matches_for_struct( } /// Generate a block of code to add arguments/subcommands corresponding to -/// the `fields` to an app. +/// the `fields` to an cmd. pub fn gen_augment( fields: &Punctuated, app_var: &Ident, diff --git a/clap_derive/src/derives/into_app.rs b/clap_derive/src/derives/into_app.rs index 3df12f5b39e..cae57ea15a2 100644 --- a/clap_derive/src/derives/into_app.rs +++ b/clap_derive/src/derives/into_app.rs @@ -57,13 +57,13 @@ pub fn gen_for_struct( )] #[deny(clippy::correctness)] impl #impl_generics clap::IntoApp for #struct_name #ty_generics #where_clause { - fn into_app<'b>() -> clap::App<'b> { - let #app_var = clap::App::new(#name); + fn into_app<'b>() -> clap::Command<'b> { + let #app_var = clap::Command::new(#name); ::augment_args(#app_var) } - fn into_app_for_update<'b>() -> clap::App<'b> { - let #app_var = clap::App::new(#name); + fn into_app_for_update<'b>() -> clap::Command<'b> { + let #app_var = clap::Command::new(#name); ::augment_args_for_update(#app_var) } } @@ -102,15 +102,15 @@ pub fn gen_for_enum(enum_name: &Ident, generics: &Generics, attrs: &[Attribute]) )] #[deny(clippy::correctness)] impl #impl_generics clap::IntoApp for #enum_name #ty_generics #where_clause { - fn into_app<'b>() -> clap::App<'b> { + fn into_app<'b>() -> clap::Command<'b> { #[allow(deprecated)] - let #app_var = clap::App::new(#name) + let #app_var = clap::Command::new(#name) .setting(clap::AppSettings::SubcommandRequiredElseHelp); ::augment_subcommands(#app_var) } - fn into_app_for_update<'b>() -> clap::App<'b> { - let #app_var = clap::App::new(#name); + fn into_app_for_update<'b>() -> clap::Command<'b> { + let #app_var = clap::Command::new(#name); ::augment_subcommands_for_update(#app_var) } } diff --git a/clap_derive/src/derives/subcommand.rs b/clap_derive/src/derives/subcommand.rs index c6c7738f5c1..f8aa52c860f 100644 --- a/clap_derive/src/derives/subcommand.rs +++ b/clap_derive/src/derives/subcommand.rs @@ -75,10 +75,10 @@ pub fn gen_for_enum( )] #[deny(clippy::correctness)] impl #impl_generics clap::Subcommand for #enum_name #ty_generics #where_clause { - fn augment_subcommands <'b>(__clap_app: clap::App<'b>) -> clap::App<'b> { + fn augment_subcommands <'b>(__clap_app: clap::Command<'b>) -> clap::Command<'b> { #augmentation } - fn augment_subcommands_for_update <'b>(__clap_app: clap::App<'b>) -> clap::App<'b> { + fn augment_subcommands_for_update <'b>(__clap_app: clap::Command<'b>) -> clap::Command<'b> { #augmentation_update } fn has_subcommand(__clap_name: &str) -> bool { @@ -245,7 +245,7 @@ fn gen_augment( let final_from_attrs = attrs.final_top_level_methods(); let subcommand = quote! { let #app_var = #app_var.subcommand({ - let #subcommand_var = clap::App::new(#name); + let #subcommand_var = clap::Command::new(#name); let #subcommand_var = #subcommand_var #initial_app_methods; let #subcommand_var = #arg_block; #[allow(deprecated)] @@ -260,7 +260,7 @@ fn gen_augment( let subcommand_var = Ident::new("__clap_subcommand", Span::call_site()); let sub_augment = match variant.fields { Named(ref fields) => { - // Defer to `gen_augment` for adding app methods + // Defer to `gen_augment` for adding cmd methods args::gen_augment(&fields.named, &subcommand_var, &attrs, override_required) } Unit => { @@ -304,7 +304,7 @@ fn gen_augment( let name = attrs.cased_name(); let subcommand = quote! { let #app_var = #app_var.subcommand({ - let #subcommand_var = clap::App::new(#name); + let #subcommand_var = clap::Command::new(#name); #sub_augment }); }; diff --git a/clap_derive/src/dummies.rs b/clap_derive/src/dummies.rs index 291aba99d82..a0e0ad3e67f 100644 --- a/clap_derive/src/dummies.rs +++ b/clap_derive/src/dummies.rs @@ -19,10 +19,10 @@ pub fn parser_enum(name: &Ident) { pub fn into_app(name: &Ident) { append_dummy(quote! { impl clap::IntoApp for #name { - fn into_app<'b>() -> clap::App<'b> { + fn into_app<'b>() -> clap::Command<'b> { unimplemented!() } - fn into_app_for_update<'b>() -> clap::App<'b> { + fn into_app_for_update<'b>() -> clap::Command<'b> { unimplemented!() } } @@ -46,10 +46,10 @@ pub fn subcommand(name: &Ident) { from_arg_matches(name); append_dummy(quote! { impl clap::Subcommand for #name { - fn augment_subcommands(_app: clap::App<'_>) -> clap::App<'_> { + fn augment_subcommands(_cmd: clap::Command<'_>) -> clap::Command<'_> { unimplemented!() } - fn augment_subcommands_for_update(_app: clap::App<'_>) -> clap::App<'_> { + fn augment_subcommands_for_update(_cmd: clap::Command<'_>) -> clap::Command<'_> { unimplemented!() } fn has_subcommand(name: &str) -> bool { @@ -63,10 +63,10 @@ pub fn args(name: &Ident) { from_arg_matches(name); append_dummy(quote! { impl clap::Args for #name { - fn augment_args(_app: clap::App<'_>) -> clap::App<'_> { + fn augment_args(_cmd: clap::Command<'_>) -> clap::Command<'_> { unimplemented!() } - fn augment_args_for_update(_app: clap::App<'_>) -> clap::App<'_> { + fn augment_args_for_update(_cmd: clap::Command<'_>) -> clap::Command<'_> { unimplemented!() } } diff --git a/clap_derive/src/lib.rs b/clap_derive/src/lib.rs index b68f05725fd..973b61e177c 100644 --- a/clap_derive/src/lib.rs +++ b/clap_derive/src/lib.rs @@ -38,7 +38,7 @@ pub fn arg_enum(input: TokenStream) -> TokenStream { /// Generates the `Parser` implementation. /// -/// This is far less verbose than defining the `clap::App` struct manually, +/// This is far less verbose than defining the `clap::Command` struct manually, /// receiving an instance of `clap::ArgMatches` from conducting parsing, and then /// implementing a conversion code to instantiate an instance of the user /// context struct. diff --git a/clap_derive/src/parse.rs b/clap_derive/src/parse.rs index e20b9e88af8..2973cf670f4 100644 --- a/clap_derive/src/parse.rs +++ b/clap_derive/src/parse.rs @@ -266,12 +266,12 @@ fn raw_method_suggestion(ts: ParseBuffer) -> String { }; format!( - "if you need to call `clap::Arg/App::{}` method you \ + "if you need to call `clap::Arg/Command::{}` method you \ can do it like this: #[clap({}{})]", name, name, suggestion ) } else { - "if you need to call some method from `clap::Arg/App` \ + "if you need to call some method from `clap::Arg/Command` \ you should use raw method, see \ https://github.com/clap-rs/clap/blob/master/examples/derive_ref/README.md#raw-attributes" .into() diff --git a/clap_generate/src/lib.rs b/clap_generate/src/lib.rs index 841865891f3..67297be5715 100644 --- a/clap_generate/src/lib.rs +++ b/clap_generate/src/lib.rs @@ -22,7 +22,7 @@ pub mod utils { #[deprecated(since = "3.0.0", note = "Renamed to `clap_complete::generate_to`")] pub fn generate_to( gen: G, - app: &mut clap::App, + cmd: &mut clap::Command, bin_name: S, out_dir: T, ) -> Result @@ -31,14 +31,14 @@ where S: Into, T: Into, { - clap_complete::generate_to(gen, app, bin_name, out_dir) + clap_complete::generate_to(gen, cmd, bin_name, out_dir) } #[deprecated(since = "3.0.0", note = "Renamed to `clap_complete`")] -pub fn generate(gen: G, app: &mut clap::App, bin_name: S, buf: &mut dyn Write) +pub fn generate(gen: G, cmd: &mut clap::Command, bin_name: S, buf: &mut dyn Write) where G: Generator, S: Into, { - clap_complete::generate(gen, app, bin_name, buf) + clap_complete::generate(gen, cmd, bin_name, buf) } diff --git a/clap_generate/tests/warning.rs b/clap_generate/tests/warning.rs index 293b2a34618..2fbcba95022 100644 --- a/clap_generate/tests/warning.rs +++ b/clap_generate/tests/warning.rs @@ -1,23 +1,23 @@ #![allow(deprecated)] -use clap::{App, Arg}; +use clap::{Arg, Command}; use clap_generate::{generate, generators::*}; use std::io; #[test] fn generate_completions() { - let mut app = App::new("test_app") + let mut cmd = Command::new("test_app") .arg(Arg::new("config").short('c').global(true)) .arg(Arg::new("v").short('v').conflicts_with("config")) .subcommand( - App::new("test") + Command::new("test") .about("Subcommand") .arg(Arg::new("debug").short('d')), ); - generate(Bash, &mut app, "test_app", &mut io::sink()); - generate(Fish, &mut app, "test_app", &mut io::sink()); - generate(PowerShell, &mut app, "test_app", &mut io::sink()); - generate(Elvish, &mut app, "test_app", &mut io::sink()); - generate(Zsh, &mut app, "test_app", &mut io::sink()); + generate(Bash, &mut cmd, "test_app", &mut io::sink()); + generate(Fish, &mut cmd, "test_app", &mut io::sink()); + generate(PowerShell, &mut cmd, "test_app", &mut io::sink()); + generate(Elvish, &mut cmd, "test_app", &mut io::sink()); + generate(Zsh, &mut cmd, "test_app", &mut io::sink()); } diff --git a/clap_mangen/README.md b/clap_mangen/README.md index 0b5a0eebd4f..4fd66172da8 100644 --- a/clap_mangen/README.md +++ b/clap_mangen/README.md @@ -18,7 +18,7 @@ Dual-licensed under [Apache 2.0](LICENSE-APACHE) or [MIT](LICENSE-MIT). ## About -Generate [ROFF](https://en.wikipedia.org/wiki/Roff_(software)) from a `clap::App`. +Generate [ROFF](https://en.wikipedia.org/wiki/Roff_(software)) from a `clap::Command`. ### Example @@ -36,11 +36,11 @@ In your `build.rs`: fn main() -> std::io::Result<()> { let out_dir = std::path::PathBuf::from(std::env::var_os("OUT_DIR").ok_or_else(|| std::io::ErrorKind::NotFound)?); - let app = clap::App::new("mybin") + let cmd = clap::Command::new("mybin") .arg(clap::arg!(-n --name )) .arg(clap::arg!(-c --count )); - let man = clap_mangen::Man::new(app); + let man = clap_mangen::Man::new(cmd); let mut buffer: Vec = Default::default(); man.render(&mut buffer)?; diff --git a/clap_mangen/examples/man.rs b/clap_mangen/examples/man.rs index 96d267f8f53..55a4107c459 100644 --- a/clap_mangen/examples/man.rs +++ b/clap_mangen/examples/man.rs @@ -1,11 +1,11 @@ -use clap::{arg, App}; +use clap::{arg, Command}; use clap_mangen::Man; use std::io; // Run this example as `cargo run --example man | man -l -`. fn main() -> Result<(), std::io::Error> { - let app = App::new("myapp") + let cmd = Command::new("myapp") .version("1.0") .author("Kevin K. :Ola Nordmann ") .about("Does awesome things") @@ -31,10 +31,10 @@ And a few newlines.", .hide_env(true), ) .subcommand( - App::new("test") + Command::new("test") .about("does testing things") .arg(arg!(-l --list "Lists test values")), ); - Man::new(app).render(&mut io::stdout()) + Man::new(cmd).render(&mut io::stdout()) } diff --git a/clap_mangen/src/lib.rs b/clap_mangen/src/lib.rs index 60f6cd91976..3be2d52e96e 100644 --- a/clap_mangen/src/lib.rs +++ b/clap_mangen/src/lib.rs @@ -14,7 +14,7 @@ use std::io::Write; /// A manpage writer pub struct Man<'a> { - app: clap::App<'a>, + cmd: clap::Command<'a>, title: String, section: String, date: String, @@ -25,19 +25,19 @@ pub struct Man<'a> { /// Build a [`Man`] impl<'a> Man<'a> { /// Create a new manual page. - pub fn new(mut app: clap::App<'a>) -> Self { - app._build_all(); - let title = app.get_name().to_owned(); + pub fn new(mut cmd: clap::Command<'a>) -> Self { + cmd._build_all(); + let title = cmd.get_name().to_owned(); let section = "1".to_owned(); let date = "".to_owned(); let source = format!( "{} {}", - app.get_name(), - app.get_version().unwrap_or_default() + cmd.get_name(), + cmd.get_version().unwrap_or_default() ); let manual = "".to_owned(); Self { - app, + cmd, title, section, date, @@ -105,23 +105,23 @@ impl<'a> Man<'a> { self._render_synopsis_section(&mut roff); self._render_description_section(&mut roff); - if app_has_arguments(&self.app) { + if app_has_arguments(&self.cmd) { self._render_options_section(&mut roff); } - if app_has_subcommands(&self.app) { + if app_has_subcommands(&self.cmd) { self._render_subcommands_section(&mut roff); } - if self.app.get_after_long_help().is_some() || self.app.get_after_help().is_some() { + if self.cmd.get_after_long_help().is_some() || self.cmd.get_after_help().is_some() { self._render_extra_section(&mut roff); } - if app_has_version(&self.app) { + if app_has_version(&self.cmd) { self._render_version_section(&mut roff); } - if self.app.get_author().is_some() { + if self.cmd.get_author().is_some() { self._render_authors_section(&mut roff); } @@ -159,7 +159,7 @@ impl<'a> Man<'a> { fn _render_name_section(&self, roff: &mut Roff) { roff.control("SH", ["NAME"]); - render::about(roff, &self.app); + render::about(roff, &self.cmd); } /// Render the SYNOPSIS section into the writer. @@ -171,7 +171,7 @@ impl<'a> Man<'a> { fn _render_synopsis_section(&self, roff: &mut Roff) { roff.control("SH", ["SYNOPSIS"]); - render::synopsis(roff, &self.app); + render::synopsis(roff, &self.cmd); } /// Render the DESCRIPTION section into the writer. @@ -183,7 +183,7 @@ impl<'a> Man<'a> { fn _render_description_section(&self, roff: &mut Roff) { roff.control("SH", ["DESCRIPTION"]); - render::description(roff, &self.app); + render::description(roff, &self.cmd); } /// Render the OPTIONS section into the writer. @@ -195,7 +195,7 @@ impl<'a> Man<'a> { fn _render_options_section(&self, roff: &mut Roff) { roff.control("SH", ["OPTIONS"]); - render::options(roff, &self.app); + render::options(roff, &self.cmd); } /// Render the SUBCOMMANDS section into the writer. @@ -206,9 +206,9 @@ impl<'a> Man<'a> { } fn _render_subcommands_section(&self, roff: &mut Roff) { - let heading = subcommand_heading(&self.app); + let heading = subcommand_heading(&self.cmd); roff.control("SH", [heading.as_str()]); - render::subcommands(roff, &self.app, &self.section); + render::subcommands(roff, &self.cmd, &self.section); } /// Render the EXTRA section into the writer. @@ -220,7 +220,7 @@ impl<'a> Man<'a> { fn _render_extra_section(&self, roff: &mut Roff) { roff.control("SH", ["EXTRA"]); - render::after_help(roff, &self.app); + render::after_help(roff, &self.cmd); } /// Render the VERSION section into the writer. @@ -231,7 +231,7 @@ impl<'a> Man<'a> { } fn _render_version_section(&self, roff: &mut Roff) { - let version = roman(&render::version(&self.app)); + let version = roman(&render::version(&self.cmd)); roff.control("SH", ["VERSION"]); roff.text([version]); } @@ -244,25 +244,25 @@ impl<'a> Man<'a> { } fn _render_authors_section(&self, roff: &mut Roff) { - let author = roman(self.app.get_author().unwrap_or_default()); + let author = roman(self.cmd.get_author().unwrap_or_default()); roff.control("SH", ["AUTHORS"]); roff.text([author]); } } // Does the application have a version? -fn app_has_version(app: &clap::App) -> bool { - app.get_version() - .or_else(|| app.get_long_version()) +fn app_has_version(cmd: &clap::Command) -> bool { + cmd.get_version() + .or_else(|| cmd.get_long_version()) .is_some() } // Does the application have any command line arguments? -fn app_has_arguments(app: &clap::App) -> bool { - app.get_arguments().any(|i| !i.is_hide_set()) +fn app_has_arguments(cmd: &clap::Command) -> bool { + cmd.get_arguments().any(|i| !i.is_hide_set()) } // Does the application have any subcommands? -fn app_has_subcommands(app: &clap::App) -> bool { - app.get_subcommands().any(|i| !i.is_hide_set()) +fn app_has_subcommands(cmd: &clap::Command) -> bool { + cmd.get_subcommands().any(|i| !i.is_hide_set()) } diff --git a/clap_mangen/src/render.rs b/clap_mangen/src/render.rs index b6f7a70ee7d..93fa78751ed 100644 --- a/clap_mangen/src/render.rs +++ b/clap_mangen/src/render.rs @@ -1,23 +1,23 @@ use clap::AppSettings; use roff::{bold, italic, roman, Inline, Roff}; -pub(crate) fn subcommand_heading(app: &clap::App) -> String { - match app.get_subcommand_help_heading() { +pub(crate) fn subcommand_heading(cmd: &clap::Command) -> String { + match cmd.get_subcommand_help_heading() { Some(title) => title.to_string(), None => "SUBCOMMANDS".to_string(), } } -pub(crate) fn about(roff: &mut Roff, app: &clap::App) { - let s = match app.get_about().or_else(|| app.get_long_about()) { - Some(about) => format!("{} - {}", app.get_name(), about), - None => app.get_name().to_string(), +pub(crate) fn about(roff: &mut Roff, cmd: &clap::Command) { + let s = match cmd.get_about().or_else(|| cmd.get_long_about()) { + Some(about) => format!("{} - {}", cmd.get_name(), about), + None => cmd.get_name().to_string(), }; roff.text([roman(&s)]); } -pub(crate) fn description(roff: &mut Roff, app: &clap::App) { - if let Some(about) = app.get_long_about().or_else(|| app.get_about()) { +pub(crate) fn description(roff: &mut Roff, cmd: &clap::Command) { + if let Some(about) = cmd.get_long_about().or_else(|| cmd.get_about()) { for line in about.lines() { if line.trim().is_empty() { roff.control("PP", []); @@ -28,10 +28,10 @@ pub(crate) fn description(roff: &mut Roff, app: &clap::App) { } } -pub(crate) fn synopsis(roff: &mut Roff, app: &clap::App) { - let mut line = vec![bold(app.get_name()), roman(" ")]; +pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) { + let mut line = vec![bold(cmd.get_name()), roman(" ")]; - for opt in app.get_arguments() { + for opt in cmd.get_arguments() { let (lhs, rhs) = option_markers(opt); match (opt.get_short(), opt.get_long()) { (Some(short), Some(long)) => { @@ -58,7 +58,7 @@ pub(crate) fn synopsis(roff: &mut Roff, app: &clap::App) { }; } - for arg in app.get_positionals() { + for arg in cmd.get_positionals() { let (lhs, rhs) = option_markers(arg); line.push(roman(lhs)); line.push(italic(arg.get_id())); @@ -66,12 +66,12 @@ pub(crate) fn synopsis(roff: &mut Roff, app: &clap::App) { line.push(roman(" ")); } - if app.has_subcommands() { - let (lhs, rhs) = subcommand_markers(app); + if cmd.has_subcommands() { + let (lhs, rhs) = subcommand_markers(cmd); line.push(roman(lhs)); line.push(italic( - &app.get_subcommand_value_name() - .unwrap_or(&subcommand_heading(app)) + &cmd.get_subcommand_value_name() + .unwrap_or(&subcommand_heading(cmd)) .to_lowercase(), )); line.push(roman(rhs)); @@ -80,8 +80,8 @@ pub(crate) fn synopsis(roff: &mut Roff, app: &clap::App) { roff.text(line); } -pub(crate) fn options(roff: &mut Roff, app: &clap::App) { - let items: Vec<_> = app.get_arguments().filter(|i| !i.is_hide_set()).collect(); +pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) { + let items: Vec<_> = cmd.get_arguments().filter(|i| !i.is_hide_set()).collect(); for opt in items.iter().filter(|a| !a.is_positional()) { let mut body = vec![]; @@ -143,11 +143,11 @@ pub(crate) fn options(roff: &mut Roff, app: &clap::App) { } } -pub(crate) fn subcommands(roff: &mut Roff, app: &clap::App, section: &str) { - for sub in app.get_subcommands().filter(|s| !s.is_hide_set()) { +pub(crate) fn subcommands(roff: &mut Roff, cmd: &clap::Command, section: &str) { + for sub in cmd.get_subcommands().filter(|s| !s.is_hide_set()) { roff.control("TP", []); - let name = format!("{}-{}({})", app.get_name(), sub.get_name(), section); + let name = format!("{}-{}({})", cmd.get_name(), sub.get_name(), section); roff.text([roman(&name)]); if let Some(about) = sub.get_about().or_else(|| sub.get_long_about()) { @@ -158,24 +158,24 @@ pub(crate) fn subcommands(roff: &mut Roff, app: &clap::App, section: &str) { } } -pub(crate) fn version(app: &clap::App) -> String { +pub(crate) fn version(cmd: &clap::Command) -> String { format!( "v{}", - app.get_long_version() - .or_else(|| app.get_version()) + cmd.get_long_version() + .or_else(|| cmd.get_version()) .unwrap() ) } -pub(crate) fn after_help(roff: &mut Roff, app: &clap::App) { - if let Some(about) = app.get_after_long_help().or_else(|| app.get_after_help()) { +pub(crate) fn after_help(roff: &mut Roff, cmd: &clap::Command) { + if let Some(about) = cmd.get_after_long_help().or_else(|| cmd.get_after_help()) { for line in about.lines() { roff.text([roman(line)]); } } } -fn subcommand_markers(cmd: &clap::App) -> (&'static str, &'static str) { +fn subcommand_markers(cmd: &clap::Command) -> (&'static str, &'static str) { #[allow(deprecated)] markers(cmd.is_subcommand_required_set() || cmd.is_set(AppSettings::SubcommandRequiredElseHelp)) } diff --git a/clap_mangen/tests/generate.rs b/clap_mangen/tests/generate.rs index 65b690c0831..c8a2a1ab4b6 100644 --- a/clap_mangen/tests/generate.rs +++ b/clap_mangen/tests/generate.rs @@ -1,10 +1,10 @@ -use clap::{arg, App}; +use clap::{arg, Command}; use clap_mangen::Man; use std::io; #[test] fn render_manpage() { - let app = App::new("myapp") + let cmd = Command::new("myapp") .version("1.0") .author("Kevin K. ") .about("Does awesome things") @@ -20,10 +20,10 @@ fn render_manpage() { .arg(arg!([output] "Sets an optional output file").index(1)) .arg(arg!(-d --debug ... "Turn debugging information on")) .subcommand( - App::new("test") + Command::new("test") .about("does testing things") .arg(arg!(-l --list "Lists test values")), ); - Man::new(app).render(&mut io::sink()).unwrap(); + Man::new(cmd).render(&mut io::sink()).unwrap(); } diff --git a/docs/FAQ.md b/docs/FAQ.md index eef426de3b7..fe212eae49d 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -66,7 +66,7 @@ Previously, we supported: There are also experiments with other APIs: - [fncmd](https://github.com/yuhr/fncmd): function attribute -- [clap-serde](https://github.com/aobatact/clap-serde): create an `App` from a deserializer +- [clap-serde](https://github.com/aobatact/clap-serde): create an `Command` from a deserializer ### Why is there a default subcommand of help? diff --git a/examples/cargo-example.rs b/examples/cargo-example.rs index 51356dc40a5..61fcd8aa518 100644 --- a/examples/cargo-example.rs +++ b/examples/cargo-example.rs @@ -1,7 +1,7 @@ // Note: this requires the `cargo` feature fn main() { - let app = clap::App::new("cargo") + let cmd = clap::Command::new("cargo") .bin_name("cargo") .subcommand_required(true) .subcommand( @@ -11,7 +11,7 @@ fn main() { .allow_invalid_utf8(true), ), ); - let matches = app.get_matches(); + let matches = cmd.get_matches(); let matches = match matches.subcommand() { Some(("example", matches)) => matches, _ => unreachable!("clap should ensure we don't get here"), diff --git a/examples/derive_ref/README.md b/examples/derive_ref/README.md index 917a85bd5d1..bdb8fdc9b6c 100644 --- a/examples/derive_ref/README.md +++ b/examples/derive_ref/README.md @@ -3,7 +3,7 @@ 1. [Overview](#overview) 2. [Raw Attributes](#raw-attributes) 3. [Magic Attributes](#magic-attributes) - 1. [App Attributes](#app-attributes) + 1. [Command Attributes](#cmd-attributes) 2. [Arg Attributes](#arg-attributes) 3. [Arg Types](#arg-types) 4. [Arg Enum Attributes](#arg-enum-attributes) @@ -85,7 +85,7 @@ See also the [tutorial](../tutorial_derive/README.md) and [examples](../README.m ## Raw Attributes **Raw attributes** are forwarded directly to the underlying `clap` builder. Any -`App`, `Arg`, or `PossibleValue` method can be used as an attribute. +`Command`, `Arg`, or `PossibleValue` method can be used as an attribute. Raw attributes come in two different syntaxes: ```rust @@ -107,33 +107,33 @@ translated into a mere method call. - Providing of defaults - Special behavior is triggered off of it -### App Attributes +### Command Attributes -These correspond to a `clap::App` which is used for both top-level parsers and +These correspond to a `clap::Command` which is used for both top-level parsers and when defining subcommands. In addition to the raw attributes, the following magic attributes are supported: -- `name = `: `clap::App::name` +- `name = `: `clap::Command::name` - When not present: [crate `name`](https://doc.rust-lang.org/cargo/reference/manifest.html#the-name-field) (`Parser` container), variant name (`Subcommand` variant) -- `version [= ]`: `clap::App::version` +- `version [= ]`: `clap::Command::version` - When not present: no version set - Without ``: defaults to [crate `version`](https://doc.rust-lang.org/cargo/reference/manifest.html#the-version-field) -- `author [= ]`: `clap::App::author` +- `author [= ]`: `clap::Command::author` - When not present: no author set - Without ``: defaults to [crate `authors`](https://doc.rust-lang.org/cargo/reference/manifest.html#the-authors-field) -- `about [= ]`: `clap::App::about` +- `about [= ]`: `clap::Command::about` - When not present: [Doc comment summary](#doc-comments) - Without ``: [crate `description`](https://doc.rust-lang.org/cargo/reference/manifest.html#the-description-field) (`Parser` container) - **TIP:** When a doc comment is also present, you most likely want to add `#[clap(long_about = None)]` to clear the doc comment so only `about` gets shown with both `-h` and `--help`. -- `long_about = `: `clap::App::long_about` +- `long_about = `: `clap::Command::long_about` - When not present: [Doc comment](#doc-comments) if there is a blank line, else nothing - `verbatim_doc_comment`: Minimizes pre-processing when converting doc comments to `about` / `long_about` -- `next_display_order`: `clap::App::next_display_order` -- `next_help_heading`: `clap::App::next_help_heading` +- `next_display_order`: `clap::Command::next_display_order` +- `next_help_heading`: `clap::Command::next_help_heading` - When `flatten`ing `Args`, this is scoped to just the args in this struct and any struct `flatten`ed into it -- `rename_all = `: Override default field / variant name case conversion for `App::name` / `Arg::name` +- `rename_all = `: Override default field / variant name case conversion for `Command::name` / `Arg::name` - When not present: `kebab-case` - Available values: `camelCase`, `kebab-case`, `PascalCase`, `SCREAMING_SNAKE_CASE`, `snake_case`, `lower`, `UPPER`, `verbatim` - `rename_all_env = `: Override default field name case conversion for env variables for `clap::Arg::env` @@ -144,7 +144,7 @@ And for `Subcommand` variants: - `skip`: Ignore this variant - `flatten`: Delegates to the variant for more subcommands (must implement `Subcommand`) - `subcommand`: Nest subcommands under the current set of subcommands (must implement `Subcommand`) -- `external_subcommand`: `clap::App::allow_external_subcommand(true)` +- `external_subcommand`: `clap::Command::allow_external_subcommand(true)` - Variant must be either `Variant(Vec)` or `Variant(Vec)` ### Arg Attributes @@ -172,8 +172,8 @@ In addition to the raw attributes, the following magic attributes are supported: - Only `help_heading` can be used with `flatten`. See [clap-rs/clap#3269](https://github.com/clap-rs/clap/issues/3269) for why arg attributes are not generally supported. - - **Tip:** Though we do apply a flattened `Args`'s Parent App Attributes, this - makes reuse harder. Generally prefer putting the app attributes on the `Parser` + - **Tip:** Though we do apply a flattened `Args`'s Parent Command Attributes, this + makes reuse harder. Generally prefer putting the cmd attributes on the `Parser` or on the flattened field. - `subcommand`: Delegates definition of subcommands to the field (must implement `Subcommand`) - When `Option`, the subcommand becomes optional @@ -259,7 +259,7 @@ These correspond to a `clap::PossibleValue`. ### Doc Comments In clap, help messages for the whole binary can be specified -via [`App::about`] and [`App::long_about`] while help messages +via [`Command::about`] and [`Command::long_about`] while help messages for individual arguments can be specified via [`Arg::help`] and [`Arg::long_help`]". `long_*` variants are used when user calls the program with @@ -292,8 +292,8 @@ struct Foo { **NOTE:** Attributes have priority over doc comments! -**Top level doc comments always generate `App::about/long_about` calls!** -If you really want to use the `App::about/long_about` methods (you likely don't), +**Top level doc comments always generate `Command::about/long_about` calls!** +If you really want to use the `Command::about/long_about` methods (you likely don't), use the `about` / `long_about` attributes to override the calls generated from the doc comment. To clear `long_about`, you can use `#[clap(long_about = None)]`. @@ -326,10 +326,10 @@ A doc comment consists of three parts: - A blank line (whitespace only) - Detailed description, all the rest -The summary corresponds with `App::about` / `Arg::help`. When a blank line is -present, the whole doc comment will be passed to `App::long_about` / -`Arg::long_help`. Or in other words, a doc may result in just a `App::about` / -`Arg::help` or `App::about` / `Arg::help` and `App::long_about` / +The summary corresponds with `Command::about` / `Arg::help`. When a blank line is +present, the whole doc comment will be passed to `Command::long_about` / +`Arg::long_help`. Or in other words, a doc may result in just a `Command::about` / +`Arg::help` or `Command::about` / `Arg::help` and `Command::long_about` / `Arg::long_help` In addition, when `verbatim_doc_comment` is not present, `clap` applies some preprocessing, including: diff --git a/examples/git.rs b/examples/git.rs index cfb6848f4ab..4bcd1954c7c 100644 --- a/examples/git.rs +++ b/examples/git.rs @@ -2,29 +2,29 @@ use std::path::PathBuf; -use clap::{arg, App}; +use clap::{arg, Command}; fn main() { - let matches = App::new("git") + let matches = Command::new("git") .about("A fictional versioning CLI") .subcommand_required(true) .arg_required_else_help(true) .allow_external_subcommands(true) .allow_invalid_utf8_for_external_subcommands(true) .subcommand( - App::new("clone") + Command::new("clone") .about("Clones repos") .arg(arg!( "The remote to clone")) .arg_required_else_help(true), ) .subcommand( - App::new("push") + Command::new("push") .about("pushes things") .arg(arg!( "The remote to target")) .arg_required_else_help(true), ) .subcommand( - App::new("add") + Command::new("add") .about("adds things") .arg_required_else_help(true) .arg(arg!( ... "Stuff to add").allow_invalid_utf8(true)), diff --git a/examples/multicall-busybox.md b/examples/multicall-busybox.md index 723d03319c0..a09418403f7 100644 --- a/examples/multicall-busybox.md +++ b/examples/multicall-busybox.md @@ -2,7 +2,7 @@ Example of a busybox-style multicall program -See the documentation for `clap::App::multicall` for rationale. +See the documentation for `clap::Command::multicall` for rationale. This example omits every command except true and false, which are the most trivial to implement, diff --git a/examples/multicall-busybox.rs b/examples/multicall-busybox.rs index 8d49fe7269c..30865a8303f 100644 --- a/examples/multicall-busybox.rs +++ b/examples/multicall-busybox.rs @@ -2,20 +2,20 @@ use std::process::exit; -use clap::{App, Arg}; +use clap::{Arg, Command}; -fn applet_commands() -> [App<'static>; 2] { +fn applet_commands() -> [Command<'static>; 2] { [ - App::new("true").about("does nothing successfully"), - App::new("false").about("does nothing unsuccessfully"), + Command::new("true").about("does nothing successfully"), + Command::new("false").about("does nothing unsuccessfully"), ] } fn main() { - let app = App::new(env!("CARGO_CRATE_NAME")) + let cmd = Command::new(env!("CARGO_CRATE_NAME")) .multicall(true) .subcommand( - App::new("busybox") + Command::new("busybox") .arg_required_else_help(true) .subcommand_value_name("APPLET") .subcommand_help_heading("APPLETS") @@ -32,7 +32,7 @@ fn main() { ) .subcommands(applet_commands()); - let matches = app.get_matches(); + let matches = cmd.get_matches(); let mut subcommand = matches.subcommand(); if let Some(("busybox", cmd)) = subcommand { if cmd.occurrences_of("install") > 0 { diff --git a/examples/multicall-hostname.md b/examples/multicall-hostname.md index 1bbb521fc1f..9e17ca16cbc 100644 --- a/examples/multicall-hostname.md +++ b/examples/multicall-hostname.md @@ -2,7 +2,7 @@ Example of a `hostname-style` multicall program -See the documentation for `clap::App::multicall` for rationale. +See the documentation for `clap::Command::multicall` for rationale. This example omits the implementation of displaying address config diff --git a/examples/multicall-hostname.rs b/examples/multicall-hostname.rs index eb19cd47136..45542611059 100644 --- a/examples/multicall-hostname.rs +++ b/examples/multicall-hostname.rs @@ -1,18 +1,18 @@ // Note: this requires the `unstable-multicall` feature -use clap::App; +use clap::Command; fn main() { - let app = App::new(env!("CARGO_CRATE_NAME")) + let cmd = Command::new(env!("CARGO_CRATE_NAME")) .arg_required_else_help(true) .subcommand_value_name("APPLET") .subcommand_help_heading("APPLETS") - .subcommand(App::new("hostname").about("show hostname part of FQDN")) - .subcommand(App::new("dnsdomainname").about("show domain name part of FQDN")); + .subcommand(Command::new("hostname").about("show hostname part of FQDN")) + .subcommand(Command::new("dnsdomainname").about("show domain name part of FQDN")); - let app = app.multicall(true); + let cmd = cmd.multicall(true); - match app.get_matches().subcommand_name() { + match cmd.get_matches().subcommand_name() { Some("hostname") => println!("www"), Some("dnsdomainname") => println!("example.com"), _ => unreachable!("parser should ensure only valid subcommand names are used"), diff --git a/examples/pacman.rs b/examples/pacman.rs index 155e31d6cb2..c088a8fe916 100644 --- a/examples/pacman.rs +++ b/examples/pacman.rs @@ -1,7 +1,7 @@ -use clap::{App, Arg}; +use clap::{Arg, Command}; fn main() { - let matches = App::new("pacman") + let matches = Command::new("pacman") .about("package manager utility") .version("5.2.1") .subcommand_required(true) @@ -11,7 +11,7 @@ fn main() { // // Only a few of its arguments are implemented below. .subcommand( - App::new("query") + Command::new("query") .short_flag('Q') .long_flag("query") .about("Query the package database.") @@ -38,7 +38,7 @@ fn main() { // // Only a few of its arguments are implemented below. .subcommand( - App::new("sync") + Command::new("sync") .short_flag('S') .long_flag("sync") .about("Synchronize packages.") diff --git a/examples/tutorial_builder/01_quick.rs b/examples/tutorial_builder/01_quick.rs index f14a9181435..0f7c84fd0ef 100644 --- a/examples/tutorial_builder/01_quick.rs +++ b/examples/tutorial_builder/01_quick.rs @@ -1,4 +1,4 @@ -use clap::{app_from_crate, arg, App}; +use clap::{app_from_crate, arg, Command}; use std::path::Path; fn main() { @@ -17,7 +17,7 @@ fn main() { -d --debug ... "Turn debugging information on" )) .subcommand( - App::new("test") + Command::new("test") .about("does testing things") .arg(arg!(-l --list "lists test values")), ) @@ -43,7 +43,7 @@ fn main() { } // You can check for the existence of subcommands, and if found use their - // matches just as you would the top level app + // matches just as you would the top level cmd if let Some(matches) = matches.subcommand_matches("test") { // "$ myapp test" was run if matches.is_present("list") { diff --git a/examples/tutorial_builder/02_apps.rs b/examples/tutorial_builder/02_apps.rs index b607b7f19a7..c9422d64a3a 100644 --- a/examples/tutorial_builder/02_apps.rs +++ b/examples/tutorial_builder/02_apps.rs @@ -1,7 +1,7 @@ -use clap::{arg, App}; +use clap::{arg, Command}; fn main() { - let matches = App::new("MyApp") + let matches = Command::new("MyApp") .version("1.0") .author("Kevin K. ") .about("Does awesome things") diff --git a/examples/tutorial_builder/03_04_subcommands.rs b/examples/tutorial_builder/03_04_subcommands.rs index d5900824ae6..dbf27081381 100644 --- a/examples/tutorial_builder/03_04_subcommands.rs +++ b/examples/tutorial_builder/03_04_subcommands.rs @@ -1,4 +1,4 @@ -use clap::{app_from_crate, arg, App}; +use clap::{app_from_crate, arg, Command}; fn main() { let matches = app_from_crate!() @@ -6,7 +6,7 @@ fn main() { .subcommand_required(true) .arg_required_else_help(true) .subcommand( - App::new("add") + Command::new("add") .about("Adds files to myapp") .arg(arg!([NAME])), ) diff --git a/examples/tutorial_builder/04_04_custom.rs b/examples/tutorial_builder/04_04_custom.rs index 2a4e9b8556c..747cc95fb61 100644 --- a/examples/tutorial_builder/04_04_custom.rs +++ b/examples/tutorial_builder/04_04_custom.rs @@ -2,7 +2,7 @@ use clap::{app_from_crate, arg, ErrorKind}; fn main() { // Create application like normal - let mut app = app_from_crate!() + let mut cmd = app_from_crate!() // Add the version arguments .arg(arg!(--"set-ver" "set version manually").required(false)) .arg(arg!(--major "auto inc major")) @@ -15,7 +15,7 @@ fn main() { // Now let's assume we have a -c [config] argument which requires one of // (but **not** both) the "input" arguments .arg(arg!(config: -c ).required(false)); - let matches = app.get_matches_mut(); + let matches = cmd.get_matches_mut(); // Let's assume the old version 1.2.3 let mut major = 1; @@ -26,7 +26,7 @@ fn main() { let version = if let Some(ver) = matches.value_of("set-ver") { if matches.is_present("major") || matches.is_present("minor") || matches.is_present("patch") { - app.error( + cmd.error( ErrorKind::ArgumentConflict, "Can't do relative and absolute version change", ) @@ -45,7 +45,7 @@ fn main() { (false, true, false) => minor += 1, (false, false, true) => patch += 1, _ => { - app.error( + cmd.error( ErrorKind::ArgumentConflict, "Cam only modify one version field", ) @@ -63,7 +63,7 @@ fn main() { .value_of("INPUT_FILE") .or_else(|| matches.value_of("spec-in")) .unwrap_or_else(|| { - app.error( + cmd.error( ErrorKind::MissingRequiredArgument, "INPUT_FILE or --spec-in is required when using --config", ) diff --git a/examples/tutorial_builder/05_01_assert.rs b/examples/tutorial_builder/05_01_assert.rs index 034367e7964..b341cd96385 100644 --- a/examples/tutorial_builder/05_01_assert.rs +++ b/examples/tutorial_builder/05_01_assert.rs @@ -1,7 +1,7 @@ use clap::{app_from_crate, arg}; fn main() { - let matches = app().get_matches(); + let matches = cmd().get_matches(); // Note, it's safe to call unwrap() because the arg is required let port: usize = matches @@ -10,7 +10,7 @@ fn main() { println!("PORT = {}", port); } -fn app() -> clap::App<'static> { +fn cmd() -> clap::Command<'static> { app_from_crate!().arg( arg!() .help("Network port to use") @@ -20,5 +20,5 @@ fn app() -> clap::App<'static> { #[test] fn verify_app() { - app().debug_assert(); + cmd().debug_assert(); } diff --git a/examples/tutorial_builder/README.md b/examples/tutorial_builder/README.md index 59ac563f9bc..9906b386a65 100644 --- a/examples/tutorial_builder/README.md +++ b/examples/tutorial_builder/README.md @@ -63,7 +63,7 @@ Not printing testing lists... ## Configuring the Parser -You use the `App` the start building a parser. +You use the `Command` the start building a parser. [Example:](02_apps.rs) ```console @@ -109,7 +109,7 @@ clap [..] ``` -You can use `App` methods to change the application level behavior of clap. +You can use `Command` methods to change the application level behavior of clap. [Example:](02_app_settings.rs) ```console @@ -264,7 +264,7 @@ NAME: Some("bob") ### Subcommands -Subcommands are defined as `App`s that get added via `App::subcommand`. Each +Subcommands are defined as `Command`s that get added via `Command::subcommand`. Each instance of a Subcommand can have its own version, author(s), Args, and even its own subcommands. @@ -304,7 +304,7 @@ $ 03_04_subcommands add bob ``` -Because we set `App::arg_required_else_help`: +Because we set `Command::arg_required_else_help`: ```console $ 03_04_subcommands ? failed @@ -324,7 +324,7 @@ SUBCOMMANDS: ``` -Because we set `App::propagate_version`: +Because we set `Command::propagate_version`: ```console $ 03_04_subcommands --version clap [..] @@ -642,7 +642,7 @@ Doing work using input input.txt and config config.toml ## Tips -- Proactively check for bad `App` configurations by calling `App::debug_assert` ([example](05_01_assert.rs)) +- Proactively check for bad `Command` configurations by calling `Command::debug_assert` ([example](05_01_assert.rs)) ## Contributing diff --git a/examples/tutorial_derive/01_quick.rs b/examples/tutorial_derive/01_quick.rs index 9bd1c52ccc6..f840b8a9b2f 100644 --- a/examples/tutorial_derive/01_quick.rs +++ b/examples/tutorial_derive/01_quick.rs @@ -52,7 +52,7 @@ fn main() { } // You can check for the existence of subcommands, and if found use their - // matches just as you would the top level app + // matches just as you would the top level cmd match &cli.command { Some(Commands::Test { list }) => { if *list { diff --git a/examples/tutorial_derive/03_04_subcommands.rs b/examples/tutorial_derive/03_04_subcommands.rs index 1ce71c01730..86cf444c21b 100644 --- a/examples/tutorial_derive/03_04_subcommands.rs +++ b/examples/tutorial_derive/03_04_subcommands.rs @@ -18,7 +18,7 @@ fn main() { let cli = Cli::parse(); // You can check for the existence of subcommands, and if found use their - // matches just as you would the top level app + // matches just as you would the top level cmd match &cli.command { Commands::Add { name } => { println!("'myapp add' was used, name is: {:?}", name) diff --git a/examples/tutorial_derive/04_04_custom.rs b/examples/tutorial_derive/04_04_custom.rs index e3c1387d462..6541dd8613a 100644 --- a/examples/tutorial_derive/04_04_custom.rs +++ b/examples/tutorial_derive/04_04_custom.rs @@ -41,8 +41,8 @@ fn main() { // See if --set-ver was used to set the version manually let version = if let Some(ver) = cli.set_ver.as_deref() { if cli.major || cli.minor || cli.patch { - let mut app = Cli::into_app(); - app.error( + let mut cmd = Cli::into_app(); + cmd.error( ErrorKind::ArgumentConflict, "Can't do relative and absolute version change", ) @@ -57,8 +57,8 @@ fn main() { (false, true, false) => minor += 1, (false, false, true) => patch += 1, _ => { - let mut app = Cli::into_app(); - app.error( + let mut cmd = Cli::into_app(); + cmd.error( ErrorKind::ArgumentConflict, "Cam only modify one version field", ) @@ -80,8 +80,8 @@ fn main() { // 'or' is preferred to 'or_else' here since `Option::as_deref` is 'const' .or(cli.spec_in.as_deref()) .unwrap_or_else(|| { - let mut app = Cli::into_app(); - app.error( + let mut cmd = Cli::into_app(); + cmd.error( ErrorKind::MissingRequiredArgument, "INPUT_FILE or --spec-in is required when using --config", ) diff --git a/examples/tutorial_derive/README.md b/examples/tutorial_derive/README.md index c8ab0ea5fef..71cde2a990c 100644 --- a/examples/tutorial_derive/README.md +++ b/examples/tutorial_derive/README.md @@ -66,7 +66,7 @@ In addition to this tutorial, see the [derive reference](../derive_ref/README.md ## Configuring the Parser -You use the `App` the start building a parser. +You use the `Command` the start building a parser. [Example:](02_apps.rs) ```console @@ -111,7 +111,7 @@ clap [..] ``` -You can use `App` methods to change the application level behavior of clap. +You can use `Command` methods to change the application level behavior of clap. [Example:](02_app_settings.rs) ```console @@ -266,7 +266,7 @@ name: Some("bob") ### Subcommands -Subcommands are defined as `App`s that get added via `App::subcommand`. Each +Subcommands are defined as `Command`s that get added via `Command::subcommand`. Each instance of a Subcommand can have its own version, author(s), Args, and even its own subcommands. @@ -326,7 +326,7 @@ SUBCOMMANDS: ``` -Because we set `App::propagate_version`: +Because we set `Command::propagate_version`: ```console $ 03_04_subcommands_derive --version clap [..] @@ -610,7 +610,7 @@ Doing work using input input.txt and config config.toml ## Tips -- Proactively check for bad `App` configurations by calling `App::debug_assert` ([example](05_01_assert.rs)) +- Proactively check for bad `Command` configurations by calling `Command::debug_assert` ([example](05_01_assert.rs)) ## Contributing diff --git a/src/build/app_settings.rs b/src/build/app_settings.rs index 7998bc93ac6..65d69ef825b 100644 --- a/src/build/app_settings.rs +++ b/src/build/app_settings.rs @@ -5,10 +5,10 @@ use std::ops::BitOr; #[cfg(feature = "yaml")] use std::str::FromStr; -#[allow(unused)] -use crate::App; #[allow(unused)] use crate::Arg; +#[allow(unused)] +use crate::Command; // Third party use bitflags::bitflags; @@ -23,31 +23,31 @@ impl Default for AppFlags { } } -/// Application level settings, which affect how [`App`] operates +/// Application level settings, which affect how [`Command`] operates /// /// **NOTE:** When these settings are used, they apply only to current command, and are *not* /// propagated down or up through child or parent subcommands /// -/// [`App`]: crate::App +/// [`Command`]: crate::Command #[derive(Debug, PartialEq, Copy, Clone)] #[non_exhaustive] pub enum AppSettings { - /// Deprecated, replaced with [`App::ignore_errors`] - #[deprecated(since = "3.1.0", note = "Replaced with `App::ignore_errors`")] + /// Deprecated, replaced with [`Command::ignore_errors`] + #[deprecated(since = "3.1.0", note = "Replaced with `Command::ignore_errors`")] IgnoreErrors, /// Deprecated, replace /// ```rust,no_run - /// let app = clap::App::new("app") + /// let cmd = clap::Command::new("cmd") /// .global_setting(clap::AppSettings::WaitOnError) /// .arg(clap::arg!(--flag)); - /// let m = app.get_matches(); + /// let m = cmd.get_matches(); /// ``` /// with /// ```rust - /// let app = clap::App::new("app") + /// let cmd = clap::Command::new("cmd") /// .arg(clap::arg!(--flag)); - /// let m = match app.try_get_matches() { + /// let m = match cmd.try_get_matches() { /// Ok(m) => m, /// Err(err) => { /// if err.use_stderr() { @@ -73,93 +73,93 @@ pub enum AppSettings { )] WaitOnError, - /// Deprecated, replaced with [`App::allow_hyphen_values`] and + /// Deprecated, replaced with [`Command::allow_hyphen_values`] and /// [`Arg::is_allow_hyphen_values_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::allow_hyphen_values` and `Arg::is_allow_hyphen_values_set`" + note = "Replaced with `Command::allow_hyphen_values` and `Arg::is_allow_hyphen_values_set`" )] AllowHyphenValues, - /// Deprecated, replaced with [`App::allow_negative_numbers`] and - /// [`App::is_allow_negative_numbers_set`] + /// Deprecated, replaced with [`Command::allow_negative_numbers`] and + /// [`Command::is_allow_negative_numbers_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::allow_negative_numbers` and `App::is_allow_negative_numbers_set`" + note = "Replaced with `Command::allow_negative_numbers` and `Command::is_allow_negative_numbers_set`" )] AllowNegativeNumbers, - /// Deprecated, replaced with [`App::args_override_self`] - #[deprecated(since = "3.1.0", note = "Replaced with `App::args_override_self`")] + /// Deprecated, replaced with [`Command::args_override_self`] + #[deprecated(since = "3.1.0", note = "Replaced with `Command::args_override_self`")] AllArgsOverrideSelf, - /// Deprecated, replaced with [`App::allow_missing_positional`] and - /// [`App::is_allow_missing_positional_set`] + /// Deprecated, replaced with [`Command::allow_missing_positional`] and + /// [`Command::is_allow_missing_positional_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::allow_missing_positional` and `App::is_allow_missing_positional_set`" + note = "Replaced with `Command::allow_missing_positional` and `Command::is_allow_missing_positional_set`" )] AllowMissingPositional, - /// Deprecated, replaced with [`App::trailing_var_arg`] and [`App::is_trailing_var_arg_set`] + /// Deprecated, replaced with [`Command::trailing_var_arg`] and [`Command::is_trailing_var_arg_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::trailing_var_arg` and `App::is_trailing_var_arg_set`" + note = "Replaced with `Command::trailing_var_arg` and `Command::is_trailing_var_arg_set`" )] TrailingVarArg, - /// Deprecated, replaced with [`App::dont_delimit_trailing_values`] and - /// [`App::is_dont_delimit_trailing_values_set`] + /// Deprecated, replaced with [`Command::dont_delimit_trailing_values`] and + /// [`Command::is_dont_delimit_trailing_values_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::dont_delimit_trailing_values` and `App::is_dont_delimit_trailing_values_set`" + note = "Replaced with `Command::dont_delimit_trailing_values` and `Command::is_dont_delimit_trailing_values_set`" )] DontDelimitTrailingValues, - /// Deprecated, replaced with [`App::infer_long_args`] - #[deprecated(since = "3.1.0", note = "Replaced with `App::infer_long_args`")] + /// Deprecated, replaced with [`Command::infer_long_args`] + #[deprecated(since = "3.1.0", note = "Replaced with `Command::infer_long_args`")] InferLongArgs, - /// Deprecated, replaced with [`App::infer_subcommands`] - #[deprecated(since = "3.1.0", note = "Replaced with `App::infer_subcommands`")] + /// Deprecated, replaced with [`Command::infer_subcommands`] + #[deprecated(since = "3.1.0", note = "Replaced with `Command::infer_subcommands`")] InferSubcommands, - /// Deprecated, replaced with [`App::subcommand_required`] and - /// [`App::is_subcommand_required_set`] + /// Deprecated, replaced with [`Command::subcommand_required`] and + /// [`Command::is_subcommand_required_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::subcommand_required` and `App::is_subcommand_required_set`" + note = "Replaced with `Command::subcommand_required` and `Command::is_subcommand_required_set`" )] SubcommandRequired, - /// Deprecated, replaced with [`App::subcommand_required`] combined with - /// [`App::arg_required_else_help`]. + /// Deprecated, replaced with [`Command::subcommand_required`] combined with + /// [`Command::arg_required_else_help`]. #[deprecated( since = "3.1.0", - note = "Replaced with `App::subcommand_required` combined with `App::arg_required_else_help`" + note = "Replaced with `Command::subcommand_required` combined with `Command::arg_required_else_help`" )] SubcommandRequiredElseHelp, - /// Deprecated, replaced with [`App::allow_external_subcommands`] and - /// [`App::is_allow_external_subcommands_set`] + /// Deprecated, replaced with [`Command::allow_external_subcommands`] and + /// [`Command::is_allow_external_subcommands_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::allow_external_subcommands` and `App::is_allow_external_subcommands_set`" + note = "Replaced with `Command::allow_external_subcommands` and `Command::is_allow_external_subcommands_set`" )] AllowExternalSubcommands, - /// Deprecated, replaced with [`App::multicall`] and [`App::is_multicall_set`] + /// Deprecated, replaced with [`Command::multicall`] and [`Command::is_multicall_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::multicall` and `App::is_multicall_set`" + note = "Replaced with `Command::multicall` and `Command::is_multicall_set`" )] #[cfg(feature = "unstable-multicall")] Multicall, - /// Deprecated, replaced with [`App::allow_invalid_utf8_for_external_subcommands`] and [`App::is_allow_invalid_utf8_for_external_subcommands_set`] + /// Deprecated, replaced with [`Command::allow_invalid_utf8_for_external_subcommands`] and [`Command::is_allow_invalid_utf8_for_external_subcommands_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::allow_invalid_utf8_for_external_subcommands` and `App::is_allow_invalid_utf8_for_external_subcommands_set`" + note = "Replaced with `Command::allow_invalid_utf8_for_external_subcommands` and `Command::is_allow_invalid_utf8_for_external_subcommands_set`" )] AllowInvalidUtf8ForExternalSubcommands, @@ -167,131 +167,131 @@ pub enum AppSettings { #[deprecated(since = "3.1.0", note = "This is now the default")] UseLongFormatForHelpSubcommand, - /// Deprecated, replaced with [`App::subcommand_negates_reqs`] and - /// [`App::is_subcommand_negates_reqs_set`] + /// Deprecated, replaced with [`Command::subcommand_negates_reqs`] and + /// [`Command::is_subcommand_negates_reqs_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::subcommand_negates_reqs` and `App::is_subcommand_negates_reqs_set`" + note = "Replaced with `Command::subcommand_negates_reqs` and `Command::is_subcommand_negates_reqs_set`" )] SubcommandsNegateReqs, - /// Deprecated, replaced with [`App::args_conflicts_with_subcommands`] and - /// [`App::is_args_conflicts_with_subcommands_set`] + /// Deprecated, replaced with [`Command::args_conflicts_with_subcommands`] and + /// [`Command::is_args_conflicts_with_subcommands_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::args_conflicts_with_subcommands` and `App::is_args_conflicts_with_subcommands_set`" + note = "Replaced with `Command::args_conflicts_with_subcommands` and `Command::is_args_conflicts_with_subcommands_set`" )] ArgsNegateSubcommands, - /// Deprecated, replaced with [`App::subcommand_precedence_over_arg`] and - /// [`App::is_subcommand_precedence_over_arg_set`] + /// Deprecated, replaced with [`Command::subcommand_precedence_over_arg`] and + /// [`Command::is_subcommand_precedence_over_arg_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::subcommand_precedence_over_arg` and `App::is_subcommand_precedence_over_arg_set`" + note = "Replaced with `Command::subcommand_precedence_over_arg` and `Command::is_subcommand_precedence_over_arg_set`" )] SubcommandPrecedenceOverArg, - /// Deprecated, replaced with [`App::arg_required_else_help`] and - /// [`App::is_arg_required_else_help_set`] + /// Deprecated, replaced with [`Command::arg_required_else_help`] and + /// [`Command::is_arg_required_else_help_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::arg_required_else_help` and `App::is_arg_required_else_help_set`" + note = "Replaced with `Command::arg_required_else_help` and `Command::is_arg_required_else_help_set`" )] ArgRequiredElseHelp, /// Displays the arguments and [`subcommands`] in the help message in the order that they were /// declared in, and not alphabetically which is the default. /// - /// To override the declaration order, see [`Arg::display_order`] and [`App::display_order`]. + /// To override the declaration order, see [`Arg::display_order`] and [`Command::display_order`]. /// /// # Examples /// /// ```no_run - /// # use clap::{App, Arg, AppSettings}; - /// App::new("myprog") + /// # use clap::{Command, Arg, AppSettings}; + /// Command::new("myprog") /// .global_setting(AppSettings::DeriveDisplayOrder) /// .get_matches(); /// ``` /// - /// [`subcommands`]: crate::App::subcommand() + /// [`subcommands`]: crate::Command::subcommand() /// [`Arg::display_order`]: crate::Arg::display_order - /// [`App::display_order`]: crate::App::display_order + /// [`Command::display_order`]: crate::Command::display_order DeriveDisplayOrder, - /// Deprecated, replaced with [`App::dont_collapse_args_in_usage`] and - /// [`App::is_dont_collapse_args_in_usage_set`] + /// Deprecated, replaced with [`Command::dont_collapse_args_in_usage`] and + /// [`Command::is_dont_collapse_args_in_usage_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::dont_collapse_args_in_usage` and `App::is_dont_collapse_args_in_usage_set`" + note = "Replaced with `Command::dont_collapse_args_in_usage` and `Command::is_dont_collapse_args_in_usage_set`" )] DontCollapseArgsInUsage, - /// Deprecated, replaced with [`App::next_line_help`] and [`App::is_next_line_help_set`] + /// Deprecated, replaced with [`Command::next_line_help`] and [`Command::is_next_line_help_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::next_line_help` and `App::is_next_line_help_set`" + note = "Replaced with `Command::next_line_help` and `Command::is_next_line_help_set`" )] NextLineHelp, - /// Deprecated, replaced with [`App::disable_colored_help`] and - /// [`App::is_disable_colored_help_set`] + /// Deprecated, replaced with [`Command::disable_colored_help`] and + /// [`Command::is_disable_colored_help_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::disable_colored_help` and `App::is_disable_colored_help_set`" + note = "Replaced with `Command::disable_colored_help` and `Command::is_disable_colored_help_set`" )] DisableColoredHelp, - /// Deprecated, replaced with [`App::disable_help_flag`] and [`App::is_disable_help_flag_set`] + /// Deprecated, replaced with [`Command::disable_help_flag`] and [`Command::is_disable_help_flag_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::disable_help_flag` and `App::is_disable_help_flag_set`" + note = "Replaced with `Command::disable_help_flag` and `Command::is_disable_help_flag_set`" )] DisableHelpFlag, - /// Deprecated, replaced with [`App::disable_help_subcommand`] and - /// [`App::is_disable_help_subcommand_set`] + /// Deprecated, replaced with [`Command::disable_help_subcommand`] and + /// [`Command::is_disable_help_subcommand_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::disable_help_subcommand` and `App::is_disable_help_subcommand_set`" + note = "Replaced with `Command::disable_help_subcommand` and `Command::is_disable_help_subcommand_set`" )] DisableHelpSubcommand, - /// Deprecated, replaced with [`App::disable_version_flag`] and - /// [`App::is_disable_version_flag_set`] + /// Deprecated, replaced with [`Command::disable_version_flag`] and + /// [`Command::is_disable_version_flag_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::disable_version_flag` and `App::is_disable_version_flag_set`" + note = "Replaced with `Command::disable_version_flag` and `Command::is_disable_version_flag_set`" )] DisableVersionFlag, - /// Deprecated, replaced with [`App::propagate_version`] and [`App::is_propagate_version_set`] + /// Deprecated, replaced with [`Command::propagate_version`] and [`Command::is_propagate_version_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::propagate_version` and `App::is_propagate_version_set`" + note = "Replaced with `Command::propagate_version` and `Command::is_propagate_version_set`" )] PropagateVersion, - /// Deprecated, replaced with [`App::hide`] and [`App::is_hide_set`] + /// Deprecated, replaced with [`Command::hide`] and [`Command::is_hide_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::hide` and `App::is_hide_set`" + note = "Replaced with `Command::hide` and `Command::is_hide_set`" )] Hidden, - /// Deprecated, replaced with [`App::hide_possible_values`] and + /// Deprecated, replaced with [`Command::hide_possible_values`] and /// [`Arg::is_hide_possible_values_set`] #[deprecated( since = "3.1.0", - note = "Replaced with `App::hide_possible_values` and `Arg::is_hide_possible_values_set`" + note = "Replaced with `Command::hide_possible_values` and `Arg::is_hide_possible_values_set`" )] HidePossibleValues, - /// Deprecated, replaced with [`App::help_expected`] - #[deprecated(since = "3.1.0", note = "Replaced with `App::help_expected`")] + /// Deprecated, replaced with [`Command::help_expected`] + #[deprecated(since = "3.1.0", note = "Replaced with `Command::help_expected`")] HelpExpected, - /// Deprecated, replaced with [`App::no_binary_name`] - #[deprecated(since = "3.1.0", note = "Replaced with `App::no_binary_name`")] + /// Deprecated, replaced with [`Command::no_binary_name`] + #[deprecated(since = "3.1.0", note = "Replaced with `Command::no_binary_name`")] NoBinaryName, /// Treat the auto-generated `-h, --help` flags like any other flag, and *not* print the help @@ -300,8 +300,8 @@ pub enum AppSettings { /// This allows one to handle printing of the help message manually. /// /// ```rust - /// # use clap::{App, AppSettings}; - /// let result = App::new("myprog") + /// # use clap::{Command, AppSettings}; + /// let result = Command::new("myprog") /// .setting(AppSettings::NoAutoHelp) /// .try_get_matches_from("myprog --help".split(" ")); /// @@ -321,8 +321,8 @@ pub enum AppSettings { /// This allows one to handle printing of the version message manually. /// /// ```rust - /// # use clap::{App, AppSettings}; - /// let result = App::new("myprog") + /// # use clap::{Command, AppSettings}; + /// let result = Command::new("myprog") /// .version("3.0") /// .setting(AppSettings::NoAutoVersion) /// .try_get_matches_from("myprog --version".split(" ")); @@ -363,18 +363,18 @@ pub enum AppSettings { #[doc(hidden)] ColoredHelp, - /// Deprecated, see [`App::color`][crate::App::color] - #[deprecated(since = "3.0.0", note = "Replaced with `App::color`")] + /// Deprecated, see [`Command::color`][crate::Command::color] + #[deprecated(since = "3.0.0", note = "Replaced with `Command::color`")] #[doc(hidden)] ColorAuto, - /// Deprecated, replaced with [`App::color`][crate::App::color] - #[deprecated(since = "3.0.0", note = "Replaced with `App::color`")] + /// Deprecated, replaced with [`Command::color`][crate::Command::color] + #[deprecated(since = "3.0.0", note = "Replaced with `Command::color`")] #[doc(hidden)] ColorAlways, - /// Deprecated, replaced with [`App::color`][crate::App::color] - #[deprecated(since = "3.0.0", note = "Replaced with `App::color`")] + /// Deprecated, replaced with [`Command::color`][crate::Command::color] + #[deprecated(since = "3.0.0", note = "Replaced with `Command::color`")] #[doc(hidden)] ColorNever, @@ -412,11 +412,11 @@ pub enum AppSettings { #[doc(hidden)] UnifiedHelp, - /// If the app is already built, used for caching. + /// If the cmd is already built, used for caching. #[doc(hidden)] Built, - /// If the app's bin name is already built, used for caching. + /// If the cmd's bin name is already built, used for caching. #[doc(hidden)] BinNameBuilt, } diff --git a/src/build/app_tests.rs b/src/build/app_tests.rs deleted file mode 100644 index 8317c8aa093..00000000000 --- a/src/build/app_tests.rs +++ /dev/null @@ -1,48 +0,0 @@ -use crate::App; - -#[test] -fn propagate_version() { - let mut app = App::new("test") - .propagate_version(true) - .version("1.1") - .subcommand(App::new("sub1")); - app._propagate(); - assert_eq!( - app.get_subcommands().next().unwrap().get_version(), - Some("1.1") - ); -} - -#[test] -fn global_setting() { - let mut app = App::new("test") - .disable_version_flag(true) - .subcommand(App::new("subcmd")); - app._propagate(); - assert!(app - .get_subcommands() - .find(|s| s.get_name() == "subcmd") - .unwrap() - .is_disable_version_flag_set()); -} - -// This test will *fail to compile* if App is not Send + Sync -#[test] -fn app_send_sync() { - fn foo(_: T) {} - foo(App::new("test")) -} - -#[test] -fn issue_2090() { - let mut app = App::new("app") - .disable_version_flag(true) - .subcommand(App::new("sub")); - app._build(); - - assert!(app - .get_subcommands() - .next() - .unwrap() - .is_disable_version_flag_set()); -} diff --git a/src/build/arg.rs b/src/build/arg.rs index f923404a38e..34aaaeaf21f 100644 --- a/src/build/arg.rs +++ b/src/build/arg.rs @@ -104,7 +104,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("config") /// # ; /// ``` @@ -143,8 +143,8 @@ impl<'help> Arg<'help> { /// argument via a single hyphen (`-`) such as `-c`: /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("config") /// .short('c')) /// .get_matches_from(vec![ @@ -180,8 +180,8 @@ impl<'help> Arg<'help> { /// Setting `long` allows using the argument via a double hyphen (`--`) such as `--config` /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("cfg") /// .long("config")) /// .get_matches_from(vec![ @@ -205,8 +205,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .long("test") /// .alias("alias") @@ -231,8 +231,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .short('t') /// .short_alias('e') @@ -259,8 +259,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .long("test") /// .aliases(&["do-stuff", "do-tests", "tests"]) @@ -285,8 +285,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .short('t') /// .short_aliases(&['e', 's']) @@ -313,8 +313,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .visible_alias("something-awesome") /// .long("test") @@ -325,7 +325,7 @@ impl<'help> Arg<'help> { /// assert!(m.is_present("test")); /// assert_eq!(m.value_of("test"), Some("coffee")); /// ``` - /// [`App::alias`]: Arg::alias() + /// [`Command::alias`]: Arg::alias() #[must_use] pub fn visible_alias>(mut self, name: S) -> Self { self.aliases.push((name.into(), true)); @@ -339,8 +339,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .long("test") /// .visible_short_alias('t') @@ -366,8 +366,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .long("test") /// .visible_aliases(&["something", "awesome", "cool"])) @@ -376,7 +376,7 @@ impl<'help> Arg<'help> { /// ]); /// assert!(m.is_present("test")); /// ``` - /// [`App::aliases`]: Arg::aliases() + /// [`Command::aliases`]: Arg::aliases() #[must_use] pub fn visible_aliases(mut self, names: &[&'help str]) -> Self { self.aliases.extend(names.iter().map(|n| (*n, true))); @@ -390,8 +390,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("test") /// .long("test") /// .visible_short_aliases(&['t', 'e'])) @@ -426,22 +426,22 @@ impl<'help> Arg<'help> { /// /// # Panics /// - /// [`App`] will [`panic!`] if indexes are skipped (such as defining `index(1)` and `index(3)` + /// [`Command`] will [`panic!`] if indexes are skipped (such as defining `index(1)` and `index(3)` /// but not `index(2)`, or a positional argument is defined as multiple and is not the highest /// index /// /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("config") /// .index(1) /// # ; /// ``` /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("mode") /// .index(1)) /// .arg(Arg::new("debug") @@ -458,7 +458,7 @@ impl<'help> Arg<'help> { /// [`Arg::long`]: Arg::long() /// [`Arg::multiple_values(true)`]: Arg::multiple_values() /// [`panic!`]: https://doc.rust-lang.org/std/macro.panic!.html - /// [`App`]: crate::App + /// [`Command`]: crate::Command #[inline] #[must_use] pub fn index(mut self, idx: usize) -> Self { @@ -478,7 +478,7 @@ impl<'help> Arg<'help> { /// **NOTE:** This will change the usage string to look like `$ prog [OPTIONS] [-- ]` if /// `ARG` is marked as `.last(true)`. /// - /// **NOTE:** This setting will imply [`crate::App::dont_collapse_args_in_usage`] because failing + /// **NOTE:** This setting will imply [`crate::Command::dont_collapse_args_in_usage`] because failing /// to set this can make the usage string very confusing. /// /// **NOTE**: This setting only applies to positional arguments, and has no effect on OPTIONS @@ -487,8 +487,8 @@ impl<'help> Arg<'help> { /// /// **CAUTION:** Using this setting *and* having child subcommands is not /// recommended with the exception of *also* using - /// [`crate::App::args_conflicts_with_subcommands`] - /// (or [`crate::App::subcommand_negates_reqs`] if the argument marked `Last` is also + /// [`crate::Command::args_conflicts_with_subcommands`] + /// (or [`crate::Command::subcommand_negates_reqs`] if the argument marked `Last` is also /// marked [`Arg::required`]) /// /// # Examples @@ -505,8 +505,8 @@ impl<'help> Arg<'help> { /// and requires that the `--` syntax be used to access it early. /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("first")) /// .arg(Arg::new("second")) /// .arg(Arg::new("third") @@ -526,8 +526,8 @@ impl<'help> Arg<'help> { /// failing to use the `--` syntax results in an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("first")) /// .arg(Arg::new("second")) /// .arg(Arg::new("third") @@ -576,8 +576,8 @@ impl<'help> Arg<'help> { /// Setting required requires that the argument be used at runtime. /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required(true) /// .takes_value(true) @@ -592,8 +592,8 @@ impl<'help> Arg<'help> { /// Setting required and then *not* supplying that argument at runtime is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required(true) /// .takes_value(true) @@ -635,8 +635,8 @@ impl<'help> Arg<'help> { /// required /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .requires("input") @@ -653,8 +653,8 @@ impl<'help> Arg<'help> { /// Setting [`Arg::requires(name)`] and *not* supplying that argument is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .requires("input") @@ -692,8 +692,8 @@ impl<'help> Arg<'help> { /// is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("exclusive") /// .takes_value(true) /// .exclusive(true) @@ -733,14 +733,14 @@ impl<'help> Arg<'help> { /// want to clutter the source with three duplicate [`Arg`] definitions. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("verb") /// .long("verbose") /// .short('v') /// .global(true)) - /// .subcommand(App::new("test")) - /// .subcommand(App::new("do-stuff")) + /// .subcommand(Command::new("test")) + /// .subcommand(Command::new("do-stuff")) /// .get_matches_from(vec![ /// "prog", "do-stuff", "--verbose" /// ]); @@ -776,8 +776,8 @@ impl<'help> Arg<'help> { /// An example with flags /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("verbose") /// .multiple_occurrences(true) /// .short('v')) @@ -792,8 +792,8 @@ impl<'help> Arg<'help> { /// An example with options /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("file") /// .multiple_occurrences(true) /// .takes_value(true) @@ -827,7 +827,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("verbosity") /// .short('v') /// .max_occurrences(3); @@ -836,8 +836,8 @@ impl<'help> Arg<'help> { /// Supplying less than the maximum number of arguments is allowed /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("verbosity") /// .max_occurrences(3) /// .short('v')) @@ -853,8 +853,8 @@ impl<'help> Arg<'help> { /// Supplying more than the maximum number of arguments is an error /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("verbosity") /// .max_occurrences(2) /// .short('v')) @@ -965,8 +965,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("mode") /// .long("mode") /// .takes_value(true)) @@ -1047,8 +1047,8 @@ impl<'help> Arg<'help> { /// An example with options /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("file") /// .takes_value(true) /// .multiple_values(true) @@ -1066,8 +1066,8 @@ impl<'help> Arg<'help> { /// Although `multiple_values` has been specified, we cannot use the argument more than once. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("file") /// .takes_value(true) /// .multiple_values(true) @@ -1084,8 +1084,8 @@ impl<'help> Arg<'help> { /// argument. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("file") /// .takes_value(true) /// .multiple_values(true) @@ -1110,8 +1110,8 @@ impl<'help> Arg<'help> { /// number, or to say [`Arg::multiple_occurrences`] is ok, but multiple values is not. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("file") /// .takes_value(true) /// .multiple_occurrences(true) @@ -1132,8 +1132,8 @@ impl<'help> Arg<'help> { /// As a final example, let's fix the above error and get a pretty message to the user :) /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("file") /// .takes_value(true) /// .multiple_occurrences(true) @@ -1148,7 +1148,7 @@ impl<'help> Arg<'help> { /// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument); /// ``` /// - /// [`subcommands`]: crate::App::subcommand() + /// [`subcommands`]: crate::Command::subcommand() /// [`Arg::number_of_values(1)`]: Arg::number_of_values() /// [maximum number of values]: Arg::max_values() /// [specific number of values]: Arg::number_of_values() @@ -1180,7 +1180,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("file") /// .short('f') /// .number_of_values(3); @@ -1189,8 +1189,8 @@ impl<'help> Arg<'help> { /// Not supplying the correct number of values is an error /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("file") /// .takes_value(true) /// .number_of_values(2) @@ -1225,7 +1225,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("file") /// .short('f') /// .max_values(3); @@ -1234,8 +1234,8 @@ impl<'help> Arg<'help> { /// Supplying less than the maximum number of values is allowed /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("file") /// .takes_value(true) /// .max_values(3) @@ -1253,8 +1253,8 @@ impl<'help> Arg<'help> { /// Supplying more than the maximum number of values is an error /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("file") /// .takes_value(true) /// .max_values(2) @@ -1290,7 +1290,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("file") /// .short('f') /// .min_values(3); @@ -1299,8 +1299,8 @@ impl<'help> Arg<'help> { /// Supplying more than the minimum number of values is allowed /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("file") /// .takes_value(true) /// .min_values(2) @@ -1318,8 +1318,8 @@ impl<'help> Arg<'help> { /// Supplying less than the minimum number of values is an error /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("file") /// .takes_value(true) /// .min_values(2) @@ -1351,7 +1351,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("cfg") /// .long("config") /// .value_name("FILE") @@ -1359,8 +1359,8 @@ impl<'help> Arg<'help> { /// ``` /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("config") /// .long("config") /// .value_name("FILE") @@ -1410,15 +1410,15 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("speed") /// .short('s') /// .value_names(&["fast", "slow"]); /// ``` /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("io") /// .long("io-files") /// .value_names(&["INFILE", "OUTFILE"])) @@ -1469,8 +1469,8 @@ impl<'help> Arg<'help> { /// To take a full command line and its arguments (for example, when writing a command wrapper): /// /// ``` - /// # use clap::{App, Arg, ValueHint}; - /// App::new("prog") + /// # use clap::{Command, Arg, ValueHint}; + /// Command::new("prog") /// .trailing_var_arg(true) /// .arg( /// Arg::new("command") @@ -1504,12 +1504,12 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// fn has_at(v: &str) -> Result<(), String> { /// if v.contains("@") { return Ok(()); } /// Err(String::from("The value did not contain the required @ sigil")) /// } - /// let res = App::new("prog") + /// let res = Command::new("prog") /// .arg(Arg::new("file") /// .index(1) /// .validator(has_at)) @@ -1542,14 +1542,14 @@ impl<'help> Arg<'help> { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```rust")] - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// # use std::ffi::{OsStr, OsString}; /// # use std::os::unix::ffi::OsStrExt; /// fn has_ampersand(v: &OsStr) -> Result<(), String> { /// if v.as_bytes().iter().any(|b| *b == b'&') { return Ok(()); } /// Err(String::from("The value did not contain the required & sigil")) /// } - /// let res = App::new("prog") + /// let res = Command::new("prog") /// .arg(Arg::new("file") /// .index(1) /// .validator_os(has_ampersand)) @@ -1596,12 +1596,12 @@ impl<'help> Arg<'help> { /// You can use the classical `"\d+"` regular expression to match digits only: /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// use regex::Regex; /// /// let digits = Regex::new(r"\d+").unwrap(); /// - /// let res = App::new("prog") + /// let res = Command::new("prog") /// .arg(Arg::new("digits") /// .index(1) /// .validator_regex(&digits, "only digits are allowed")) @@ -1615,12 +1615,12 @@ impl<'help> Arg<'help> { /// However, any valid `Regex` can be used: /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind}; /// use regex::Regex; /// /// let priority = Regex::new(r"[A-C]").unwrap(); /// - /// let res = App::new("prog") + /// let res = Command::new("prog") /// .arg(Arg::new("priority") /// .index(1) /// .validator_regex(priority, "only priorities A, B or C are allowed")) @@ -1660,7 +1660,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("mode") /// .takes_value(true) /// .possible_value("fast") @@ -1671,7 +1671,7 @@ impl<'help> Arg<'help> { /// The same using [`PossibleValue`]: /// /// ```rust - /// # use clap::{App, Arg, PossibleValue}; + /// # use clap::{Command, Arg, PossibleValue}; /// Arg::new("mode").takes_value(true) /// .possible_value(PossibleValue::new("fast")) /// // value with a help text @@ -1682,8 +1682,8 @@ impl<'help> Arg<'help> { /// ``` /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("mode") /// .long("mode") /// .takes_value(true) @@ -1701,8 +1701,8 @@ impl<'help> Arg<'help> { /// possible values. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("mode") /// .long("mode") /// .takes_value(true) @@ -1741,7 +1741,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("mode") /// .takes_value(true) /// .possible_values(["fast", "slow", "medium"]) @@ -1750,7 +1750,7 @@ impl<'help> Arg<'help> { /// The same using [`PossibleValue`]: /// /// ```rust - /// # use clap::{App, Arg, PossibleValue}; + /// # use clap::{Command, Arg, PossibleValue}; /// Arg::new("mode").takes_value(true).possible_values([ /// PossibleValue::new("fast"), /// // value with a help text @@ -1762,8 +1762,8 @@ impl<'help> Arg<'help> { /// ``` /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("mode") /// .long("mode") /// .takes_value(true) @@ -1779,8 +1779,8 @@ impl<'help> Arg<'help> { /// possible values. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("mode") /// .long("mode") /// .takes_value(true) @@ -1819,8 +1819,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("pv") + /// # use clap::{Command, Arg}; + /// let m = Command::new("pv") /// .arg(Arg::new("option") /// .long("--option") /// .takes_value(true) @@ -1836,8 +1836,8 @@ impl<'help> Arg<'help> { /// This setting also works when multiple values can be defined: /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("pv") + /// # use clap::{Command, Arg}; + /// let m = Command::new("pv") /// .arg(Arg::new("option") /// .short('o') /// .long("--option") @@ -1882,8 +1882,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("pat") /// .takes_value(true) /// .allow_hyphen_values(true) @@ -1899,8 +1899,8 @@ impl<'help> Arg<'help> { /// hyphen is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("pat") /// .takes_value(true) /// .long("pattern")) @@ -1935,10 +1935,10 @@ impl<'help> Arg<'help> { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```rust")] - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// use std::ffi::OsString; /// use std::os::unix::ffi::{OsStrExt,OsStringExt}; - /// let r = App::new("myprog") + /// let r = Command::new("myprog") /// .arg(Arg::new("arg").allow_invalid_utf8(true)) /// .try_get_matches_from(vec![ /// OsString::from("myprog"), @@ -1977,8 +1977,8 @@ impl<'help> Arg<'help> { /// The default is allowing empty values. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .long("config") /// .short('v') @@ -1994,8 +1994,8 @@ impl<'help> Arg<'help> { /// By adding this setting, we can forbid empty values. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .long("config") /// .short('v') @@ -2030,8 +2030,8 @@ impl<'help> Arg<'help> { /// it and the associated value. /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .require_equals(true) @@ -2047,8 +2047,8 @@ impl<'help> Arg<'help> { /// error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .require_equals(true) @@ -2087,8 +2087,8 @@ impl<'help> Arg<'help> { /// The following example shows the default behavior. /// /// ```rust - /// # use clap::{App, Arg}; - /// let delims = App::new("prog") + /// # use clap::{Command, Arg}; + /// let delims = Command::new("prog") /// .arg(Arg::new("option") /// .long("option") /// .use_value_delimiter(true) @@ -2105,8 +2105,8 @@ impl<'help> Arg<'help> { /// behavior /// /// ```rust - /// # use clap::{App, Arg}; - /// let nodelims = App::new("prog") + /// # use clap::{Command, Arg}; + /// let nodelims = Command::new("prog") /// .arg(Arg::new("option") /// .long("option") /// .takes_value(true)) @@ -2151,8 +2151,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("config") /// .short('c') /// .long("config") @@ -2192,8 +2192,8 @@ impl<'help> Arg<'help> { /// everything works in this first example, as we use a delimiter, as expected. /// /// ```rust - /// # use clap::{App, Arg}; - /// let delims = App::new("prog") + /// # use clap::{Command, Arg}; + /// let delims = Command::new("prog") /// .arg(Arg::new("opt") /// .short('o') /// .takes_value(true) @@ -2211,8 +2211,8 @@ impl<'help> Arg<'help> { /// In this next example, we will *not* use a delimiter. Notice it's now an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("opt") /// .short('o') /// .takes_value(true) @@ -2235,8 +2235,8 @@ impl<'help> Arg<'help> { /// is *not* an error. /// /// ```rust - /// # use clap::{App, Arg}; - /// let delims = App::new("prog") + /// # use clap::{Command, Arg}; + /// let delims = Command::new("prog") /// .arg(Arg::new("opt") /// .short('o') /// .takes_value(true) @@ -2282,7 +2282,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("vals") /// .takes_value(true) /// .multiple_values(true) @@ -2294,8 +2294,8 @@ impl<'help> Arg<'help> { /// to perform them /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("cmds") /// .takes_value(true) /// .multiple_values(true) @@ -2334,7 +2334,7 @@ impl<'help> Arg<'help> { /// ``` /// /// Will result in everything after `--` to be considered one raw argument. This behavior - /// may not be exactly what you are expecting and using [`crate::App::trailing_var_arg`] + /// may not be exactly what you are expecting and using [`crate::Command::trailing_var_arg`] /// may be more appropriate. /// /// **NOTE:** Implicitly sets [`Arg::takes_value(true)`] [`Arg::multiple_values(true)`], @@ -2378,8 +2378,8 @@ impl<'help> Arg<'help> { /// First we use the default value without providing any value at runtime. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("opt") /// .long("myopt") /// .default_value("myval")) @@ -2395,8 +2395,8 @@ impl<'help> Arg<'help> { /// Next we provide a value at runtime to override the default. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("opt") /// .long("myopt") /// .default_value("myval")) @@ -2472,11 +2472,11 @@ impl<'help> Arg<'help> { /// Here is an implementation of the common POSIX style `--color` argument. /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// - /// macro_rules! app { + /// macro_rules! cmd { /// () => {{ - /// App::new("prog") + /// Command::new("prog") /// .arg(Arg::new("color").long("color") /// .value_name("WHEN") /// .possible_values(["always", "auto", "never"]) @@ -2494,7 +2494,7 @@ impl<'help> Arg<'help> { /// /// // first, we'll provide no arguments /// - /// m = app!().get_matches_from(vec![ + /// m = cmd!().get_matches_from(vec![ /// "prog" /// ]); /// @@ -2504,7 +2504,7 @@ impl<'help> Arg<'help> { /// /// // next, we'll provide a runtime value to override the default (as usually done). /// - /// m = app!().get_matches_from(vec![ + /// m = cmd!().get_matches_from(vec![ /// "prog", "--color=never" /// ]); /// @@ -2514,7 +2514,7 @@ impl<'help> Arg<'help> { /// /// // finally, we will use the shortcut and only provide the argument without a value. /// - /// m = app!().get_matches_from(vec![ + /// m = cmd!().get_matches_from(vec![ /// "prog", "--color" /// ]); /// @@ -2591,11 +2591,11 @@ impl<'help> Arg<'help> { /// /// ```rust /// # use std::env; - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// /// env::set_var("MY_FLAG", "env"); /// - /// let m = App::new("prog") + /// let m = Command::new("prog") /// .arg(Arg::new("flag") /// .long("flag") /// .env("MY_FLAG") @@ -2615,12 +2615,12 @@ impl<'help> Arg<'help> { /// /// ```rust /// # use std::env; - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// /// env::set_var("TRUE_FLAG", "true"); /// env::set_var("FALSE_FLAG", "0"); /// - /// let m = App::new("prog") + /// let m = Command::new("prog") /// .arg(Arg::new("true_flag") /// .long("true_flag") /// .env("TRUE_FLAG")) @@ -2644,11 +2644,11 @@ impl<'help> Arg<'help> { /// /// ```rust /// # use std::env; - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// /// env::set_var("MY_FLAG", "env"); /// - /// let m = App::new("prog") + /// let m = Command::new("prog") /// .arg(Arg::new("flag") /// .long("flag") /// .env("MY_FLAG") @@ -2665,11 +2665,11 @@ impl<'help> Arg<'help> { /// /// ```rust /// # use std::env; - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// /// env::set_var("MY_FLAG", "env"); /// - /// let m = App::new("prog") + /// let m = Command::new("prog") /// .arg(Arg::new("flag") /// .long("flag") /// .env("MY_FLAG") @@ -2686,11 +2686,11 @@ impl<'help> Arg<'help> { /// /// ```rust /// # use std::env; - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// /// env::set_var("MY_FLAG_MULTI", "env1,env2"); /// - /// let m = App::new("prog") + /// let m = Command::new("prog") /// .arg(Arg::new("flag") /// .long("flag") /// .env("MY_FLAG_MULTI") @@ -2747,8 +2747,8 @@ impl<'help> Arg<'help> { /// `-h` or `--help` (by default). /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("cfg") /// .long("config") /// .help("Some help text describing the --config arg")) @@ -2797,8 +2797,8 @@ impl<'help> Arg<'help> { /// `-h` or `--help` (by default). /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("cfg") /// .long("config") /// .long_help( @@ -2854,8 +2854,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("a") // Typically args are grouped alphabetically by name. /// // Args without a display_order have a value of 999 and are /// // displayed alphabetically with all other 999 valued args. @@ -2902,7 +2902,7 @@ impl<'help> Arg<'help> { /// Override the [current] help section. /// - /// [current]: crate::App::help_heading + /// [current]: crate::Command::help_heading #[inline] #[must_use] pub fn help_heading(mut self, heading: O) -> Self @@ -2919,13 +2919,13 @@ impl<'help> Arg<'help> { /// This can also be helpful for arguments with very long flag names, or many/long value names. /// /// **NOTE:** To apply this setting to all arguments and subcommands, consider using - /// [`crate::App::next_line_help`] + /// [`crate::Command::next_line_help`] /// /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("opt") /// .long("long-option-flag") /// .short('o') @@ -2975,8 +2975,8 @@ impl<'help> Arg<'help> { /// Setting `Hidden` will hide the argument when displaying help text /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("cfg") /// .long("config") /// .hide(true) @@ -3016,13 +3016,13 @@ impl<'help> Arg<'help> { /// **NOTE:** Setting this requires [`Arg::takes_value`] /// /// To set this for all arguments, see - /// [`App::hide_possible_values`][crate::App::hide_possible_values]. + /// [`Command::hide_possible_values`][crate::Command::hide_possible_values]. /// /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("mode") /// .long("mode") /// .possible_values(["fast", "slow"]) @@ -3050,8 +3050,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("connect") + /// # use clap::{Command, Arg}; + /// let m = Command::new("connect") /// .arg(Arg::new("host") /// .long("host") /// .default_value("localhost") @@ -3079,8 +3079,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("mode") /// .long("mode") /// .env("MODE") @@ -3108,8 +3108,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("connect") + /// # use clap::{Command, Arg}; + /// let m = Command::new("connect") /// .arg(Arg::new("host") /// .long("host") /// .env("CONNECT") @@ -3141,7 +3141,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("debug") /// .hide_short_help(true); /// ``` @@ -3149,8 +3149,8 @@ impl<'help> Arg<'help> { /// Setting `hide_short_help(true)` will hide the argument when displaying short help text /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("cfg") /// .long("config") /// .hide_short_help(true) @@ -3176,8 +3176,8 @@ impl<'help> Arg<'help> { /// However, when --help is called /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("cfg") /// .long("config") /// .hide_short_help(true) @@ -3222,8 +3222,8 @@ impl<'help> Arg<'help> { /// Setting `hide_long_help(true)` will hide the argument when displaying long help text /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("cfg") /// .long("config") /// .hide_long_help(true) @@ -3249,8 +3249,8 @@ impl<'help> Arg<'help> { /// However, when -h is called /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("cfg") /// .long("config") /// .hide_long_help(true) @@ -3291,7 +3291,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("debug") /// .long("debug") /// .group("mode") @@ -3302,8 +3302,8 @@ impl<'help> Arg<'help> { /// was one of said arguments. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("debug") /// .long("debug") /// .group("mode")) @@ -3328,7 +3328,7 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// Arg::new("debug") /// .long("debug") /// .groups(&["mode", "verbosity"]) @@ -3339,8 +3339,8 @@ impl<'help> Arg<'help> { /// was one of said arguments. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("debug") /// .long("debug") /// .groups(&["mode", "verbosity"])) @@ -3382,8 +3382,8 @@ impl<'help> Arg<'help> { /// First we use the default value only if another arg is present at runtime. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("flag") /// .long("flag")) /// .arg(Arg::new("other") @@ -3399,8 +3399,8 @@ impl<'help> Arg<'help> { /// Next we run the same test, but without providing `--flag`. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("flag") /// .long("flag")) /// .arg(Arg::new("other") @@ -3416,8 +3416,8 @@ impl<'help> Arg<'help> { /// Now lets only use the default value if `--opt` contains the value `special`. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("opt") /// .takes_value(true) /// .long("opt")) @@ -3435,8 +3435,8 @@ impl<'help> Arg<'help> { /// default value. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("opt") /// .takes_value(true) /// .long("opt")) @@ -3454,8 +3454,8 @@ impl<'help> Arg<'help> { /// value of some other Arg. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("flag") /// .long("flag")) /// .arg(Arg::new("other") @@ -3509,8 +3509,8 @@ impl<'help> Arg<'help> { /// First we use the default value only if another arg is present at runtime. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("flag") /// .long("flag")) /// .arg(Arg::new("opt") @@ -3532,8 +3532,8 @@ impl<'help> Arg<'help> { /// Next we run the same test, but without providing `--flag`. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("flag") /// .long("flag")) /// .arg(Arg::new("other") @@ -3553,8 +3553,8 @@ impl<'help> Arg<'help> { /// true, only the first evaluated "wins" /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .arg(Arg::new("flag") /// .long("flag")) /// .arg(Arg::new("opt") @@ -3619,8 +3619,8 @@ impl<'help> Arg<'help> { /// but it's not an error because the `unless` arg has been supplied. /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present("dbg") /// .takes_value(true) @@ -3637,8 +3637,8 @@ impl<'help> Arg<'help> { /// Setting `Arg::required_unless_present(name)` and *not* supplying `name` or this arg is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present("dbg") /// .takes_value(true) @@ -3681,8 +3681,8 @@ impl<'help> Arg<'help> { /// because *all* of the `names` args have been supplied. /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present_all(&["dbg", "infile"]) /// .takes_value(true) @@ -3703,8 +3703,8 @@ impl<'help> Arg<'help> { /// either *all* of `unless` args or the `self` arg is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present_all(&["dbg", "infile"]) /// .takes_value(true) @@ -3758,8 +3758,8 @@ impl<'help> Arg<'help> { /// have been supplied. /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present_any(&["dbg", "infile"]) /// .takes_value(true) @@ -3780,8 +3780,8 @@ impl<'help> Arg<'help> { /// or this arg is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_unless_present_any(&["dbg", "infile"]) /// .takes_value(true) @@ -3824,8 +3824,8 @@ impl<'help> Arg<'help> { /// ``` /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .required_if_eq("other", "special") @@ -3839,7 +3839,7 @@ impl<'help> Arg<'help> { /// /// assert!(res.is_ok()); // We didn't use --other=special, so "cfg" wasn't required /// - /// let res = App::new("prog") + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .required_if_eq("other", "special") @@ -3855,7 +3855,7 @@ impl<'help> Arg<'help> { /// assert!(res.is_err()); /// assert_eq!(res.unwrap_err().kind(), ErrorKind::MissingRequiredArgument); /// - /// let res = App::new("prog") + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .required_if_eq("other", "special") @@ -3870,7 +3870,7 @@ impl<'help> Arg<'help> { /// // By default, the comparison is case-sensitive, so "cfg" wasn't required /// assert!(res.is_ok()); /// - /// let res = App::new("prog") + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .required_if_eq("other", "special") @@ -3918,8 +3918,8 @@ impl<'help> Arg<'help> { /// anything other than `val`, this argument isn't required. /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_if_eq_any(&[ /// ("extra", "val"), @@ -3944,8 +3944,8 @@ impl<'help> Arg<'help> { /// value of `val` but *not* using this arg is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_if_eq_any(&[ /// ("extra", "val"), @@ -3998,8 +3998,8 @@ impl<'help> Arg<'help> { /// anything other than `val`, this argument isn't required. /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_if_eq_all(&[ /// ("extra", "val"), @@ -4024,8 +4024,8 @@ impl<'help> Arg<'help> { /// value of `val` but *not* using this arg is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .required_if_eq_all(&[ /// ("extra", "val"), @@ -4074,8 +4074,8 @@ impl<'help> Arg<'help> { /// `val`, the other argument isn't required. /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .requires_if("my.cfg", "other") @@ -4092,8 +4092,8 @@ impl<'help> Arg<'help> { /// `arg` is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .requires_if("my.cfg", "input") @@ -4137,8 +4137,8 @@ impl<'help> Arg<'help> { /// than `val`, `arg` isn't required. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .requires_ifs(&[ @@ -4190,8 +4190,8 @@ impl<'help> Arg<'help> { /// argument isn't required /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .requires("input") @@ -4211,8 +4211,8 @@ impl<'help> Arg<'help> { /// error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .requires_all(&["input", "output"]) @@ -4263,8 +4263,8 @@ impl<'help> Arg<'help> { /// Setting conflicting argument, and having both arguments present at runtime is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .conflicts_with("debug") @@ -4313,8 +4313,8 @@ impl<'help> Arg<'help> { /// conflicting argument is an error. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("cfg") /// .takes_value(true) /// .conflicts_with_all(&["debug", "input"]) @@ -4355,9 +4355,9 @@ impl<'help> Arg<'help> { /// /// # Examples /// - /// ```rust # use clap::{App, Arg}; - /// # use clap::{App, arg}; - /// let m = App::new("prog") + /// ```rust # use clap::{Command, Arg}; + /// # use clap::{Command, arg}; + /// let m = Command::new("prog") /// .arg(arg!(-f --flag "some flag") /// .conflicts_with("debug")) /// .arg(arg!(-d --debug "other flag")) @@ -4381,8 +4381,8 @@ impl<'help> Arg<'help> { /// preventing a "Unexpected multiple usage" error): /// /// ```rust - /// # use clap::{App, arg}; - /// let m = App::new("posix") + /// # use clap::{Command, arg}; + /// let m = Command::new("posix") /// .arg(arg!(--flag "some flag").overrides_with("flag")) /// .get_matches_from(vec!["posix", "--flag", "--flag"]); /// assert!(m.is_present("flag")); @@ -4394,8 +4394,8 @@ impl<'help> Arg<'help> { /// if it's a flag and it already accepts multiple occurrences. /// /// ``` - /// # use clap::{App, arg}; - /// let m = App::new("posix") + /// # use clap::{Command, arg}; + /// let m = Command::new("posix") /// .arg(arg!(--flag ... "some flag").overrides_with("flag")) /// .get_matches_from(vec!["", "--flag", "--flag", "--flag", "--flag"]); /// assert!(m.is_present("flag")); @@ -4407,8 +4407,8 @@ impl<'help> Arg<'help> { /// occurrence happened. /// /// ``` - /// # use clap::{App, arg}; - /// let m = App::new("posix") + /// # use clap::{Command, arg}; + /// let m = Command::new("posix") /// .arg(arg!(--opt "some option").overrides_with("opt")) /// .get_matches_from(vec!["", "--opt=some", "--opt=other"]); /// assert!(m.is_present("opt")); @@ -4419,8 +4419,8 @@ impl<'help> Arg<'help> { /// This will also work when [`Arg::multiple_values`] is enabled: /// /// ``` - /// # use clap::{App, Arg}; - /// let m = App::new("posix") + /// # use clap::{Command, Arg}; + /// let m = Command::new("posix") /// .arg( /// Arg::new("opt") /// .long("opt") @@ -4438,8 +4438,8 @@ impl<'help> Arg<'help> { /// will ignore the "override self" setting. /// /// ``` - /// # use clap::{App, arg}; - /// let m = App::new("posix") + /// # use clap::{Command, arg}; + /// let m = Command::new("posix") /// .arg(arg!(--opt ... "some option") /// .multiple_values(true) /// .overrides_with("opt")) @@ -4465,8 +4465,8 @@ impl<'help> Arg<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, arg}; - /// let m = App::new("prog") + /// # use clap::{Command, arg}; + /// let m = Command::new("prog") /// .arg(arg!(-f --flag "some flag") /// .conflicts_with("color")) /// .arg(arg!(-d --debug "other flag")) diff --git a/src/build/arg_group.rs b/src/build/arg_group.rs index b635a23725f..dbcf9aa41b0 100644 --- a/src/build/arg_group.rs +++ b/src/build/arg_group.rs @@ -37,8 +37,8 @@ use yaml_rust::Yaml; /// the arguments from the specified group is present at runtime. /// /// ```rust -/// # use clap::{App, arg, ArgGroup, ErrorKind}; -/// let result = App::new("app") +/// # use clap::{Command, arg, ArgGroup, ErrorKind}; +/// let result = Command::new("cmd") /// .arg(arg!(--"set-ver" "set the version manually").required(false)) /// .arg(arg!(--major "auto increase major")) /// .arg(arg!(--minor "auto increase minor")) @@ -46,7 +46,7 @@ use yaml_rust::Yaml; /// .group(ArgGroup::new("vers") /// .args(&["set-ver", "major", "minor", "patch"]) /// .required(true)) -/// .try_get_matches_from(vec!["app", "--major", "--patch"]); +/// .try_get_matches_from(vec!["cmd", "--major", "--patch"]); /// // Because we used two args in the group it's an error /// assert!(result.is_err()); /// let err = result.unwrap_err(); @@ -55,8 +55,8 @@ use yaml_rust::Yaml; /// This next example shows a passing parse of the same scenario /// /// ```rust -/// # use clap::{App, arg, ArgGroup}; -/// let result = App::new("app") +/// # use clap::{Command, arg, ArgGroup}; +/// let result = Command::new("cmd") /// .arg(arg!(--"set-ver" "set the version manually").required(false)) /// .arg(arg!(--major "auto increase major")) /// .arg(arg!(--minor "auto increase minor")) @@ -64,7 +64,7 @@ use yaml_rust::Yaml; /// .group(ArgGroup::new("vers") /// .args(&["set-ver", "major", "minor","patch"]) /// .required(true)) -/// .try_get_matches_from(vec!["app", "--major"]); +/// .try_get_matches_from(vec!["cmd", "--major"]); /// assert!(result.is_ok()); /// let matches = result.unwrap(); /// // We may not know which of the args was used, so we can test for the group... @@ -104,7 +104,7 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, ArgGroup}; + /// # use clap::{Command, ArgGroup}; /// ArgGroup::new("config") /// # ; /// ``` @@ -117,7 +117,7 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, ArgGroup}; + /// # use clap::{Command, ArgGroup}; /// ArgGroup::default().name("config") /// # ; /// ``` @@ -139,8 +139,8 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ArgGroup}; - /// let m = App::new("myprog") + /// # use clap::{Command, Arg, ArgGroup}; + /// let m = Command::new("myprog") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("color") @@ -166,8 +166,8 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ArgGroup}; - /// let m = App::new("myprog") + /// # use clap::{Command, Arg, ArgGroup}; + /// let m = Command::new("myprog") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("color") @@ -197,8 +197,8 @@ impl<'help> ArgGroup<'help> { /// group /// /// ```rust - /// # use clap::{App, Arg, ArgGroup}; - /// let m = App::new("myprog") + /// # use clap::{Command, Arg, ArgGroup}; + /// let m = Command::new("myprog") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("color") @@ -214,8 +214,8 @@ impl<'help> ArgGroup<'help> { /// an error if more than one of the args in the group was used. /// /// ```rust - /// # use clap::{App, Arg, ArgGroup, ErrorKind}; - /// let result = App::new("myprog") + /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// let result = Command::new("myprog") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("color") @@ -242,7 +242,7 @@ impl<'help> ArgGroup<'help> { /// This is unless conflicting with another argument. A required group will be displayed in /// the usage string of the application in the format ``. /// - /// **NOTE:** This setting only applies to the current [`App`] / [`Subcommand`]s, and not + /// **NOTE:** This setting only applies to the current [`Command`] / [`Subcommand`]s, and not /// globally. /// /// **NOTE:** By default, [`ArgGroup::multiple`] is set to `false` which when combined with @@ -253,8 +253,8 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ArgGroup, ErrorKind}; - /// let result = App::new("myprog") + /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// let result = Command::new("myprog") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("color") @@ -271,7 +271,7 @@ impl<'help> ArgGroup<'help> { /// /// [`Subcommand`]: crate::Subcommand /// [`ArgGroup::multiple`]: ArgGroup::multiple() - /// [`App`]: crate::App + /// [`Command`]: crate::Command #[inline] #[must_use] pub fn required(mut self, yes: bool) -> Self { @@ -290,8 +290,8 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ArgGroup, ErrorKind}; - /// let result = App::new("myprog") + /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// let result = Command::new("myprog") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("color") @@ -327,8 +327,8 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ArgGroup, ErrorKind}; - /// let result = App::new("myprog") + /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// let result = Command::new("myprog") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("color") @@ -368,8 +368,8 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ArgGroup, ErrorKind}; - /// let result = App::new("myprog") + /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// let result = Command::new("myprog") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("color") @@ -402,8 +402,8 @@ impl<'help> ArgGroup<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ArgGroup, ErrorKind}; - /// let result = App::new("myprog") + /// # use clap::{Command, Arg, ArgGroup, ErrorKind}; + /// let result = Command::new("myprog") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("color") diff --git a/src/build/arg_tests.rs b/src/build/arg_tests.rs deleted file mode 100644 index 6a6506e43f9..00000000000 --- a/src/build/arg_tests.rs +++ /dev/null @@ -1,8 +0,0 @@ -use crate::Arg; - -// This test will *fail to compile* if Arg is not Send + Sync -#[test] -fn arg_send_sync() { - fn foo(_: T) {} - foo(Arg::new("test")) -} diff --git a/src/build/app.rs b/src/build/command.rs similarity index 87% rename from src/build/app.rs rename to src/build/command.rs index bcc36ea2d4d..5e95fd6854d 100644 --- a/src/build/app.rs +++ b/src/build/command.rs @@ -35,19 +35,19 @@ use crate::build::debug_asserts::assert_app; /// /// This includes defining arguments, subcommands, parser behavior, and help output. /// Once all configuration is complete, -/// the [`App::get_matches`] family of methods starts the runtime-parsing +/// the [`Command::get_matches`] family of methods starts the runtime-parsing /// process. These methods then return information about the user supplied /// arguments (or lack thereof). /// /// When deriving a [`Parser`][crate::Parser], you can use /// [`IntoApp::into_app`][crate::IntoApp::into_app] to access the -/// `App`. +/// `Command`. /// /// # Examples /// /// ```no_run -/// # use clap::{App, Arg}; -/// let m = App::new("My Program") +/// # use clap::{Command, Arg}; +/// let m = Command::new("My Program") /// .author("Me, me@mail.com") /// .version("1.0.2") /// .about("Explains in brief what the program does") @@ -60,7 +60,11 @@ use crate::build::debug_asserts::assert_app; /// /// // Your program logic starts here... /// ``` -/// [`App::get_matches`]: App::get_matches() +/// [`App::get_matches`]: Command::get_matches() +pub type Command<'help> = App<'help>; + +/// Deprecated, replaced with [`Command`] +#[deprecated(since = "3.1.0", note = "Replaced with `Command`")] #[derive(Debug, Clone, PartialEq, Eq)] pub struct App<'help> { id: Id, @@ -101,7 +105,7 @@ pub struct App<'help> { /// Basic API impl<'help> App<'help> { - /// Creates a new instance of an `App`. + /// Creates a new instance of an `Command`. /// /// It is common, but not required, to use binary name as the `name`. This /// name will only be displayed to the user when they request to print @@ -112,8 +116,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("My Program") + /// # use clap::Command; + /// Command::new("My Program") /// # ; /// ``` pub fn new>(name: S) -> Self { @@ -151,8 +155,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, arg, Arg}; - /// App::new("myprog") + /// # use clap::{Command, arg, Arg}; + /// Command::new("myprog") /// // Adding a single "flag" argument with a short and help text, using Arg::new() /// .arg( /// Arg::new("debug") @@ -188,8 +192,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, arg, Arg}; - /// App::new("myprog") + /// # use clap::{Command, arg, Arg}; + /// Command::new("myprog") /// .args(&[ /// arg!("[debug] -d 'turns on debugging info'"), /// Arg::new("input").index(1).help("the input file to use") @@ -213,28 +217,28 @@ impl<'help> App<'help> { self } - /// Allows one to mutate an [`Arg`] after it's been added to an [`App`]. + /// Allows one to mutate an [`Arg`] after it's been added to an [`Command`]. /// /// This can be useful for modifying the auto-generated help or version arguments. /// /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// - /// let mut app = App::new("foo") + /// let mut cmd = Command::new("foo") /// .arg(Arg::new("bar") /// .short('b')) /// .mut_arg("bar", |a| a.short('B')); /// - /// let res = app.try_get_matches_from_mut(vec!["foo", "-b"]); + /// let res = cmd.try_get_matches_from_mut(vec!["foo", "-b"]); /// /// // Since we changed `bar`'s short to "B" this should err as there /// // is no `-b` anymore, only `-B` /// /// assert!(res.is_err()); /// - /// let res = app.try_get_matches_from_mut(vec!["foo", "-B"]); + /// let res = cmd.try_get_matches_from_mut(vec!["foo", "-B"]); /// assert!(res.is_ok()); /// ``` #[must_use] @@ -280,8 +284,8 @@ impl<'help> App<'help> { /// of the arguments from the specified group is present at runtime. /// /// ```no_run - /// # use clap::{App, arg, ArgGroup}; - /// App::new("app") + /// # use clap::{Command, arg, ArgGroup}; + /// Command::new("cmd") /// .arg(arg!("--set-ver [ver] 'set the version manually'")) /// .arg(arg!("--major 'auto increase major'")) /// .arg(arg!("--minor 'auto increase minor'")) @@ -298,13 +302,13 @@ impl<'help> App<'help> { self } - /// Adds multiple [`ArgGroup`]s to the [`App`] at once. + /// Adds multiple [`ArgGroup`]s to the [`Command`] at once. /// /// # Examples /// /// ```no_run - /// # use clap::{App, arg, ArgGroup}; - /// App::new("app") + /// # use clap::{Command, arg, ArgGroup}; + /// Command::new("cmd") /// .arg(arg!("--set-ver [ver] 'set the version manually'")) /// .arg(arg!("--major 'auto increase major'")) /// .arg(arg!("--minor 'auto increase minor'")) @@ -334,20 +338,20 @@ impl<'help> App<'help> { /// Adds a subcommand to the list of valid possibilities. /// - /// Subcommands are effectively sub-[`App`]s, because they can contain their own arguments, - /// subcommands, version, usage, etc. They also function just like [`App`]s, in that they get + /// Subcommands are effectively sub-[`Command`]s, because they can contain their own arguments, + /// subcommands, version, usage, etc. They also function just like [`Command`]s, in that they get /// their own auto generated help, version, and usage. /// - /// A subcommand's [`App::name`] will be used for: + /// A subcommand's [`Command::name`] will be used for: /// - The argument the user passes in /// - Programmatically looking up the subcommand /// /// # Examples /// /// ```no_run - /// # use clap::{App, arg}; - /// App::new("myprog") - /// .subcommand(App::new("config") + /// # use clap::{Command, arg}; + /// Command::new("myprog") + /// .subcommand(Command::new("config") /// .about("Controls configuration features") /// .arg(arg!(" 'Required configuration file to use'"))) /// # ; @@ -364,12 +368,12 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, }; - /// # App::new("myprog") + /// # use clap::{Command, Arg, }; + /// # Command::new("myprog") /// .subcommands( vec![ - /// App::new("config").about("Controls configuration functionality") + /// Command::new("config").about("Controls configuration functionality") /// .arg(Arg::new("config_file").index(1)), - /// App::new("debug").about("Controls debug functionality")]) + /// Command::new("debug").about("Controls debug functionality")]) /// # ; /// ``` /// [`IntoIterator`]: std::iter::IntoIterator @@ -398,20 +402,20 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// fn app() -> App<'static> { - /// App::new("foo") + /// # use clap::{Command, Arg}; + /// fn cmd() -> Command<'static> { + /// Command::new("foo") /// .arg(Arg::new("bar").short('b') /// ) /// } /// /// #[test] /// fn verify_app() { - /// app().debug_assert(); + /// cmd().debug_assert(); /// } /// /// fn main() { - /// let m = app().get_matches_from(vec!["foo", "-b"]); + /// let m = cmd().get_matches_from(vec!["foo", "-b"]); /// println!("{}", m.is_present("bar")); /// } /// ``` @@ -424,9 +428,9 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, ErrorKind}; - /// let mut app = App::new("myprog"); - /// let err = app.error(ErrorKind::InvalidValue, "Some failure case"); + /// # use clap::{Command, ErrorKind}; + /// let mut cmd = Command::new("myprog"); + /// let err = cmd.error(ErrorKind::InvalidValue, "Some failure case"); /// ``` pub fn error(&mut self, kind: ErrorKind, message: impl std::fmt::Display) -> Error { Error::raw(kind, message).format(self) @@ -441,13 +445,13 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// let matches = App::new("myprog") + /// # use clap::{Command, Arg}; + /// let matches = Command::new("myprog") /// // Args and options go here... /// .get_matches(); /// ``` /// [`env::args_os`]: std::env::args_os() - /// [`App::try_get_matches_from_mut`]: App::try_get_matches_from_mut() + /// [`App::try_get_matches_from_mut`]: Command::try_get_matches_from_mut() #[inline] pub fn get_matches(self) -> ArgMatches { self.get_matches_from(&mut env::args_os()) @@ -455,7 +459,7 @@ impl<'help> App<'help> { /// Parse [`env::args_os`], exiting on failure. /// - /// Like [`App::get_matches`] but doesn't consume the `App`. + /// Like [`App::get_matches`] but doesn't consume the `Command`. /// /// # Panics /// @@ -464,14 +468,14 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// let mut app = App::new("myprog") + /// # use clap::{Command, Arg}; + /// let mut cmd = Command::new("myprog") /// // Args and options go here... /// ; - /// let matches = app.get_matches_mut(); + /// let matches = cmd.get_matches_mut(); /// ``` /// [`env::args_os`]: std::env::args_os() - /// [`App::get_matches`]: App::get_matches() + /// [`App::get_matches`]: Command::get_matches() pub fn get_matches_mut(&mut self) -> ArgMatches { self.try_get_matches_from_mut(&mut env::args_os()) .unwrap_or_else(|e| e.exit()) @@ -491,8 +495,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// let matches = App::new("myprog") + /// # use clap::{Command, Arg}; + /// let matches = Command::new("myprog") /// // Args and options go here... /// .try_get_matches() /// .unwrap_or_else(|e| e.exit()); @@ -514,7 +518,7 @@ impl<'help> App<'help> { /// Parse the specified arguments, exiting on failure. /// /// **NOTE:** The first argument will be parsed as the binary name unless - /// [`App::no_binary_name`] is used. + /// [`Command::no_binary_name`] is used. /// /// # Panics /// @@ -523,14 +527,14 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// let arg_vec = vec!["my_prog", "some", "args", "to", "parse"]; /// - /// let matches = App::new("myprog") + /// let matches = Command::new("myprog") /// // Args and options go here... /// .get_matches_from(arg_vec); /// ``` - /// [`App::get_matches`]: App::get_matches() + /// [`App::get_matches`]: Command::get_matches() /// [`clap::Result`]: Result /// [`Vec`]: std::vec::Vec pub fn get_matches_from(mut self, itr: I) -> ArgMatches @@ -552,7 +556,7 @@ impl<'help> App<'help> { /// perform a [`std::process::exit`] yourself. /// /// **NOTE:** The first argument will be parsed as the binary name unless - /// [`App::no_binary_name`] is used. + /// [`Command::no_binary_name`] is used. /// /// # Panics /// @@ -561,16 +565,16 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// let arg_vec = vec!["my_prog", "some", "args", "to", "parse"]; /// - /// let matches = App::new("myprog") + /// let matches = Command::new("myprog") /// // Args and options go here... /// .try_get_matches_from(arg_vec) /// .unwrap_or_else(|e| e.exit()); /// ``` - /// [`App::get_matches_from`]: App::get_matches_from() - /// [`App::try_get_matches`]: App::try_get_matches() + /// [`App::get_matches_from`]: Command::get_matches_from() + /// [`App::try_get_matches`]: Command::try_get_matches() /// [`Error::exit`]: crate::Error::exit() /// [`std::process::exit`]: std::process::exit() /// [`clap::Error`]: crate::Error @@ -589,7 +593,7 @@ impl<'help> App<'help> { /// Parse the specified arguments, returning a [`clap::Result`] on failure. /// - /// Like [`App::try_get_matches_from`] but doesn't consume the `App`. + /// Like [`App::try_get_matches_from`] but doesn't consume the `Command`. /// /// **NOTE:** This method WILL NOT exit when `--help` or `--version` (or short versions) are /// used. It will return a [`clap::Error`], where the [`kind`] is a [`ErrorKind::DisplayHelp`] @@ -597,7 +601,7 @@ impl<'help> App<'help> { /// perform a [`std::process::exit`] yourself. /// /// **NOTE:** The first argument will be parsed as the binary name unless - /// [`App::no_binary_name`] is used. + /// [`Command::no_binary_name`] is used. /// /// # Panics /// @@ -606,15 +610,15 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// let arg_vec = vec!["my_prog", "some", "args", "to", "parse"]; /// - /// let mut app = App::new("myprog"); + /// let mut cmd = Command::new("myprog"); /// // Args and options go here... - /// let matches = app.try_get_matches_from_mut(arg_vec) + /// let matches = cmd.try_get_matches_from_mut(arg_vec) /// .unwrap_or_else(|e| e.exit()); /// ``` - /// [`App::try_get_matches_from`]: App::try_get_matches_from() + /// [`App::try_get_matches_from`]: Command::try_get_matches_from() /// [`clap::Result`]: Result /// [`clap::Error`]: crate::Error /// [`kind`]: crate::Error @@ -673,14 +677,14 @@ impl<'help> App<'help> { /// Prints the short help message (`-h`) to [`io::stdout()`]. /// - /// See also [`App::print_long_help`]. + /// See also [`Command::print_long_help`]. /// /// # Examples /// /// ```rust - /// # use clap::App; - /// let mut app = App::new("myprog"); - /// app.print_help(); + /// # use clap::Command; + /// let mut cmd = Command::new("myprog"); + /// cmd.print_help(); /// ``` /// [`io::stdout()`]: std::io::stdout() pub fn print_help(&mut self) -> io::Result<()> { @@ -695,14 +699,14 @@ impl<'help> App<'help> { /// Prints the long help message (`--help`) to [`io::stdout()`]. /// - /// See also [`App::print_help`]. + /// See also [`Command::print_help`]. /// /// # Examples /// /// ```rust - /// # use clap::App; - /// let mut app = App::new("myprog"); - /// app.print_long_help(); + /// # use clap::Command; + /// let mut cmd = Command::new("myprog"); + /// cmd.print_long_help(); /// ``` /// [`io::stdout()`]: std::io::stdout() /// [`BufWriter`]: std::io::BufWriter @@ -720,16 +724,16 @@ impl<'help> App<'help> { /// Writes the short help message (`-h`) to a [`io::Write`] object. /// - /// See also [`App::write_long_help`]. + /// See also [`Command::write_long_help`]. /// /// # Examples /// /// ```rust - /// # use clap::App; + /// # use clap::Command; /// use std::io; - /// let mut app = App::new("myprog"); + /// let mut cmd = Command::new("myprog"); /// let mut out = io::stdout(); - /// app.write_help(&mut out).expect("failed to write to stdout"); + /// cmd.write_help(&mut out).expect("failed to write to stdout"); /// ``` /// [`io::Write`]: std::io::Write /// [`-h` (short)]: Arg::help() @@ -744,16 +748,16 @@ impl<'help> App<'help> { /// Writes the long help message (`--help`) to a [`io::Write`] object. /// - /// See also [`App::write_help`]. + /// See also [`Command::write_help`]. /// /// # Examples /// /// ```rust - /// # use clap::App; + /// # use clap::Command; /// use std::io; - /// let mut app = App::new("myprog"); + /// let mut cmd = Command::new("myprog"); /// let mut out = io::stdout(); - /// app.write_long_help(&mut out).expect("failed to write to stdout"); + /// cmd.write_long_help(&mut out).expect("failed to write to stdout"); /// ``` /// [`io::Write`]: std::io::Write /// [`-h` (short)]: Arg::help() @@ -768,7 +772,7 @@ impl<'help> App<'help> { /// Version message rendered as if the user ran `-V`. /// - /// See also [`App::render_long_version`]. + /// See also [`Command::render_long_version`]. /// /// ### Coloring /// @@ -777,14 +781,14 @@ impl<'help> App<'help> { /// ### Examples /// /// ```rust - /// # use clap::App; + /// # use clap::Command; /// use std::io; - /// let app = App::new("myprog"); - /// println!("{}", app.render_version()); + /// let cmd = Command::new("myprog"); + /// println!("{}", cmd.render_version()); /// ``` /// [`io::Write`]: std::io::Write - /// [`-V` (short)]: App::version() - /// [`--version` (long)]: App::long_version() + /// [`-V` (short)]: Command::version() + /// [`--version` (long)]: Command::long_version() /// [ANSI escape codes]: https://en.wikipedia.org/wiki/ANSI_escape_code pub fn render_version(&self) -> String { self._render_version(false) @@ -792,7 +796,7 @@ impl<'help> App<'help> { /// Version message rendered as if the user ran `--version`. /// - /// See also [`App::render_version`]. + /// See also [`Command::render_version`]. /// /// ### Coloring /// @@ -801,14 +805,14 @@ impl<'help> App<'help> { /// ### Examples /// /// ```rust - /// # use clap::App; + /// # use clap::Command; /// use std::io; - /// let app = App::new("myprog"); - /// println!("{}", app.render_long_version()); + /// let cmd = Command::new("myprog"); + /// println!("{}", cmd.render_long_version()); /// ``` /// [`io::Write`]: std::io::Write - /// [`-V` (short)]: App::version() - /// [`--version` (long)]: App::long_version() + /// [`-V` (short)]: Command::version() + /// [`--version` (long)]: Command::long_version() /// [ANSI escape codes]: https://en.wikipedia.org/wiki/ANSI_escape_code pub fn render_long_version(&self) -> String { self._render_version(true) @@ -819,10 +823,10 @@ impl<'help> App<'help> { /// ### Examples /// /// ```rust - /// # use clap::App; + /// # use clap::Command; /// use std::io; - /// let mut app = App::new("myprog"); - /// println!("{}", app.render_usage()); + /// let mut cmd = Command::new("myprog"); + /// println!("{}", cmd.render_usage()); /// ``` pub fn render_usage(&mut self) -> String { // If there are global arguments, or settings we need to propagate them down to subcommands @@ -833,7 +837,7 @@ impl<'help> App<'help> { } } -/// App-wide Settings +/// Command-wide Settings /// /// These settings will apply to the top-level command and all subcommands, by default. Some /// settings can be overridden in subcommands. @@ -846,8 +850,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, arg}; - /// let m = App::new("myprog") + /// # use clap::{Command, arg}; + /// let m = Command::new("myprog") /// .no_binary_name(true) /// .arg(arg!( ... "commands to run")) /// .get_matches_from(vec!["command", "set"]); @@ -855,7 +859,7 @@ impl<'help> App<'help> { /// let cmds: Vec<&str> = m.values_of("cmd").unwrap().collect(); /// assert_eq!(cmds, ["command", "set"]); /// ``` - /// [`try_get_matches_from_mut`]: crate::App::try_get_matches_from_mut() + /// [`try_get_matches_from_mut`]: crate::Command::try_get_matches_from_mut() #[inline] pub fn no_binary_name(self, yes: bool) -> Self { if yes { @@ -875,14 +879,14 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, arg}; - /// let app = App::new("app") + /// # use clap::{Command, arg}; + /// let cmd = Command::new("cmd") /// .ignore_errors(true) /// .arg(arg!(-c --config "Sets a custom config file").required(false)) /// .arg(arg!(-x --stuff "Sets a custom stuff file").required(false)) /// .arg(arg!(f: -f "Flag")); /// - /// let r = app.try_get_matches_from(vec!["app", "-c", "file", "-f", "-x"]); + /// let r = cmd.try_get_matches_from(vec!["cmd", "-c", "file", "-f", "-x"]); /// /// assert!(r.is_ok(), "unexpected error: {:?}", r); /// let m = r.unwrap(); @@ -918,7 +922,7 @@ impl<'help> App<'help> { } } - /// Disables the automatic delimiting of values after `--` or when [`App::trailing_var_arg`] + /// Disables the automatic delimiting of values after `--` or when [`Command::trailing_var_arg`] /// was used. /// /// **NOTE:** The same thing can be done manually by setting the final positional argument to @@ -930,8 +934,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// App::new("myprog") + /// # use clap::{Command, Arg}; + /// Command::new("myprog") /// .dont_delimit_trailing_values(true) /// .get_matches(); /// ``` @@ -955,8 +959,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, ColorChoice}; - /// App::new("myprog") + /// # use clap::{Command, ColorChoice}; + /// Command::new("myprog") /// .color(ColorChoice::Never) /// .get_matches(); /// ``` @@ -966,14 +970,14 @@ impl<'help> App<'help> { #[must_use] pub fn color(self, color: ColorChoice) -> Self { #![allow(deprecated)] - let app = self + let cmd = self .unset_global_setting(AppSettings::ColorAuto) .unset_global_setting(AppSettings::ColorAlways) .unset_global_setting(AppSettings::ColorNever); match color { - ColorChoice::Auto => app.global_setting(AppSettings::ColorAuto), - ColorChoice::Always => app.global_setting(AppSettings::ColorAlways), - ColorChoice::Never => app.global_setting(AppSettings::ColorNever), + ColorChoice::Auto => cmd.global_setting(AppSettings::ColorAuto), + ColorChoice::Always => cmd.global_setting(AppSettings::ColorAlways), + ColorChoice::Never => cmd.global_setting(AppSettings::ColorNever), } } @@ -989,8 +993,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .term_width(80) /// # ; /// ``` @@ -1003,7 +1007,7 @@ impl<'help> App<'help> { /// Sets the maximum terminal width at which to wrap help messages. /// - /// This only applies when setting the current terminal width. See [`App::term_width`] for + /// This only applies when setting the current terminal width. See [`Command::term_width`] for /// more details. /// /// Using `0` will ignore terminal widths and use source formatting. @@ -1013,8 +1017,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .max_term_width(100) /// # ; /// ``` @@ -1030,8 +1034,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, ErrorKind}; - /// let res = App::new("myprog") + /// # use clap::{Command, ErrorKind}; + /// let res = Command::new("myprog") /// .disable_version_flag(true) /// .try_get_matches_from(vec![ /// "myprog", "-V" @@ -1060,17 +1064,17 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// App::new("myprog") + /// # use clap::{Command, Arg}; + /// Command::new("myprog") /// .version("v1.1") /// .propagate_version(true) - /// .subcommand(App::new("test")) + /// .subcommand(Command::new("test")) /// .get_matches(); /// // running `$ myprog test --version` will display /// // "myprog-test v1.1" /// ``` /// - /// [`subcommands`]: crate::App::subcommand() + /// [`subcommands`]: crate::Command::subcommand() #[inline] pub fn propagate_version(self, yes: bool) -> Self { if yes { @@ -1087,8 +1091,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// App::new("myprog") + /// # use clap::{Command, Arg}; + /// Command::new("myprog") /// .next_line_help(true) /// .get_matches(); /// ``` @@ -1108,8 +1112,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, ErrorKind}; - /// let res = App::new("myprog") + /// # use clap::{Command, ErrorKind}; + /// let res = Command::new("myprog") /// .disable_help_flag(true) /// .try_get_matches_from(vec![ /// "myprog", "-h" @@ -1131,12 +1135,12 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, ErrorKind}; - /// let res = App::new("myprog") + /// # use clap::{Command, ErrorKind}; + /// let res = Command::new("myprog") /// .disable_help_subcommand(true) /// // Normally, creating a subcommand causes a `help` subcommand to automatically /// // be generated as well - /// .subcommand(App::new("test")) + /// .subcommand(Command::new("test")) /// .try_get_matches_from(vec![ /// "myprog", "help" /// ]); @@ -1144,7 +1148,7 @@ impl<'help> App<'help> { /// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument); /// ``` /// - /// [`subcommand`]: crate::App::subcommand() + /// [`subcommand`]: crate::Command::subcommand() #[inline] pub fn disable_help_subcommand(self, yes: bool) -> Self { if yes { @@ -1161,8 +1165,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .disable_colored_help(true) /// .get_matches(); /// ``` @@ -1185,8 +1189,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// App::new("myprog") + /// # use clap::{Command, Arg}; + /// Command::new("myprog") /// .help_expected(true) /// .arg( /// Arg::new("foo").help("It does foo stuff") @@ -1198,8 +1202,8 @@ impl<'help> App<'help> { /// # Panics /// /// ```rust,no_run - /// # use clap::{App, Arg}; - /// App::new("myapp") + /// # use clap::{Command, Arg}; + /// Command::new("myapp") /// .help_expected(true) /// .arg( /// Arg::new("foo") @@ -1225,8 +1229,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// App::new("myprog") + /// # use clap::{Command, Arg}; + /// Command::new("myprog") /// .dont_collapse_args_in_usage(true) /// .get_matches(); /// ``` @@ -1267,7 +1271,7 @@ impl<'help> App<'help> { /// /// **NOTE:** This choice is propagated to all child subcommands. /// - /// [aliases]: crate::App::aliases() + /// [aliases]: crate::Command::aliases() #[inline] pub fn infer_long_args(self, yes: bool) -> Self { if yes { @@ -1288,7 +1292,7 @@ impl<'help> App<'help> { /// **CAUTION:** This setting can interfere with [positional/free arguments], take care when /// designing CLIs which allow inferred subcommands and have potential positional/free /// arguments whose values could start with the same characters as subcommands. If this is the - /// case, it's recommended to use settings such as [`App::args_conflicts_with_subcommands`] in + /// case, it's recommended to use settings such as [`Command::args_conflicts_with_subcommands`] in /// conjunction with this setting. /// /// **NOTE:** This choice is propagated to all child subcommands. @@ -1296,19 +1300,19 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// let m = App::new("prog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("prog") /// .infer_subcommands(true) - /// .subcommand(App::new("test")) + /// .subcommand(Command::new("test")) /// .get_matches_from(vec![ /// "prog", "te" /// ]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` /// - /// [subcommand]: crate::App::subcommand() + /// [subcommand]: crate::Command::subcommand() /// [positional/free arguments]: crate::Arg::index() - /// [aliases]: crate::App::aliases() + /// [aliases]: crate::Command::aliases() #[inline] pub fn infer_subcommands(self, yes: bool) -> Self { if yes { @@ -1325,17 +1329,17 @@ impl<'help> App<'help> { impl<'help> App<'help> { /// (Re)Sets the program's name. /// - /// See [`App::new`] for more details. + /// See [`Command::new`] for more details. /// /// # Examples /// /// ```ignore - /// # use clap::{App, load_yaml}; - /// let yaml = load_yaml!("app.yaml"); - /// let app = App::from(yaml) + /// # use clap::{Command, load_yaml}; + /// let yaml = load_yaml!("cmd.yaml"); + /// let cmd = Command::from(yaml) /// .name(crate_name!()); /// - /// // continued logic goes here, such as `app.get_matches()` etc. + /// // continued logic goes here, such as `cmd.get_matches()` etc. /// ``` #[must_use] pub fn name>(mut self, name: S) -> Self { @@ -1358,8 +1362,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("My Program") + /// # use clap::Command; + /// Command::new("My Program") /// .bin_name("my_binary") /// # ; /// ``` @@ -1378,8 +1382,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .author("Me, me@mymain.com") /// # ; /// ``` @@ -1392,9 +1396,9 @@ impl<'help> App<'help> { /// Sets the program's description for the short help (`-h`). /// - /// If [`App::long_about`] is not specified, this message will be displayed for `--help`. + /// If [`Command::long_about`] is not specified, this message will be displayed for `--help`. /// - /// **NOTE:** Only `App::about` (short format) is used in completion + /// **NOTE:** Only `Command::about` (short format) is used in completion /// script generation in order to be concise. /// /// See also [`crate_description!`](crate::crate_description!). @@ -1402,8 +1406,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .about("Does really amazing things for great people") /// # ; /// ``` @@ -1415,23 +1419,23 @@ impl<'help> App<'help> { /// Sets the program's description for the long help (`--help`). /// - /// If [`App::about`] is not specified, this message will be displayed for `-h`. + /// If [`Command::about`] is not specified, this message will be displayed for `-h`. /// - /// **NOTE:** Only [`App::about`] (short format) is used in completion + /// **NOTE:** Only [`Command::about`] (short format) is used in completion /// script generation in order to be concise. /// /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .long_about( /// "Does really amazing things to great people. Now let's talk a little /// more in depth about how this subcommand really works. It may take about /// a few lines of text, but that's ok!") /// # ; /// ``` - /// [`App::about`]: App::about() + /// [`App::about`]: Command::about() #[must_use] pub fn long_about>>(mut self, long_about: O) -> Self { self.long_about = long_about.into(); @@ -1443,13 +1447,13 @@ impl<'help> App<'help> { /// This is often used to describe how to use the arguments, caveats to be noted, or license /// and contact information. /// - /// If [`App::after_long_help`] is not specified, this message will be displayed for `--help`. + /// If [`Command::after_long_help`] is not specified, this message will be displayed for `--help`. /// /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .after_help("Does really amazing things for great people... but be careful with -R!") /// # ; /// ``` @@ -1465,13 +1469,13 @@ impl<'help> App<'help> { /// This is often used to describe how to use the arguments, caveats to be noted, or license /// and contact information. /// - /// If [`App::after_help`] is not specified, this message will be displayed for `-h`. + /// If [`Command::after_help`] is not specified, this message will be displayed for `-h`. /// /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .after_long_help("Does really amazing things to great people... but be careful with -R, \ /// like, for real, be careful with this!") /// # ; @@ -1486,13 +1490,13 @@ impl<'help> App<'help> { /// /// This is often used for header, copyright, or license information. /// - /// If [`App::before_long_help`] is not specified, this message will be displayed for `--help`. + /// If [`Command::before_long_help`] is not specified, this message will be displayed for `--help`. /// /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .before_help("Some info I'd like to appear before the help info") /// # ; /// ``` @@ -1506,13 +1510,13 @@ impl<'help> App<'help> { /// /// This is often used for header, copyright, or license information. /// - /// If [`App::before_help`] is not specified, this message will be displayed for `-h`. + /// If [`Command::before_help`] is not specified, this message will be displayed for `-h`. /// /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .before_long_help("Some verbose and long info I'd like to appear before the help info") /// # ; /// ``` @@ -1524,7 +1528,7 @@ impl<'help> App<'help> { /// Sets the version for the short version (`-V`) and help messages. /// - /// If [`App::long_version`] is not specified, this message will be displayed for `--version`. + /// If [`Command::long_version`] is not specified, this message will be displayed for `--version`. /// /// **Pro-tip:** Use `clap`s convenience macro [`crate_version!`] to /// automatically set your application's version to the same thing as your @@ -1533,8 +1537,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .version("v0.1.24") /// # ; /// ``` @@ -1547,7 +1551,7 @@ impl<'help> App<'help> { /// Sets the version for the long version (`--version`) and help messages. /// - /// If [`App::version`] is not specified, this message will be displayed for `-V`. + /// If [`Command::version`] is not specified, this message will be displayed for `-V`. /// /// **Pro-tip:** Use `clap`s convenience macro [`crate_version!`] to /// automatically set your application's version to the same thing as your @@ -1556,8 +1560,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .long_version( /// "v0.1.24 /// commit: abcdef89726d @@ -1582,8 +1586,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// App::new("myprog") + /// # use clap::{Command, Arg}; + /// Command::new("myprog") /// .override_usage("myapp [-clDas] ") /// # ; /// ``` @@ -1600,14 +1604,14 @@ impl<'help> App<'help> { /// /// **NOTE:** This **only** replaces the help message for the current /// command, meaning if you are using subcommands, those help messages will - /// still be auto-generated unless you specify a [`App::override_help`] for + /// still be auto-generated unless you specify a [`Command::override_help`] for /// them as well. /// /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// App::new("myapp") + /// # use clap::{Command, Arg}; + /// Command::new("myapp") /// .override_help("myapp v1.0\n\ /// Does awesome things\n\ /// (C) me@mail.com\n\n\ @@ -1645,8 +1649,8 @@ impl<'help> App<'help> { /// * `{author}` - Author information. /// * `{author-with-newline}` - Author followed by `\n`. /// * `{author-section}` - Author preceded and followed by `\n`. - /// * `{about}` - General description (from [`App::about`] or - /// [`App::long_about`]). + /// * `{about}` - General description (from [`Command::about`] or + /// [`Command::long_about`]). /// * `{about-with-newline}` - About followed by `\n`. /// * `{about-section}` - About preceded and followed by '\n'. /// * `{usage-heading}` - Automatically generated usage heading. @@ -1656,24 +1660,24 @@ impl<'help> App<'help> { /// * `{options}` - Help for options. /// * `{positionals}` - Help for positional arguments. /// * `{subcommands}` - Help for subcommands. - /// * `{after-help}` - Help from [`App::after_help`] or [`App::after_long_help`]. - /// * `{before-help}` - Help from [`App::before_help`] or [`App::before_long_help`]. + /// * `{after-help}` - Help from [`App::after_help`] or [`Command::after_long_help`]. + /// * `{before-help}` - Help from [`App::before_help`] or [`Command::before_long_help`]. /// /// # Examples /// /// ```no_run - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .version("1.0") /// .help_template("{bin} ({version}) - {usage}") /// # ; /// ``` - /// [`App::about`]: App::about() - /// [`App::long_about`]: App::long_about() - /// [`App::after_help`]: App::after_help() - /// [`App::after_long_help`]: App::after_long_help() - /// [`App::before_help`]: App::before_help() - /// [`App::before_long_help`]: App::before_long_help() + /// [`App::about`]: Command::about() + /// [`App::long_about`]: Command::long_about() + /// [`App::after_help`]: Command::after_help() + /// [`App::after_long_help`]: Command::after_long_help() + /// [`App::before_help`]: Command::before_help() + /// [`App::before_long_help`]: Command::before_long_help() #[must_use] pub fn help_template>(mut self, s: S) -> Self { self.template = Some(s.into()); @@ -1682,23 +1686,23 @@ impl<'help> App<'help> { /// Apply a setting for the current command or subcommand. /// - /// See [`App::global_setting`] to apply a setting to this command and all subcommands. + /// See [`Command::global_setting`] to apply a setting to this command and all subcommands. /// /// See [`AppSettings`] for a full list of possibilities and examples. /// /// # Examples /// /// ```no_run - /// # use clap::{App, AppSettings}; - /// App::new("myprog") + /// # use clap::{Command, AppSettings}; + /// Command::new("myprog") /// .setting(AppSettings::SubcommandRequired) /// .setting(AppSettings::AllowLeadingHyphen) /// # ; /// ``` /// or /// ```no_run - /// # use clap::{App, AppSettings}; - /// App::new("myprog") + /// # use clap::{Command, AppSettings}; + /// Command::new("myprog") /// .setting(AppSettings::SubcommandRequired | AppSettings::AllowLeadingHyphen) /// # ; /// ``` @@ -1719,16 +1723,16 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, AppSettings}; - /// App::new("myprog") + /// # use clap::{Command, AppSettings}; + /// Command::new("myprog") /// .unset_setting(AppSettings::SubcommandRequired) /// .setting(AppSettings::AllowLeadingHyphen) /// # ; /// ``` /// or /// ```no_run - /// # use clap::{App, AppSettings}; - /// App::new("myprog") + /// # use clap::{Command, AppSettings}; + /// Command::new("myprog") /// .unset_setting(AppSettings::SubcommandRequired | AppSettings::AllowLeadingHyphen) /// # ; /// ``` @@ -1744,15 +1748,15 @@ impl<'help> App<'help> { /// Apply a setting for the current command and all subcommands. /// - /// See [`App::setting`] to apply a setting only to this command. + /// See [`Command::setting`] to apply a setting only to this command. /// /// See [`AppSettings`] for a full list of possibilities and examples. /// /// # Examples /// /// ```no_run - /// # use clap::{App, AppSettings}; - /// App::new("myprog") + /// # use clap::{Command, AppSettings}; + /// Command::new("myprog") /// .global_setting(AppSettings::AllowNegativeNumbers) /// # ; /// ``` @@ -1771,12 +1775,12 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, AppSettings}; - /// App::new("myprog") + /// # use clap::{Command, AppSettings}; + /// Command::new("myprog") /// .unset_global_setting(AppSettings::AllowNegativeNumbers) /// # ; /// ``` - /// [global]: App::global_setting() + /// [global]: Command::global_setting() #[inline] #[must_use] pub fn unset_global_setting(mut self, setting: AppSettings) -> Self { @@ -1785,7 +1789,7 @@ impl<'help> App<'help> { self } - /// Deprecated, replaced with [`App::next_help_heading`] + /// Deprecated, replaced with [`Command::next_help_heading`] #[inline] #[must_use] #[deprecated(since = "3.1.0", note = "Replaced with `App::next_help_heading`")] @@ -1803,9 +1807,9 @@ impl<'help> App<'help> { /// This is useful if the default `OPTIONS` or `ARGS` headings are /// not specific enough for one's use case. /// - /// For subcommands, see [`App::subcommand_help_heading`] + /// For subcommands, see [`Command::subcommand_help_heading`] /// - /// [`App::arg`]: App::arg() + /// [`App::arg`]: Command::arg() /// [`Arg::help_heading`]: crate::Arg::help_heading() #[inline] #[must_use] @@ -1843,27 +1847,27 @@ impl<'help> App<'help> { /// /// We'll start with the "subcommand short" example. In this example, let's /// assume we have a program with a subcommand `module` which can be invoked - /// via `app module`. Now let's also assume `module` also has a subcommand - /// called `install` which can be invoked `app module install`. If for some - /// reason users needed to be able to reach `app module install` via the - /// short-hand `app install`, we'd have several options. + /// via `cmd module`. Now let's also assume `module` also has a subcommand + /// called `install` which can be invoked `cmd module install`. If for some + /// reason users needed to be able to reach `cmd module install` via the + /// short-hand `cmd install`, we'd have several options. /// /// We *could* create another sibling subcommand to `module` called /// `install`, but then we would need to manage another subcommand and manually - /// dispatch to `app module install` handling code. This is error prone and + /// dispatch to `cmd module install` handling code. This is error prone and /// tedious. /// - /// We could instead use [`App::replace`] so that, when the user types `app + /// We could instead use [`Command::replace`] so that, when the user types `cmd /// install`, `clap` will replace `install` with `module install` which will /// end up getting parsed as if the user typed the entire incantation. /// /// ```rust - /// # use clap::App; - /// let m = App::new("app") - /// .subcommand(App::new("module") - /// .subcommand(App::new("install"))) + /// # use clap::Command; + /// let m = Command::new("cmd") + /// .subcommand(Command::new("module") + /// .subcommand(Command::new("install"))) /// .replace("install", &["module", "install"]) - /// .get_matches_from(vec!["app", "install"]); + /// .get_matches_from(vec!["cmd", "install"]); /// /// assert!(m.subcommand_matches("module").is_some()); /// assert!(m.subcommand_matches("module").unwrap().subcommand_matches("install").is_some()); @@ -1874,7 +1878,7 @@ impl<'help> App<'help> { /// Let's assume we have an application with two flags `--save-context` and /// `--save-runtime`. But often users end up needing to do *both* at the /// same time. We can add a third flag `--save-all` which semantically means - /// the same thing as `app --save-context --save-runtime`. To implement that, + /// the same thing as `cmd --save-context --save-runtime`. To implement that, /// we have several options. /// /// We could create this third argument and manually check if that argument @@ -1884,21 +1888,21 @@ impl<'help> App<'help> { /// and we forgot to update that code to *also* check `--save-all` it'd mean /// an error! /// - /// Luckily we can use [`App::replace`] so that when the user types + /// Luckily we can use [`Command::replace`] so that when the user types /// `--save-all`, `clap` will replace that argument with `--save-context /// --save-runtime`, and parsing will continue like normal. Now all our code /// that was originally checking for things like `--save-context` doesn't /// need to change! /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("app") + /// # use clap::{Command, Arg}; + /// let m = Command::new("cmd") /// .arg(Arg::new("save-context") /// .long("save-context")) /// .arg(Arg::new("save-runtime") /// .long("save-runtime")) /// .replace("--save-all", &["--save-context", "--save-runtime"]) - /// .get_matches_from(vec!["app", "--save-all"]); + /// .get_matches_from(vec!["cmd", "--save-all"]); /// /// assert!(m.is_present("save-context")); /// assert!(m.is_present("save-runtime")); @@ -1911,8 +1915,8 @@ impl<'help> App<'help> { /// above to enforce this: /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("app") + /// # use clap::{Command, Arg}; + /// let m = Command::new("cmd") /// .arg(Arg::new("save-context") /// .long("save-context")) /// .arg(Arg::new("save-runtime") @@ -1922,14 +1926,14 @@ impl<'help> App<'help> { /// .takes_value(true) /// .possible_values(["txt", "json"])) /// .replace("--save-all", &["--save-context", "--save-runtime", "--format=json"]) - /// .get_matches_from(vec!["app", "--save-all"]); + /// .get_matches_from(vec!["cmd", "--save-all"]); /// /// assert!(m.is_present("save-context")); /// assert!(m.is_present("save-runtime")); /// assert_eq!(m.value_of("format"), Some("json")); /// ``` /// - /// [`App::replace`]: App::replace() + /// [`App::replace`]: Command::replace() #[inline] #[cfg(feature = "unstable-replace")] #[must_use] @@ -1945,12 +1949,12 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App}; - /// App::new("myprog") + /// # use clap::{Command}; + /// Command::new("myprog") /// .arg_required_else_help(true); /// ``` /// - /// [`subcommands`]: crate::App::subcommand() + /// [`subcommands`]: crate::Command::subcommand() /// [`Arg::default_value`]: crate::Arg::default_value() #[inline] pub fn arg_required_else_help(self, yes: bool) -> Self { @@ -1964,7 +1968,7 @@ impl<'help> App<'help> { /// Specifies that leading hyphens are allowed in all argument *values* (e.g. `-10`). /// /// Otherwise they will be parsed as another flag or option. See also - /// [`App::allow_negative_numbers`]. + /// [`Command::allow_negative_numbers`]. /// /// **NOTE:** Use this setting with caution as it silences certain circumstances which would /// otherwise be an error (such as accidentally forgetting to specify a value for leading @@ -1973,9 +1977,9 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{Arg, App}; + /// # use clap::{Arg, Command}; /// // Imagine you needed to represent negative numbers as well, such as -10 - /// let m = App::new("nums") + /// let m = Command::new("nums") /// .allow_hyphen_values(true) /// .arg(Arg::new("neg")) /// .get_matches_from(vec![ @@ -1997,14 +2001,14 @@ impl<'help> App<'help> { /// Allows negative numbers to pass as values. /// - /// This is similar to [`App::allow_hyphen_values`] except that it only allows numbers, + /// This is similar to [`Command::allow_hyphen_values`] except that it only allows numbers, /// all other undefined leading hyphens will fail to parse. /// /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let res = App::new("myprog") + /// # use clap::{Command, Arg}; + /// let res = Command::new("myprog") /// .allow_negative_numbers(true) /// .arg(Arg::new("num")) /// .try_get_matches_from(vec![ @@ -2034,8 +2038,8 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, arg}; - /// let m = App::new("myprog") + /// # use clap::{Command, arg}; + /// let m = Command::new("myprog") /// .trailing_var_arg(true) /// .arg(arg!( ... "commands to run")) /// .get_matches_from(vec!["myprog", "arg1", "-r", "val1"]); @@ -2086,9 +2090,9 @@ impl<'help> App<'help> { /// Style number one from above: /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// // Assume there is an external subcommand named "subcmd" - /// let m = App::new("myprog") + /// let m = Command::new("myprog") /// .allow_missing_positional(true) /// .arg(Arg::new("arg1")) /// .arg(Arg::new("arg2") @@ -2104,9 +2108,9 @@ impl<'help> App<'help> { /// Now the same example, but using a default value for the first optional positional argument /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// // Assume there is an external subcommand named "subcmd" - /// let m = App::new("myprog") + /// let m = Command::new("myprog") /// .allow_missing_positional(true) /// .arg(Arg::new("arg1") /// .default_value("something")) @@ -2123,9 +2127,9 @@ impl<'help> App<'help> { /// Style number two from above: /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// // Assume there is an external subcommand named "subcmd" - /// let m = App::new("myprog") + /// let m = Command::new("myprog") /// .allow_missing_positional(true) /// .arg(Arg::new("foo")) /// .arg(Arg::new("bar")) @@ -2142,9 +2146,9 @@ impl<'help> App<'help> { /// Now nofice if we don't specify `foo` or `baz` but use the `--` operator. /// /// ```rust - /// # use clap::{App, Arg}; + /// # use clap::{Command, Arg}; /// // Assume there is an external subcommand named "subcmd" - /// let m = App::new("myprog") + /// let m = Command::new("myprog") /// .allow_missing_positional(true) /// .arg(Arg::new("foo")) /// .arg(Arg::new("bar")) @@ -2178,10 +2182,10 @@ impl<'help> App<'help> { /// # Examples /// /// ``` - /// # use clap::{App, Arg}; - /// let matches = App::new("pacman") + /// # use clap::{Command, Arg}; + /// let matches = Command::new("pacman") /// .subcommand( - /// App::new("sync").short_flag('S').arg( + /// Command::new("sync").short_flag('S').arg( /// Arg::new("search") /// .short('s') /// .long("search") @@ -2214,10 +2218,10 @@ impl<'help> App<'help> { /// will *not* be stripped (i.e. `sync-file` is allowed). /// /// ``` - /// # use clap::{App, Arg}; - /// let matches = App::new("pacman") + /// # use clap::{Command, Arg}; + /// let matches = Command::new("pacman") /// .subcommand( - /// App::new("sync").long_flag("sync").arg( + /// Command::new("sync").long_flag("sync").arg( /// Arg::new("search") /// .short('s') /// .long("search") @@ -2246,7 +2250,7 @@ impl<'help> App<'help> { /// /// **NOTE:** Aliases defined with this method are *hidden* from the help /// message. If you're looking for aliases that will be displayed in the help - /// message, see [`App::visible_alias`]. + /// message, see [`Command::visible_alias`]. /// /// **NOTE:** When using aliases and checking for the existence of a /// particular subcommand within an [`ArgMatches`] struct, one only needs to @@ -2255,14 +2259,14 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, }; - /// let m = App::new("myprog") - /// .subcommand(App::new("test") + /// # use clap::{Command, Arg, }; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test") /// .alias("do-stuff")) /// .get_matches_from(vec!["myprog", "do-stuff"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` - /// [`App::visible_alias`]: App::visible_alias() + /// [`App::visible_alias`]: Command::visible_alias() #[must_use] pub fn alias>(mut self, name: S) -> Self { self.aliases.push((name.into(), false)); @@ -2278,9 +2282,9 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg, }; - /// let m = App::new("myprog") - /// .subcommand(App::new("test").short_flag('t') + /// # use clap::{Command, Arg, }; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test").short_flag('t') /// .short_flag_alias('d')) /// .get_matches_from(vec!["myprog", "-d"]); /// assert_eq!(m.subcommand_name(), Some("test")); @@ -2301,9 +2305,9 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg, }; - /// let m = App::new("myprog") - /// .subcommand(App::new("test").long_flag("test") + /// # use clap::{Command, Arg, }; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test").long_flag("test") /// .long_flag_alias("testing")) /// .get_matches_from(vec!["myprog", "--testing"]); /// assert_eq!(m.subcommand_name(), Some("test")); @@ -2322,7 +2326,7 @@ impl<'help> App<'help> { /// /// **NOTE:** Aliases defined with this method are *hidden* from the help /// message. If looking for aliases that will be displayed in the help - /// message, see [`App::visible_aliases`]. + /// message, see [`Command::visible_aliases`]. /// /// **NOTE:** When using aliases and checking for the existence of a /// particular subcommand within an [`ArgMatches`] struct, one only needs to @@ -2331,9 +2335,9 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myprog") - /// .subcommand(App::new("test") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test") /// .aliases(&["do-stuff", "do-tests", "tests"])) /// .arg(Arg::new("input") /// .help("the file to add") @@ -2342,7 +2346,7 @@ impl<'help> App<'help> { /// .get_matches_from(vec!["myprog", "do-tests"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` - /// [`App::visible_aliases`]: App::visible_aliases() + /// [`App::visible_aliases`]: Command::visible_aliases() #[must_use] pub fn aliases(mut self, names: &[&'help str]) -> Self { self.aliases.extend(names.iter().map(|n| (*n, false))); @@ -2358,9 +2362,9 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, }; - /// let m = App::new("myprog") - /// .subcommand(App::new("test").short_flag('t') + /// # use clap::{Command, Arg, }; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test").short_flag('t') /// .short_flag_aliases(&['a', 'b', 'c'])) /// .arg(Arg::new("input") /// .help("the file to add") @@ -2387,9 +2391,9 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, }; - /// let m = App::new("myprog") - /// .subcommand(App::new("test").long_flag("test") + /// # use clap::{Command, Arg, }; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test").long_flag("test") /// .long_flag_aliases(&["testing", "testall", "test_all"])) /// .arg(Arg::new("input") /// .help("the file to add") @@ -2416,7 +2420,7 @@ impl<'help> App<'help> { /// **NOTE:** The alias defined with this method is *visible* from the help /// message and displayed as if it were just another regular subcommand. If /// looking for an alias that will not be displayed in the help message, see - /// [`App::alias`]. + /// [`Command::alias`]. /// /// **NOTE:** When using aliases and checking for the existence of a /// particular subcommand within an [`ArgMatches`] struct, one only needs to @@ -2425,14 +2429,14 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// let m = App::new("myprog") - /// .subcommand(App::new("test") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test") /// .visible_alias("do-stuff")) /// .get_matches_from(vec!["myprog", "do-stuff"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` - /// [`App::alias`]: App::alias() + /// [`App::alias`]: Command::alias() #[must_use] pub fn visible_alias>(mut self, name: S) -> Self { self.aliases.push((name.into(), true)); @@ -2445,19 +2449,19 @@ impl<'help> App<'help> { /// and easier than creating multiple hidden subcommands as one only needs to check for the /// existence of this command, and not all variants. /// - /// See also [`App::short_flag_alias`]. + /// See also [`Command::short_flag_alias`]. /// /// # Examples /// /// ```no_run - /// # use clap::{App, Arg, }; - /// let m = App::new("myprog") - /// .subcommand(App::new("test").short_flag('t') + /// # use clap::{Command, Arg, }; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test").short_flag('t') /// .visible_short_flag_alias('d')) /// .get_matches_from(vec!["myprog", "-d"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` - /// [`App::short_flag_alias`]: App::short_flag_alias() + /// [`App::short_flag_alias`]: Command::short_flag_alias() #[must_use] pub fn visible_short_flag_alias(mut self, name: char) -> Self { assert!(name != '-', "short alias name cannot be `-`"); @@ -2471,19 +2475,19 @@ impl<'help> App<'help> { /// and easier than creating multiple hidden subcommands as one only needs to check for the /// existence of this command, and not all variants. /// - /// See also [`App::long_flag_alias`]. + /// See also [`Command::long_flag_alias`]. /// /// # Examples /// /// ```no_run - /// # use clap::{App, Arg, }; - /// let m = App::new("myprog") - /// .subcommand(App::new("test").long_flag("test") + /// # use clap::{Command, Arg, }; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test").long_flag("test") /// .visible_long_flag_alias("testing")) /// .get_matches_from(vec!["myprog", "--testing"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` - /// [`App::long_flag_alias`]: App::long_flag_alias() + /// [`App::long_flag_alias`]: Command::long_flag_alias() #[must_use] pub fn visible_long_flag_alias(mut self, name: &'help str) -> Self { self.long_flag_aliases.push((name, true)); @@ -2500,7 +2504,7 @@ impl<'help> App<'help> { /// **NOTE:** The alias defined with this method is *visible* from the help /// message and displayed as if it were just another regular subcommand. If /// looking for an alias that will not be displayed in the help message, see - /// [`App::alias`]. + /// [`Command::alias`]. /// /// **NOTE:** When using aliases, and checking for the existence of a /// particular subcommand within an [`ArgMatches`] struct, one only needs to @@ -2509,14 +2513,14 @@ impl<'help> App<'help> { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg, }; - /// let m = App::new("myprog") - /// .subcommand(App::new("test") + /// # use clap::{Command, Arg, }; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test") /// .visible_aliases(&["do-stuff", "tests"])) /// .get_matches_from(vec!["myprog", "do-stuff"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` - /// [`App::alias`]: App::alias() + /// [`App::alias`]: Command::alias() #[must_use] pub fn visible_aliases(mut self, names: &[&'help str]) -> Self { self.aliases.extend(names.iter().map(|n| (*n, true))); @@ -2525,19 +2529,19 @@ impl<'help> App<'help> { /// Add aliases, which function as *visible* short flag subcommands. /// - /// See [`App::short_flag_aliases`]. + /// See [`Command::short_flag_aliases`]. /// /// # Examples /// /// ```no_run - /// # use clap::{App, Arg, }; - /// let m = App::new("myprog") - /// .subcommand(App::new("test").short_flag('b') + /// # use clap::{Command, Arg, }; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test").short_flag('b') /// .visible_short_flag_aliases(&['t'])) /// .get_matches_from(vec!["myprog", "-t"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` - /// [`App::short_flag_aliases`]: App::short_flag_aliases() + /// [`App::short_flag_aliases`]: Command::short_flag_aliases() #[must_use] pub fn visible_short_flag_aliases(mut self, names: &[char]) -> Self { for s in names { @@ -2549,19 +2553,19 @@ impl<'help> App<'help> { /// Add aliases, which function as *visible* long flag subcommands. /// - /// See [`App::long_flag_aliases`]. + /// See [`Command::long_flag_aliases`]. /// /// # Examples /// /// ```no_run - /// # use clap::{App, Arg, }; - /// let m = App::new("myprog") - /// .subcommand(App::new("test").long_flag("test") + /// # use clap::{Command, Arg, }; + /// let m = Command::new("myprog") + /// .subcommand(Command::new("test").long_flag("test") /// .visible_long_flag_aliases(&["testing", "testall", "test_all"])) /// .get_matches_from(vec!["myprog", "--testing"]); /// assert_eq!(m.subcommand_name(), Some("test")); /// ``` - /// [`App::long_flag_aliases`]: App::long_flag_aliases() + /// [`App::long_flag_aliases`]: Command::long_flag_aliases() #[must_use] pub fn visible_long_flag_aliases(mut self, names: &[&'help str]) -> Self { for s in names { @@ -2583,15 +2587,15 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, }; - /// let m = App::new("cust-ord") - /// .subcommand(App::new("alpha") // typically subcommands are grouped + /// # use clap::{Command, }; + /// let m = Command::new("cust-ord") + /// .subcommand(Command::new("alpha") // typically subcommands are grouped /// // alphabetically by name. Subcommands /// // without a display_order have a value of /// // 999 and are displayed alphabetically with /// // all other 999 subcommands /// .about("Some help and text")) - /// .subcommand(App::new("beta") + /// .subcommand(Command::new("beta") /// .display_order(1) // In order to force this subcommand to appear *first* /// // all we have to do is give it a value lower than 999. /// // Any other subcommands with a value of 1 will be displayed @@ -2630,15 +2634,15 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// App::new("myprog") + /// # use clap::{Command, Arg}; + /// Command::new("myprog") /// .subcommand( - /// App::new("test").hide(true) + /// Command::new("test").hide(true) /// ) /// # ; /// ``` /// - /// [`subcommand`]: crate::App::subcommand() + /// [`subcommand`]: crate::Command::subcommand() #[inline] pub fn hide(self, yes: bool) -> Self { if yes { @@ -2653,10 +2657,10 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, ErrorKind}; - /// let err = App::new("myprog") + /// # use clap::{Command, ErrorKind}; + /// let err = Command::new("myprog") /// .subcommand_required(true) - /// .subcommand(App::new("test")) + /// .subcommand(Command::new("test")) /// .try_get_matches_from(vec![ /// "myprog", /// ]); @@ -2665,7 +2669,7 @@ impl<'help> App<'help> { /// # ; /// ``` /// - /// [`subcommand`]: crate::App::subcommand() + /// [`subcommand`]: crate::Command::subcommand() pub fn subcommand_required(self, yes: bool) -> Self { if yes { self.setting(AppSettings::SubcommandRequired) @@ -2684,9 +2688,9 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::App; + /// # use clap::Command; /// // Assume there is an external subcommand named "subcmd" - /// let m = App::new("myprog") + /// let m = Command::new("myprog") /// .allow_external_subcommands(true) /// .get_matches_from(vec![ /// "myprog", "subcmd", "--option", "value", "-fff", "--flag" @@ -2704,7 +2708,7 @@ impl<'help> App<'help> { /// } /// ``` /// - /// [`subcommand`]: crate::App::subcommand() + /// [`subcommand`]: crate::Command::subcommand() /// [`ArgMatches`]: crate::ArgMatches /// [`ErrorKind::UnknownArgument`]: crate::ErrorKind::UnknownArgument pub fn allow_external_subcommands(self, yes: bool) -> Self { @@ -2721,7 +2725,7 @@ impl<'help> App<'help> { /// [`ArgMatches::values_of_os`] or [`ArgMatches::values_of_lossy`] for those particular /// arguments which may contain invalid UTF-8 values /// - /// **NOTE:** Setting this requires [`App::allow_external_subcommands`] + /// **NOTE:** Setting this requires [`Command::allow_external_subcommands`] /// /// # Platform Specific /// @@ -2731,9 +2735,9 @@ impl<'help> App<'help> { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] - /// # use clap::App; + /// # use clap::Command; /// // Assume there is an external subcommand named "subcmd" - /// let m = App::new("myprog") + /// let m = Command::new("myprog") /// .allow_invalid_utf8_for_external_subcommands(true) /// .allow_external_subcommands(true) /// .get_matches_from(vec![ @@ -2754,7 +2758,7 @@ impl<'help> App<'help> { /// /// [`ArgMatches::values_of_os`]: crate::ArgMatches::values_of_os() /// [`ArgMatches::values_of_lossy`]: crate::ArgMatches::values_of_lossy() - /// [`subcommands`]: crate::App::subcommand() + /// [`subcommands`]: crate::Command::subcommand() pub fn allow_invalid_utf8_for_external_subcommands(self, yes: bool) -> Self { if yes { self.setting(AppSettings::AllowInvalidUtf8ForExternalSubcommands) @@ -2779,12 +2783,12 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::App; - /// App::new("myprog") + /// # use clap::Command; + /// Command::new("myprog") /// .args_conflicts_with_subcommands(true); /// ``` /// - /// [`subcommands`]: crate::App::subcommand() + /// [`subcommands`]: crate::Command::subcommand() pub fn args_conflicts_with_subcommands(self, yes: bool) -> Self { if yes { self.setting(AppSettings::ArgsNegateSubcommands) @@ -2799,7 +2803,7 @@ impl<'help> App<'help> { /// subcommand will be parsed as another value. /// /// ```text - /// app --foo val1 val2 subcommand + /// cmd --foo val1 val2 subcommand /// --------- ---------- /// values another value /// ``` @@ -2808,7 +2812,7 @@ impl<'help> App<'help> { /// greedily consuming arguments. /// /// ```text - /// app --foo val1 val2 subcommand + /// cmd --foo val1 val2 subcommand /// --------- ---------- /// values subcommand /// ``` @@ -2819,17 +2823,17 @@ impl<'help> App<'help> { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let app = App::new("app").subcommand(App::new("sub")).arg( + /// # use clap::{Command, Arg}; + /// let cmd = Command::new("cmd").subcommand(Command::new("sub")).arg( /// Arg::new("arg") /// .long("arg") /// .multiple_values(true) /// .takes_value(true), /// ); /// - /// let matches = app + /// let matches = cmd /// .clone() - /// .try_get_matches_from(&["app", "--arg", "1", "2", "3", "sub"]) + /// .try_get_matches_from(&["cmd", "--arg", "1", "2", "3", "sub"]) /// .unwrap(); /// assert_eq!( /// matches.values_of("arg").unwrap().collect::>(), @@ -2837,9 +2841,9 @@ impl<'help> App<'help> { /// ); /// assert!(matches.subcommand_matches("sub").is_none()); /// - /// let matches = app + /// let matches = cmd /// .subcommand_precedence_over_arg(true) - /// .try_get_matches_from(&["app", "--arg", "1", "2", "3", "sub"]) + /// .try_get_matches_from(&["cmd", "--arg", "1", "2", "3", "sub"]) /// .unwrap(); /// assert_eq!( /// matches.values_of("arg").unwrap().collect::>(), @@ -2869,11 +2873,11 @@ impl<'help> App<'help> { /// This first example shows that it is an error to not use a required argument /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let err = App::new("myprog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let err = Command::new("myprog") /// .subcommand_negates_reqs(true) /// .arg(Arg::new("opt").required(true)) - /// .subcommand(App::new("test")) + /// .subcommand(Command::new("test")) /// .try_get_matches_from(vec![ /// "myprog" /// ]); @@ -2886,11 +2890,11 @@ impl<'help> App<'help> { /// valid subcommand is used. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let noerr = App::new("myprog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let noerr = Command::new("myprog") /// .subcommand_negates_reqs(true) /// .arg(Arg::new("opt").required(true)) - /// .subcommand(App::new("test")) + /// .subcommand(Command::new("test")) /// .try_get_matches_from(vec![ /// "myprog", "test" /// ]); @@ -2899,7 +2903,7 @@ impl<'help> App<'help> { /// ``` /// /// [`Arg::required(true)`]: crate::Arg::required() - /// [`subcommands`]: crate::App::subcommand() + /// [`subcommands`]: crate::Command::subcommand() pub fn subcommand_negates_reqs(self, yes: bool) -> Self { if yes { self.setting(AppSettings::SubcommandsNegateReqs) @@ -2934,25 +2938,25 @@ impl<'help> App<'help> { /// but there is other related functionality that would be convenient to provide /// and it is convenient for the code to implement it to be in the same executable. /// - /// The name of the app is essentially unused + /// The name of the cmd is essentially unused /// and may be the same as the name of a subcommand. /// - /// The names of the immediate subcommands of the App + /// The names of the immediate subcommands of the Command /// are matched against the basename of the first argument, /// which is conventionally the path of the executable. /// /// This does not allow the subcommand to be passed as the first non-path argument. /// /// ```rust - /// # use clap::{App, ErrorKind}; - /// let mut app = App::new("hostname") + /// # use clap::{Command, ErrorKind}; + /// let mut cmd = Command::new("hostname") /// .multicall(true) - /// .subcommand(App::new("hostname")) - /// .subcommand(App::new("dnsdomainname")); - /// let m = app.try_get_matches_from_mut(&["/usr/bin/hostname", "dnsdomainname"]); + /// .subcommand(Command::new("hostname")) + /// .subcommand(Command::new("dnsdomainname")); + /// let m = cmd.try_get_matches_from_mut(&["/usr/bin/hostname", "dnsdomainname"]); /// assert!(m.is_err()); /// assert_eq!(m.unwrap_err().kind(), ErrorKind::UnknownArgument); - /// let m = app.get_matches_from(&["/usr/bin/dnsdomainname"]); + /// let m = cmd.get_matches_from(&["/usr/bin/dnsdomainname"]); /// assert_eq!(m.subcommand_name(), Some("dnsdomainname")); /// ``` /// @@ -2967,18 +2971,18 @@ impl<'help> App<'help> { /// or there may already be a command of that name installed. /// /// To make an applet usable as both a multicall link and a subcommand - /// the subcommands must be defined both in the top-level App + /// the subcommands must be defined both in the top-level Command /// and as subcommands of the "main" applet. /// /// ```rust - /// # use clap::App; - /// fn applet_commands() -> [App<'static>; 2] { - /// [App::new("true"), App::new("false")] + /// # use clap::Command; + /// fn applet_commands() -> [Command<'static>; 2] { + /// [Command::new("true"), Command::new("false")] /// } - /// let mut app = App::new("busybox") + /// let mut cmd = Command::new("busybox") /// .multicall(true) /// .subcommand( - /// App::new("busybox") + /// Command::new("busybox") /// .subcommand_value_name("APPLET") /// .subcommand_help_heading("APPLETS") /// .subcommands(applet_commands()), @@ -2986,21 +2990,21 @@ impl<'help> App<'help> { /// .subcommands(applet_commands()); /// // When called from the executable's canonical name /// // its applets can be matched as subcommands. - /// let m = app.try_get_matches_from_mut(&["/usr/bin/busybox", "true"]).unwrap(); + /// let m = cmd.try_get_matches_from_mut(&["/usr/bin/busybox", "true"]).unwrap(); /// assert_eq!(m.subcommand_name(), Some("busybox")); /// assert_eq!(m.subcommand().unwrap().1.subcommand_name(), Some("true")); /// // When called from a link named after an applet that applet is matched. - /// let m = app.get_matches_from(&["/usr/bin/true"]); + /// let m = cmd.get_matches_from(&["/usr/bin/true"]); /// assert_eq!(m.subcommand_name(), Some("true")); /// ``` /// /// **NOTE:** Applets are slightly semantically different from subcommands, - /// so it's recommended to use [`App::subcommand_help_heading`] and - /// [`App::subcommand_value_name`] to change the descriptive text as above. + /// so it's recommended to use [`Command::subcommand_help_heading`] and + /// [`Command::subcommand_value_name`] to change the descriptive text as above. /// - /// [`no_binary_name`]: crate::App::no_binary_name - /// [`App::subcommand_value_name`]: crate::App::subcommand_value_name - /// [`App::subcommand_help_heading`]: crate::App::subcommand_help_heading + /// [`no_binary_name`]: crate::Command::no_binary_name + /// [`App::subcommand_value_name`]: crate::Command::subcommand_value_name + /// [`App::subcommand_help_heading`]: crate::Command::subcommand_help_heading #[inline] #[cfg(feature = "unstable-multicall")] pub fn multicall(self, yes: bool) -> Self { @@ -3015,14 +3019,14 @@ impl<'help> App<'help> { /// /// By default, this is "SUBCOMMAND". /// - /// See also [`App::subcommand_help_heading`] + /// See also [`Command::subcommand_help_heading`] /// /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// App::new("myprog") - /// .subcommand(App::new("sub1")) + /// # use clap::{Command, Arg}; + /// Command::new("myprog") + /// .subcommand(Command::new("sub1")) /// .print_help() /// # ; /// ``` @@ -3047,9 +3051,9 @@ impl<'help> App<'help> { /// but usage of `subcommand_value_name` /// /// ```no_run - /// # use clap::{App, Arg}; - /// App::new("myprog") - /// .subcommand(App::new("sub1")) + /// # use clap::{Command, Arg}; + /// Command::new("myprog") + /// .subcommand(Command::new("sub1")) /// .subcommand_value_name("THING") /// .print_help() /// # ; @@ -3084,14 +3088,14 @@ impl<'help> App<'help> { /// /// By default, this is "SUBCOMMANDS". /// - /// See also [`App::subcommand_value_name`] + /// See also [`Command::subcommand_value_name`] /// /// # Examples /// /// ```no_run - /// # use clap::{App, Arg}; - /// App::new("myprog") - /// .subcommand(App::new("sub1")) + /// # use clap::{Command, Arg}; + /// Command::new("myprog") + /// .subcommand(Command::new("sub1")) /// .print_help() /// # ; /// ``` @@ -3116,9 +3120,9 @@ impl<'help> App<'help> { /// but usage of `subcommand_help_heading` /// /// ```no_run - /// # use clap::{App, Arg}; - /// App::new("myprog") - /// .subcommand(App::new("sub1")) + /// # use clap::{Command, Arg}; + /// Command::new("myprog") + /// .subcommand(Command::new("sub1")) /// .subcommand_help_heading("THINGS") /// .print_help() /// # ; @@ -3168,25 +3172,25 @@ impl<'help> App<'help> { self.bin_name = Some(name.into()); } - /// Get the name of the app. + /// Get the name of the cmd. #[inline] pub fn get_name(&self) -> &str { &self.name } - /// Get the version of the app. + /// Get the version of the cmd. #[inline] pub fn get_version(&self) -> Option<&'help str> { self.version } - /// Get the long version of the app. + /// Get the long version of the cmd. #[inline] pub fn get_long_version(&self) -> Option<&'help str> { self.long_version } - /// Get the authors of the app. + /// Get the authors of the cmd. #[inline] pub fn get_author(&self) -> Option<&'help str> { self.author @@ -3204,32 +3208,32 @@ impl<'help> App<'help> { self.long_flag } - /// Get the help message specified via [`App::about`]. + /// Get the help message specified via [`Command::about`]. /// - /// [`App::about`]: App::about() + /// [`App::about`]: Command::about() #[inline] pub fn get_about(&self) -> Option<&'help str> { self.about } - /// Get the help message specified via [`App::long_about`]. + /// Get the help message specified via [`Command::long_about`]. /// - /// [`App::long_about`]: App::long_about() + /// [`App::long_about`]: Command::long_about() #[inline] pub fn get_long_about(&self) -> Option<&'help str> { self.long_about } - /// Deprecated, replaced with [`App::get_next_help_heading`] + /// Deprecated, replaced with [`Command::get_next_help_heading`] #[inline] #[deprecated(since = "3.1.0", note = "Replaced with `App::get_next_help_heading`")] pub fn get_help_heading(&self) -> Option<&'help str> { self.get_next_help_heading() } - /// Get the custom section heading specified via [`App::help_heading`]. + /// Get the custom section heading specified via [`Command::help_heading`]. /// - /// [`App::help_heading`]: App::help_heading() + /// [`App::help_heading`]: Command::help_heading() #[inline] pub fn get_next_help_heading(&self) -> Option<&'help str> { self.current_help_heading @@ -3277,12 +3281,12 @@ impl<'help> App<'help> { self.long_flag_aliases.iter().map(|a| a.0) } - /// Check if the given [`AppSettings`] variant is currently set on the `App`. + /// Check if the given [`AppSettings`] variant is currently set on the `Command`. /// /// This checks both [local] and [global settings]. /// - /// [local]: App::setting() - /// [global settings]: App::global_setting() + /// [local]: Command::setting() + /// [global settings]: Command::global_setting() #[inline] pub fn is_set(&self, s: AppSettings) -> bool { self.settings.is_set(s) || self.g_settings.is_set(s) @@ -3322,7 +3326,7 @@ impl<'help> App<'help> { self.subcommands.iter_mut() } - /// Returns `true` if this `App` has subcommands. + /// Returns `true` if this `Command` has subcommands. #[inline] pub fn has_subcommands(&self) -> bool { !self.subcommands.is_empty() @@ -3429,7 +3433,7 @@ impl<'help> App<'help> { /// ### Panics /// /// If the given arg contains a conflict with an argument that is unknown to - /// this `App`. + /// this `Command`. pub fn get_arg_conflicts_with(&self, arg: &Arg) -> Vec<&Arg<'help>> // FIXME: This could probably have been an iterator { if arg.is_global_set() { @@ -3440,7 +3444,7 @@ impl<'help> App<'help> { .map(|id| { self.args.args().find(|arg| arg.id == *id).expect( "App::get_arg_conflicts_with: \ - The passed arg conflicts with an arg unknown to the app", + The passed arg conflicts with an arg unknown to the cmd", ) }) .collect() @@ -3471,7 +3475,7 @@ impl<'help> App<'help> { .find(|arg| arg.id == *id) .expect( "App::get_arg_conflicts_with: \ - The passed arg conflicts with an arg unknown to the app", + The passed arg conflicts with an arg unknown to the cmd", ) }) .collect() @@ -3501,134 +3505,134 @@ impl<'help> App<'help> { vec } - /// Report whether [`App::no_binary_name`] is set + /// Report whether [`Command::no_binary_name`] is set #[allow(unused)] pub(crate) fn is_no_binary_name_set(&self) -> bool { self.is_set(AppSettings::NoBinaryName) } - /// Report whether [`App::ignore_errors`] is set + /// Report whether [`Command::ignore_errors`] is set pub(crate) fn is_ignore_errors_set(&self) -> bool { self.is_set(AppSettings::IgnoreErrors) } - /// Report whether [`App::dont_delimit_trailing_values`] is set + /// Report whether [`Command::dont_delimit_trailing_values`] is set pub fn is_dont_delimit_trailing_values_set(&self) -> bool { self.is_set(AppSettings::DontDelimitTrailingValues) } - /// Report whether [`App::disable_version_flag`] is set + /// Report whether [`Command::disable_version_flag`] is set pub fn is_disable_version_flag_set(&self) -> bool { self.is_set(AppSettings::DisableVersionFlag) } - /// Report whether [`App::propagate_version`] is set + /// Report whether [`Command::propagate_version`] is set pub fn is_propagate_version_set(&self) -> bool { self.is_set(AppSettings::PropagateVersion) } - /// Report whether [`App::next_line_help`] is set + /// Report whether [`Command::next_line_help`] is set pub fn is_next_line_help_set(&self) -> bool { self.is_set(AppSettings::NextLineHelp) } - /// Report whether [`App::disable_help_flag`] is set + /// Report whether [`Command::disable_help_flag`] is set pub fn is_disable_help_flag_set(&self) -> bool { self.is_set(AppSettings::DisableHelpFlag) } - /// Report whether [`App::disable_help_subcommand`] is set + /// Report whether [`Command::disable_help_subcommand`] is set pub fn is_disable_help_subcommand_set(&self) -> bool { self.is_set(AppSettings::DisableHelpSubcommand) } - /// Report whether [`App::disable_colored_help`] is set + /// Report whether [`Command::disable_colored_help`] is set pub fn is_disable_colored_help_set(&self) -> bool { self.is_set(AppSettings::DisableColoredHelp) } - /// Report whether [`App::help_expected`] is set + /// Report whether [`Command::help_expected`] is set #[cfg(debug_assertions)] pub(crate) fn is_help_expected_set(&self) -> bool { self.is_set(AppSettings::HelpExpected) } - /// Report whether [`App::dont_collapse_args_in_usage`] is set + /// Report whether [`Command::dont_collapse_args_in_usage`] is set pub fn is_dont_collapse_args_in_usage_set(&self) -> bool { self.is_set(AppSettings::DontCollapseArgsInUsage) } - /// Report whether [`App::infer_long_args`] is set + /// Report whether [`Command::infer_long_args`] is set pub(crate) fn is_infer_long_args_set(&self) -> bool { self.is_set(AppSettings::InferLongArgs) } - /// Report whether [`App::infer_subcommands`] is set + /// Report whether [`Command::infer_subcommands`] is set pub(crate) fn is_infer_subcommands_set(&self) -> bool { self.is_set(AppSettings::InferSubcommands) } - /// Report whether [`App::arg_required_else_help`] is set + /// Report whether [`Command::arg_required_else_help`] is set pub fn is_arg_required_else_help_set(&self) -> bool { self.is_set(AppSettings::ArgRequiredElseHelp) } - /// Report whether [`App::allow_hyphen_values`] is set + /// Report whether [`Command::allow_hyphen_values`] is set pub(crate) fn is_allow_hyphen_values_set(&self) -> bool { self.is_set(AppSettings::AllowHyphenValues) } - /// Report whether [`App::allow_negative_numbers`] is set + /// Report whether [`Command::allow_negative_numbers`] is set pub fn is_allow_negative_numbers_set(&self) -> bool { self.is_set(AppSettings::AllowNegativeNumbers) } - /// Report whether [`App::trailing_var_arg`] is set + /// Report whether [`Command::trailing_var_arg`] is set pub fn is_trailing_var_arg_set(&self) -> bool { self.is_set(AppSettings::TrailingVarArg) } - /// Report whether [`App::allow_missing_positional`] is set + /// Report whether [`Command::allow_missing_positional`] is set pub fn is_allow_missing_positional_set(&self) -> bool { self.is_set(AppSettings::AllowMissingPositional) } - /// Report whether [`App::hide`] is set + /// Report whether [`Command::hide`] is set pub fn is_hide_set(&self) -> bool { self.is_set(AppSettings::Hidden) } - /// Report whether [`App::subcommand_required`] is set + /// Report whether [`Command::subcommand_required`] is set pub fn is_subcommand_required_set(&self) -> bool { self.is_set(AppSettings::SubcommandRequired) } - /// Report whether [`App::allow_external_subcommands`] is set + /// Report whether [`Command::allow_external_subcommands`] is set pub fn is_allow_external_subcommands_set(&self) -> bool { self.is_set(AppSettings::AllowExternalSubcommands) } - /// Report whether [`App::allow_invalid_utf8_for_external_subcommands`] is set + /// Report whether [`Command::allow_invalid_utf8_for_external_subcommands`] is set pub fn is_allow_invalid_utf8_for_external_subcommands_set(&self) -> bool { self.is_set(AppSettings::AllowInvalidUtf8ForExternalSubcommands) } - /// Report whether [`App::args_conflicts_with_subcommands`] is set + /// Report whether [`Command::args_conflicts_with_subcommands`] is set pub fn is_args_conflicts_with_subcommands_set(&self) -> bool { self.is_set(AppSettings::ArgsNegateSubcommands) } - /// Report whether [`App::subcommand_precedence_over_arg`] is set + /// Report whether [`Command::subcommand_precedence_over_arg`] is set pub fn is_subcommand_precedence_over_arg_set(&self) -> bool { self.is_set(AppSettings::SubcommandPrecedenceOverArg) } - /// Report whether [`App::subcommand_negates_reqs`] is set + /// Report whether [`Command::subcommand_negates_reqs`] is set pub fn is_subcommand_negates_reqs_set(&self) -> bool { self.is_set(AppSettings::SubcommandsNegateReqs) } - /// Report whether [`App::multicall`] is set + /// Report whether [`Command::multicall`] is set #[cfg(feature = "unstable-multicall")] pub fn is_multicall_set(&self) -> bool { self.is_set(AppSettings::Multicall) @@ -3649,7 +3653,7 @@ impl<'help> App<'help> { let yaml_file_hash = y.as_hash().expect("YAML file must be a hash"); // We WANT this to panic on error...so expect() is good. let (mut a, yaml, err) = if let Some(name) = y["name"].as_str() { - (App::new(name), yaml_file_hash, "app".into()) + (App::new(name), yaml_file_hash, "cmd".into()) } else { let (name_yaml, value_yaml) = yaml_file_hash .iter() @@ -3729,7 +3733,7 @@ impl<'help> App<'help> { a } - /// Deprecated, replaced with [`App::override_usage`] + /// Deprecated, replaced with [`Command::override_usage`] #[deprecated(since = "3.0.0", note = "Replaced with `App::override_usage`")] #[doc(hidden)] #[must_use] @@ -3737,7 +3741,7 @@ impl<'help> App<'help> { self.override_usage(usage) } - /// Deprecated, replaced with [`App::override_help`] + /// Deprecated, replaced with [`Command::override_help`] #[deprecated(since = "3.0.0", note = "Replaced with `App::override_help`")] #[doc(hidden)] #[must_use] @@ -3745,7 +3749,7 @@ impl<'help> App<'help> { self.override_help(help) } - /// Deprecated, replaced with [`App::mut_arg`] + /// Deprecated, replaced with [`Command::mut_arg`] #[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")] #[doc(hidden)] #[must_use] @@ -3753,7 +3757,7 @@ impl<'help> App<'help> { self.mut_arg("help", |a| a.short(c)) } - /// Deprecated, replaced with [`App::mut_arg`] + /// Deprecated, replaced with [`Command::mut_arg`] #[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")] #[doc(hidden)] #[must_use] @@ -3761,7 +3765,7 @@ impl<'help> App<'help> { self.mut_arg("version", |a| a.short(c)) } - /// Deprecated, replaced with [`App::mut_arg`] + /// Deprecated, replaced with [`Command::mut_arg`] #[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")] #[doc(hidden)] #[must_use] @@ -3769,7 +3773,7 @@ impl<'help> App<'help> { self.mut_arg("help", |a| a.help(s.into())) } - /// Deprecated, replaced with [`App::mut_arg`] + /// Deprecated, replaced with [`Command::mut_arg`] #[deprecated(since = "3.0.0", note = "Replaced with `App::mut_arg`")] #[doc(hidden)] #[must_use] @@ -3777,7 +3781,7 @@ impl<'help> App<'help> { self.mut_arg("version", |a| a.help(s.into())) } - /// Deprecated, replaced with [`App::help_template`] + /// Deprecated, replaced with [`Command::help_template`] #[deprecated(since = "3.0.0", note = "Replaced with `App::help_template`")] #[doc(hidden)] #[must_use] @@ -3785,7 +3789,7 @@ impl<'help> App<'help> { self.help_template(s) } - /// Deprecated, replaced with [`App::setting(a| b)`] + /// Deprecated, replaced with [`Command::setting(a| b)`] #[deprecated(since = "3.0.0", note = "Replaced with `App::setting(a | b)`")] #[doc(hidden)] #[must_use] @@ -3796,7 +3800,7 @@ impl<'help> App<'help> { self } - /// Deprecated, replaced with [`App::unset_setting(a| b)`] + /// Deprecated, replaced with [`Command::unset_setting(a| b)`] #[deprecated(since = "3.0.0", note = "Replaced with `App::unset_setting(a | b)`")] #[doc(hidden)] #[must_use] @@ -3807,7 +3811,7 @@ impl<'help> App<'help> { self } - /// Deprecated, replaced with [`App::global_setting(a| b)`] + /// Deprecated, replaced with [`Command::global_setting(a| b)`] #[deprecated(since = "3.0.0", note = "Replaced with `App::global_setting(a | b)`")] #[doc(hidden)] #[must_use] @@ -3819,7 +3823,7 @@ impl<'help> App<'help> { self } - /// Deprecated, replaced with [`App::term_width`] + /// Deprecated, replaced with [`Command::term_width`] #[deprecated(since = "3.0.0", note = "Replaced with `App::term_width`")] #[doc(hidden)] #[must_use] @@ -3852,28 +3856,28 @@ impl<'help> App<'help> { self } - /// Deprecated, replaced with [`App::render_version`] + /// Deprecated, replaced with [`Command::render_version`] #[deprecated(since = "3.0.0", note = "Replaced with `App::render_version`")] #[doc(hidden)] pub fn write_version(&self, w: &mut W) -> ClapResult<()> { write!(w, "{}", self.render_version()).map_err(From::from) } - /// Deprecated, replaced with [`App::render_long_version`] + /// Deprecated, replaced with [`Command::render_long_version`] #[deprecated(since = "3.0.0", note = "Replaced with `App::render_long_version`")] #[doc(hidden)] pub fn write_long_version(&self, w: &mut W) -> ClapResult<()> { write!(w, "{}", self.render_long_version()).map_err(From::from) } - /// Deprecated, replaced with [`App::try_get_matches`] + /// Deprecated, replaced with [`Command::try_get_matches`] #[deprecated(since = "3.0.0", note = "Replaced with `App::try_get_matches`")] #[doc(hidden)] pub fn get_matches_safe(self) -> ClapResult { self.try_get_matches() } - /// Deprecated, replaced with [`App::try_get_matches_from`] + /// Deprecated, replaced with [`Command::try_get_matches_from`] #[deprecated(since = "3.0.0", note = "Replaced with `App::try_get_matches_from`")] #[doc(hidden)] pub fn get_matches_from_safe(self, itr: I) -> ClapResult @@ -3884,7 +3888,7 @@ impl<'help> App<'help> { self.try_get_matches_from(itr) } - /// Deprecated, replaced with [`App::try_get_matches_from_mut`] + /// Deprecated, replaced with [`Command::try_get_matches_from_mut`] #[deprecated( since = "3.0.0", note = "Replaced with `App::try_get_matches_from_mut`" @@ -4105,7 +4109,7 @@ impl<'help> App<'help> { .collect(); assert!(args_missing_help.is_empty(), - "AppSettings::HelpExpected is enabled for the App {}, but at least one of its arguments does not have either `help` or `long_help` set. List of such arguments: {}", + "AppSettings::HelpExpected is enabled for the Command {}, but at least one of its arguments does not have either `help` or `long_help` set. List of such arguments: {}", self.name, args_missing_help.join(", ") ); @@ -4239,7 +4243,7 @@ impl<'help> App<'help> { panic!( "`help`s `-h` conflicts with `{}`. -To change `help`s short, call `app.arg(Arg::new(\"help\")...)`.", +To change `help`s short, call `cmd.arg(Arg::new(\"help\")...)`.", other_arg.name ); } diff --git a/src/build/debug_asserts.rs b/src/build/debug_asserts.rs index 39ded8282b8..0e86473e955 100644 --- a/src/build/debug_asserts.rs +++ b/src/build/debug_asserts.rs @@ -3,55 +3,55 @@ use std::cmp::Ordering; use crate::build::arg::ArgProvider; use crate::mkeymap::KeyType; use crate::util::Id; -use crate::{App, AppSettings, Arg, ValueHint}; +use crate::{AppSettings, Arg, Command, ValueHint}; -pub(crate) fn assert_app(app: &App) { - debug!("App::_debug_asserts"); +pub(crate) fn assert_app(cmd: &Command) { + debug!("Command::_debug_asserts"); let mut short_flags = vec![]; let mut long_flags = vec![]; // Invalid version flag settings - if app.get_version().is_none() && app.get_long_version().is_none() { + if cmd.get_version().is_none() && cmd.get_long_version().is_none() { // PropagateVersion is meaningless if there is no version assert!( - !app.is_propagate_version_set(), - "App {}: No version information via App::version or App::long_version to propagate", - app.get_name(), + !cmd.is_propagate_version_set(), + "Command {}: No version information via Command::version or Command::long_version to propagate", + cmd.get_name(), ); - // Used `App::mut_arg("version", ..) but did not provide any version information to display - let has_mutated_version = app + // Used `Command::mut_arg("version", ..) but did not provide any version information to display + let has_mutated_version = cmd .get_arguments() .any(|x| x.id == Id::version_hash() && x.provider == ArgProvider::GeneratedMutated); if has_mutated_version { - assert!(app.is_set(AppSettings::NoAutoVersion), - "App {}: Used App::mut_arg(\"version\", ..) without providing App::version, App::long_version or using AppSettings::NoAutoVersion" - ,app.get_name() + assert!(cmd.is_set(AppSettings::NoAutoVersion), + "Command {}: Used Command::mut_arg(\"version\", ..) without providing Command::version, Command::long_version or using AppSettings::NoAutoVersion" + ,cmd.get_name() ); } } - for sc in app.get_subcommands() { + for sc in cmd.get_subcommands() { if let Some(s) = sc.get_short_flag().as_ref() { - short_flags.push(Flag::App(format!("-{}", s), sc.get_name())); + short_flags.push(Flag::Command(format!("-{}", s), sc.get_name())); } for short_alias in sc.get_all_short_flag_aliases() { - short_flags.push(Flag::App(format!("-{}", short_alias), sc.get_name())); + short_flags.push(Flag::Command(format!("-{}", short_alias), sc.get_name())); } if let Some(l) = sc.get_long_flag().as_ref() { - long_flags.push(Flag::App(format!("--{}", l), sc.get_name())); + long_flags.push(Flag::Command(format!("--{}", l), sc.get_name())); } for long_alias in sc.get_all_long_flag_aliases() { - long_flags.push(Flag::App(format!("--{}", long_alias), sc.get_name())); + long_flags.push(Flag::Command(format!("--{}", long_alias), sc.get_name())); } } - for arg in app.get_arguments() { + for arg in cmd.get_arguments() { assert_arg(arg); if let Some(s) = arg.short.as_ref() { @@ -72,19 +72,19 @@ pub(crate) fn assert_app(app: &App) { // Name conflicts assert!( - app.two_args_of(|x| x.id == arg.id).is_none(), - "App {}: Argument names must be unique, but '{}' is in use by more than one argument or group", - app.get_name(), + cmd.two_args_of(|x| x.id == arg.id).is_none(), + "Command {}: Argument names must be unique, but '{}' is in use by more than one argument or group", + cmd.get_name(), arg.name, ); // Long conflicts if let Some(l) = arg.long { - if let Some((first, second)) = app.two_args_of(|x| x.long == Some(l)) { + if let Some((first, second)) = cmd.two_args_of(|x| x.long == Some(l)) { panic!( - "App {}: Long option names must be unique for each argument, \ + "Command {}: Long option names must be unique for each argument, \ but '--{}' is in use by both '{}' and '{}'", - app.get_name(), + cmd.get_name(), l, first.name, second.name @@ -94,11 +94,11 @@ pub(crate) fn assert_app(app: &App) { // Short conflicts if let Some(s) = arg.short { - if let Some((first, second)) = app.two_args_of(|x| x.short == Some(s)) { + if let Some((first, second)) = cmd.two_args_of(|x| x.short == Some(s)) { panic!( - "App {}: Short option names must be unique for each argument, \ + "Command {}: Short option names must be unique for each argument, \ but '-{}' is in use by both '{}' and '{}'", - app.get_name(), + cmd.get_name(), s, first.name, second.name @@ -109,14 +109,14 @@ pub(crate) fn assert_app(app: &App) { // Index conflicts if let Some(idx) = arg.index { if let Some((first, second)) = - app.two_args_of(|x| x.is_positional() && x.index == Some(idx)) + cmd.two_args_of(|x| x.is_positional() && x.index == Some(idx)) { panic!( - "App {}: Argument '{}' has the same index as '{}' \ + "Command {}: Argument '{}' has the same index as '{}' \ and they are both positional arguments\n\n\t \ Use Arg::multiple_values(true) to allow one \ positional argument to take multiple values", - app.get_name(), + cmd.get_name(), first.name, second.name ) @@ -126,9 +126,9 @@ pub(crate) fn assert_app(app: &App) { // requires, r_if, r_unless for req in &arg.requires { assert!( - app.id_exists(&req.1), - "App {}: Argument or group '{:?}' specified in 'requires*' for '{}' does not exist", - app.get_name(), + cmd.id_exists(&req.1), + "Command {}: Argument or group '{:?}' specified in 'requires*' for '{}' does not exist", + cmd.get_name(), req.1, arg.name, ); @@ -136,9 +136,9 @@ pub(crate) fn assert_app(app: &App) { for req in &arg.r_ifs { assert!( - app.id_exists(&req.0), - "App {}: Argument or group '{:?}' specified in 'required_if_eq*' for '{}' does not exist", - app.get_name(), + cmd.id_exists(&req.0), + "Command {}: Argument or group '{:?}' specified in 'required_if_eq*' for '{}' does not exist", + cmd.get_name(), req.0, arg.name ); @@ -146,9 +146,9 @@ pub(crate) fn assert_app(app: &App) { for req in &arg.r_ifs_all { assert!( - app.id_exists(&req.0), - "App {}: Argument or group '{:?}' specified in 'required_if_eq_all' for '{}' does not exist", - app.get_name(), + cmd.id_exists(&req.0), + "Command {}: Argument or group '{:?}' specified in 'required_if_eq_all' for '{}' does not exist", + cmd.get_name(), req.0, arg.name ); @@ -156,9 +156,9 @@ pub(crate) fn assert_app(app: &App) { for req in &arg.r_unless { assert!( - app.id_exists(req), - "App {}: Argument or group '{:?}' specified in 'required_unless*' for '{}' does not exist", - app.get_name(), + cmd.id_exists(req), + "Command {}: Argument or group '{:?}' specified in 'required_unless*' for '{}' does not exist", + cmd.get_name(), req, arg.name, ); @@ -167,9 +167,9 @@ pub(crate) fn assert_app(app: &App) { // blacklist for req in &arg.blacklist { assert!( - app.id_exists(req), - "App {}: Argument or group '{:?}' specified in 'conflicts_with*' for '{}' does not exist", - app.get_name(), + cmd.id_exists(req), + "Command {}: Argument or group '{:?}' specified in 'conflicts_with*' for '{}' does not exist", + cmd.get_name(), req, arg.name, ); @@ -178,64 +178,64 @@ pub(crate) fn assert_app(app: &App) { if arg.is_last_set() { assert!( arg.long.is_none(), - "App {}: Flags or Options cannot have last(true) set. '{}' has both a long and last(true) set.", - app.get_name(), + "Command {}: Flags or Options cannot have last(true) set. '{}' has both a long and last(true) set.", + cmd.get_name(), arg.name ); assert!( arg.short.is_none(), - "App {}: Flags or Options cannot have last(true) set. '{}' has both a short and last(true) set.", - app.get_name(), + "Command {}: Flags or Options cannot have last(true) set. '{}' has both a short and last(true) set.", + cmd.get_name(), arg.name ); } assert!( !(arg.is_required_set() && arg.is_global_set()), - "App {}: Global arguments cannot be required.\n\n\t'{}' is marked as both global and required", - app.get_name(), + "Command {}: Global arguments cannot be required.\n\n\t'{}' is marked as both global and required", + cmd.get_name(), arg.name ); // validators assert!( arg.validator.is_none() || arg.validator_os.is_none(), - "App {}: Argument '{}' has both `validator` and `validator_os` set which is not allowed", - app.get_name(), + "Command {}: Argument '{}' has both `validator` and `validator_os` set which is not allowed", + cmd.get_name(), arg.name ); if arg.value_hint == ValueHint::CommandWithArguments { assert!( arg.is_positional(), - "App {}: Argument '{}' has hint CommandWithArguments and must be positional.", - app.get_name(), + "Command {}: Argument '{}' has hint CommandWithArguments and must be positional.", + cmd.get_name(), arg.name ); assert!( - app.is_trailing_var_arg_set(), - "App {}: Positional argument '{}' has hint CommandWithArguments, so App must have TrailingVarArg set.", - app.get_name(), + cmd.is_trailing_var_arg_set(), + "Command {}: Positional argument '{}' has hint CommandWithArguments, so Command must have TrailingVarArg set.", + cmd.get_name(), arg.name ); } } - for group in app.get_groups() { + for group in cmd.get_groups() { // Name conflicts assert!( - app.get_groups().filter(|x| x.id == group.id).count() < 2, - "App {}: Argument group name must be unique\n\n\t'{}' is already in use", - app.get_name(), + cmd.get_groups().filter(|x| x.id == group.id).count() < 2, + "Command {}: Argument group name must be unique\n\n\t'{}' is already in use", + cmd.get_name(), group.name, ); // Groups should not have naming conflicts with Args assert!( - !app.get_arguments().any(|x| x.id == group.id), - "App {}: Argument group name '{}' must not conflict with argument name", - app.get_name(), + !cmd.get_arguments().any(|x| x.id == group.id), + "Command {}: Argument group name '{}' must not conflict with argument name", + cmd.get_name(), group.name, ); @@ -243,11 +243,11 @@ pub(crate) fn assert_app(app: &App) { if group.required && !group.args.is_empty() { assert!( group.args.iter().any(|arg| { - app.get_arguments() + cmd.get_arguments() .any(|x| x.id == *arg && x.default_vals.is_empty()) }), - "App {}: Argument group '{}' is required but all of it's arguments have a default value.", - app.get_name(), + "Command {}: Argument group '{}' is required but all of it's arguments have a default value.", + cmd.get_name(), group.name ) } @@ -255,9 +255,9 @@ pub(crate) fn assert_app(app: &App) { for arg in &group.args { // Args listed inside groups should exist assert!( - app.get_arguments().any(|x| x.id == *arg), - "App {}: Argument group '{}' contains non-existent argument '{:?}'", - app.get_name(), + cmd.get_arguments().any(|x| x.id == *arg), + "Command {}: Argument group '{}' contains non-existent argument '{:?}'", + cmd.get_name(), group.name, arg ); @@ -272,30 +272,30 @@ pub(crate) fn assert_app(app: &App) { detect_duplicate_flags(&long_flags, "long"); detect_duplicate_flags(&short_flags, "short"); - _verify_positionals(app); + _verify_positionals(cmd); - if let Some(help_template) = app.get_help_template() { + if let Some(help_template) = cmd.get_help_template() { assert!( !help_template.contains("{flags}"), - "App {}: {}", - app.get_name(), + "Command {}: {}", + cmd.get_name(), "`{flags}` template variable was removed in clap3, they are now included in `{options}`", ); assert!( !help_template.contains("{unified}"), - "App {}: {}", - app.get_name(), + "Command {}: {}", + cmd.get_name(), "`{unified}` template variable was removed in clap3, use `{options}` instead" ); } - app._panic_on_missing_help(app.is_help_expected_set()); - assert_app_flags(app); + cmd._panic_on_missing_help(cmd.is_help_expected_set()); + assert_app_flags(cmd); } #[derive(Eq)] enum Flag<'a> { - App(String, &'a str), + Command(String, &'a str), Arg(String, &'a str), } @@ -310,10 +310,10 @@ impl PartialOrd for Flag<'_> { use Flag::*; match (self, other) { - (App(s1, _), App(s2, _)) + (Command(s1, _), Command(s2, _)) | (Arg(s1, _), Arg(s2, _)) - | (App(s1, _), Arg(s2, _)) - | (Arg(s1, _), App(s2, _)) => { + | (Command(s1, _), Arg(s2, _)) + | (Arg(s1, _), Command(s2, _)) => { if s1 == s2 { Some(Ordering::Equal) } else { @@ -335,7 +335,7 @@ fn detect_duplicate_flags(flags: &[Flag], short_or_long: &str) { for (one, two) in find_duplicates(flags) { match (one, two) { - (App(flag, one), App(_, another)) if one != another => panic!( + (Command(flag, one), Command(_, another)) if one != another => panic!( "the '{}' {} flag is specified for both '{}' and '{}' subcommands", flag, short_or_long, one, another ), @@ -345,7 +345,7 @@ fn detect_duplicate_flags(flags: &[Flag], short_or_long: &str) { short_or_long, flag, one, another ), - (Arg(flag, arg), App(_, sub)) | (App(flag, sub), Arg(_, arg)) => panic!( + (Arg(flag, arg), Command(_, sub)) | (Command(flag, sub), Arg(_, arg)) => panic!( "the '{}' {} flag for the '{}' argument conflicts with the short flag \ for '{}' subcommand", flag, short_or_long, arg, sub @@ -370,14 +370,14 @@ fn find_duplicates(slice: &[T]) -> impl Iterator }) } -fn assert_app_flags(app: &App) { +fn assert_app_flags(cmd: &Command) { macro_rules! checker { ($a:ident requires $($b:ident)|+) => { - if app.$a() { + if cmd.$a() { let mut s = String::new(); $( - if !app.$b() { + if !cmd.$b() { s.push_str(&format!(" AppSettings::{} is required when AppSettings::{} is set.\n", std::stringify!($b), std::stringify!($a))); } )+ @@ -388,17 +388,17 @@ fn assert_app_flags(app: &App) { } }; ($a:ident conflicts $($b:ident)|+) => { - if app.$a() { + if cmd.$a() { let mut s = String::new(); $( - if app.$b() { + if cmd.$b() { s.push_str(&format!(" AppSettings::{} conflicts with AppSettings::{}.\n", std::stringify!($b), std::stringify!($a))); } )+ if !s.is_empty() { - panic!("{}\n{}", app.get_name(), s) + panic!("{}\n{}", cmd.get_name(), s) } } }; @@ -410,8 +410,8 @@ fn assert_app_flags(app: &App) { } #[cfg(debug_assertions)] -fn _verify_positionals(app: &App) -> bool { - debug!("App::_verify_positionals"); +fn _verify_positionals(cmd: &Command) -> bool { + debug!("Command::_verify_positionals"); // Because you must wait until all arguments have been supplied, this is the first chance // to make assertions on positional argument indexes // @@ -419,7 +419,7 @@ fn _verify_positionals(app: &App) -> bool { // positional arguments to verify there are no gaps (i.e. supplying an index of 1 and 3 // but no 2) - let highest_idx = app + let highest_idx = cmd .get_keymap() .keys() .filter_map(|x| { @@ -432,7 +432,7 @@ fn _verify_positionals(app: &App) -> bool { .max() .unwrap_or(0); - let num_p = app.get_keymap().keys().filter(|x| x.is_position()).count(); + let num_p = cmd.get_keymap().keys().filter(|x| x.is_position()).count(); assert!( highest_idx == num_p, @@ -444,7 +444,7 @@ fn _verify_positionals(app: &App) -> bool { // Next we verify that only the highest index has takes multiple arguments (if any) let only_highest = |a: &Arg| a.is_multiple() && (a.index.unwrap_or(0) != highest_idx); - if app.get_positionals().any(only_highest) { + if cmd.get_positionals().any(only_highest) { // First we make sure if there is a positional that allows multiple values // the one before it (second to last) has one of these: // * a value terminator @@ -453,8 +453,8 @@ fn _verify_positionals(app: &App) -> bool { // We can't pass the closure (it.next()) to the macro directly because each call to // find() (iterator, not macro) gets called repeatedly. - let last = &app.get_keymap()[&KeyType::Position(highest_idx)]; - let second_to_last = &app.get_keymap()[&KeyType::Position(highest_idx - 1)]; + let last = &cmd.get_keymap()[&KeyType::Position(highest_idx)]; + let second_to_last = &cmd.get_keymap()[&KeyType::Position(highest_idx - 1)]; // Either the final positional is required // Or the second to last has a terminator or .last(true) set @@ -477,7 +477,7 @@ fn _verify_positionals(app: &App) -> bool { ); // Next we check how many have both Multiple and not a specific number of values set - let count = app + let count = cmd .get_positionals() .filter(|p| { p.is_multiple_occurrences_set() @@ -498,12 +498,12 @@ fn _verify_positionals(app: &App) -> bool { let mut found = false; - if app.is_allow_missing_positional_set() { + if cmd.is_allow_missing_positional_set() { // Check that if a required positional argument is found, all positions with a lower // index are also required. let mut foundx2 = false; - for p in app.get_positionals() { + for p in cmd.get_positionals() { if foundx2 && !p.is_required_set() { assert!( p.is_required_set(), @@ -533,7 +533,7 @@ fn _verify_positionals(app: &App) -> bool { } else { // Check that if a required positional argument is found, all positions with a lower // index are also required - for p in (1..=num_p).rev().filter_map(|n| app.get_keymap().get(&n)) { + for p in (1..=num_p).rev().filter_map(|n| cmd.get_keymap().get(&n)) { if found { assert!( p.is_required_set(), @@ -555,14 +555,14 @@ fn _verify_positionals(app: &App) -> bool { } } assert!( - app.get_positionals().filter(|p| p.is_last_set()).count() < 2, + cmd.get_positionals().filter(|p| p.is_last_set()).count() < 2, "Only one positional argument may have last(true) set. Found two." ); - if app + if cmd .get_positionals() .any(|p| p.is_last_set() && p.is_required_set()) - && app.has_subcommands() - && !app.is_subcommand_negates_reqs_set() + && cmd.has_subcommands() + && !cmd.is_subcommand_negates_reqs_set() { panic!( "Having a required positional argument with .last(true) set *and* child \ diff --git a/src/build/mod.rs b/src/build/mod.rs index 06ccb7a8930..ae8c46b6363 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -1,13 +1,12 @@ #[macro_use] mod macros; -pub mod app; -pub mod arg; - mod app_settings; +mod arg; mod arg_group; mod arg_predicate; mod arg_settings; +mod command; mod possible_value; mod usage_parser; mod value_hint; @@ -19,18 +18,21 @@ mod regex; mod debug_asserts; #[cfg(test)] -mod app_tests; -#[cfg(test)] -mod arg_tests; +mod tests; -pub use app::App; pub use app_settings::{AppFlags, AppSettings}; pub use arg::Arg; pub use arg_group::ArgGroup; -pub(crate) use arg_predicate::ArgPredicate; pub use arg_settings::{ArgFlags, ArgSettings}; +pub use command::Command; pub use possible_value::PossibleValue; pub use value_hint::ValueHint; +#[allow(deprecated)] +pub use command::App; + #[cfg(feature = "regex")] pub use self::regex::RegexRef; + +pub(crate) use arg::display_arg_val; +pub(crate) use arg_predicate::ArgPredicate; diff --git a/src/build/tests.rs b/src/build/tests.rs new file mode 100644 index 00000000000..0cea009571c --- /dev/null +++ b/src/build/tests.rs @@ -0,0 +1,56 @@ +use crate::Arg; +use crate::Command; + +#[test] +fn propagate_version() { + let mut cmd = Command::new("test") + .propagate_version(true) + .version("1.1") + .subcommand(Command::new("sub1")); + cmd._propagate(); + assert_eq!( + cmd.get_subcommands().next().unwrap().get_version(), + Some("1.1") + ); +} + +#[test] +fn global_setting() { + let mut cmd = Command::new("test") + .disable_version_flag(true) + .subcommand(Command::new("subcmd")); + cmd._propagate(); + assert!(cmd + .get_subcommands() + .find(|s| s.get_name() == "subcmd") + .unwrap() + .is_disable_version_flag_set()); +} + +// This test will *fail to compile* if Command is not Send + Sync +#[test] +fn app_send_sync() { + fn foo(_: T) {} + foo(Command::new("test")) +} + +#[test] +fn issue_2090() { + let mut cmd = Command::new("cmd") + .disable_version_flag(true) + .subcommand(Command::new("sub")); + cmd._build(); + + assert!(cmd + .get_subcommands() + .next() + .unwrap() + .is_disable_version_flag_set()); +} + +// This test will *fail to compile* if Arg is not Send + Sync +#[test] +fn arg_send_sync() { + fn foo(_: T) {} + foo(Arg::new("test")) +} diff --git a/src/build/usage_parser.rs b/src/build/usage_parser.rs index 2aa624de2aa..ccfad66bfab 100644 --- a/src/build/usage_parser.rs +++ b/src/build/usage_parser.rs @@ -1246,8 +1246,8 @@ mod test { #[test] fn value_names_building_num_vals_from_usage() { - use crate::App; - let m = App::new("test") + use crate::Command; + let m = Command::new("test") .arg(Arg::from_usage("--pos ")) .try_get_matches_from(vec!["myprog", "--pos", "val1", "val2", "val3"]); @@ -1262,9 +1262,9 @@ mod test { #[test] fn issue_665() { - use crate::{error::ErrorKind, App}; + use crate::{error::ErrorKind, Command}; // Verify fix for "arg_from_usage(): required values not being enforced when followed by another option" - let res = App::new("tester") + let res = Command::new("tester") .arg(Arg::from_usage("-v, --reroll-count=[N] 'Mark the patch series as PATCH vN'")) .arg( Arg::from_usage("--subject-prefix [Subject-Prefix] 'Use [Subject-Prefix] instead of the standard [PATCH] prefix'") diff --git a/src/build/value_hint.rs b/src/build/value_hint.rs index 3f8d591ce68..647adcc52b7 100644 --- a/src/build/value_hint.rs +++ b/src/build/value_hint.rs @@ -48,11 +48,11 @@ pub enum ValueHint { /// common when writing shell wrappers that execute anther command, for example `sudo` or `env`. /// /// This hint is special, the argument must be a positional argument and have - /// [`.multiple_values(true)`] and App must use [`App::trailing_var_arg(true)`]. The result is that the + /// [`.multiple_values(true)`] and Command must use [`Command::trailing_var_arg(true)`]. The result is that the /// command line `my_app ls -la /` will be parsed as `["ls", "-la", "/"]` and clap won't try to /// parse the `-la` argument itself. /// - /// [`App::trailing_var_arg(true)`]: crate::App::trailing_var_arg + /// [`Command::trailing_var_arg(true)`]: crate::Command::trailing_var_arg /// [`.multiple_values(true)`]: crate::Arg::multiple_values() CommandWithArguments, /// Name of a local operating system user. diff --git a/src/derive.rs b/src/derive.rs index ffe70896a54..6edb9621166 100644 --- a/src/derive.rs +++ b/src/derive.rs @@ -1,14 +1,14 @@ //! This module contains traits that are usable with the `#[derive(...)].` //! macros in [`clap_derive`]. -use crate::{App, ArgMatches, Error, PossibleValue}; +use crate::{ArgMatches, Command, Error, PossibleValue}; use std::ffi::OsString; /// Parse command-line arguments into `Self`. /// /// The primary one-stop-shop trait used to create an instance of a `clap` -/// [`App`], conduct the parsing, and turn the resulting [`ArgMatches`] back +/// [`Command`], conduct the parsing, and turn the resulting [`ArgMatches`] back /// into concrete instance of the user struct. /// /// This trait is primarily a convenience on top of [`FromArgMatches`] + @@ -46,11 +46,11 @@ use std::ffi::OsString; /// } /// ``` /// -/// The equivalent [`App`] struct + `From` implementation: +/// The equivalent [`Command`] struct + `From` implementation: /// /// ```rust -/// # use clap::{App, Arg, ArgMatches}; -/// App::new("demo") +/// # use clap::{Command, Arg, ArgMatches}; +/// Command::new("demo") /// .about("My super CLI") /// .arg(Arg::new("verbose") /// .long("verbose") @@ -154,14 +154,14 @@ pub trait Parser: FromArgMatches + IntoApp + Sized { .map_err(format_error::) } - /// Deprecated, `StructOpt::clap` replaced with [`IntoApp::into_app`] (derive as part of + /// Deprecated, `StructOpt::clap` replaced with [`IntoCommand::into_app`] (derive as part of /// [`Parser`]) #[deprecated( since = "3.0.0", - note = "`StructOpt::clap` is replaced with `IntoApp::into_app` (derived as part of `Parser`)" + note = "`StructOpt::clap` is replaced with `IntoCommand::into_app` (derived as part of `Parser`)" )] #[doc(hidden)] - fn clap<'help>() -> App<'help> { + fn clap<'help>() -> Command<'help> { ::into_app() } @@ -226,18 +226,18 @@ pub trait Parser: FromArgMatches + IntoApp + Sized { } } -/// Create an [`App`] relevant for a user-defined container. +/// Create an [`Command`] relevant for a user-defined container. /// /// Derived as part of [`Parser`]. pub trait IntoApp: Sized { - /// Build an [`App`] that can instantiate `Self`. + /// Build an [`Command`] that can instantiate `Self`. /// /// See [`FromArgMatches::from_arg_matches`] for instantiating `Self`. - fn into_app<'help>() -> App<'help>; - /// Build an [`App`] that can update `self`. + fn into_app<'help>() -> Command<'help>; + /// Build an [`Command`] that can update `self`. /// /// See [`FromArgMatches::update_from_arg_matches`] for updating `self`. - fn into_app_for_update<'help>() -> App<'help>; + fn into_app_for_update<'help>() -> Command<'help>; } /// Converts an instance of [`ArgMatches`] to a user-defined container. @@ -313,16 +313,16 @@ pub trait FromArgMatches: Sized { /// } /// ``` pub trait Args: FromArgMatches + Sized { - /// Append to [`App`] so it can instantiate `Self`. + /// Append to [`Command`] so it can instantiate `Self`. /// /// See also [`IntoApp`]. - fn augment_args(app: App<'_>) -> App<'_>; - /// Append to [`App`] so it can update `self`. + fn augment_args(cmd: Command<'_>) -> Command<'_>; + /// Append to [`Command`] so it can update `self`. /// /// This is used to implement `#[clap(flatten)]` /// /// See also [`IntoApp`]. - fn augment_args_for_update(app: App<'_>) -> App<'_>; + fn augment_args_for_update(cmd: Command<'_>) -> Command<'_>; } /// Parse a sub-command into a user-defined enum. @@ -357,16 +357,16 @@ pub trait Args: FromArgMatches + Sized { /// } /// ``` pub trait Subcommand: FromArgMatches + Sized { - /// Append to [`App`] so it can instantiate `Self`. + /// Append to [`Command`] so it can instantiate `Self`. /// /// See also [`IntoApp`]. - fn augment_subcommands(app: App<'_>) -> App<'_>; - /// Append to [`App`] so it can update `self`. + fn augment_subcommands(cmd: Command<'_>) -> Command<'_>; + /// Append to [`Command`] so it can update `self`. /// /// This is used to implement `#[clap(flatten)]` /// /// See also [`IntoApp`]. - fn augment_subcommands_for_update(app: App<'_>) -> App<'_>; + fn augment_subcommands_for_update(cmd: Command<'_>) -> Command<'_>; /// Test whether `Self` can parse a specific subcommand fn has_subcommand(name: &str) -> bool; } @@ -452,10 +452,10 @@ impl Parser for Box { } impl IntoApp for Box { - fn into_app<'help>() -> App<'help> { + fn into_app<'help>() -> Command<'help> { ::into_app() } - fn into_app_for_update<'help>() -> App<'help> { + fn into_app_for_update<'help>() -> Command<'help> { ::into_app_for_update() } } @@ -470,20 +470,20 @@ impl FromArgMatches for Box { } impl Args for Box { - fn augment_args(app: App<'_>) -> App<'_> { - ::augment_args(app) + fn augment_args(cmd: Command<'_>) -> Command<'_> { + ::augment_args(cmd) } - fn augment_args_for_update(app: App<'_>) -> App<'_> { - ::augment_args_for_update(app) + fn augment_args_for_update(cmd: Command<'_>) -> Command<'_> { + ::augment_args_for_update(cmd) } } impl Subcommand for Box { - fn augment_subcommands(app: App<'_>) -> App<'_> { - ::augment_subcommands(app) + fn augment_subcommands(cmd: Command<'_>) -> Command<'_> { + ::augment_subcommands(cmd) } - fn augment_subcommands_for_update(app: App<'_>) -> App<'_> { - ::augment_subcommands_for_update(app) + fn augment_subcommands_for_update(cmd: Command<'_>) -> Command<'_> { + ::augment_subcommands_for_update(cmd) } fn has_subcommand(name: &str) -> bool { ::has_subcommand(name) @@ -491,6 +491,6 @@ impl Subcommand for Box { } fn format_error(err: crate::Error) -> crate::Error { - let mut app = I::into_app(); - err.format(&mut app) + let mut cmd = I::into_app(); + err.format(&mut cmd) } diff --git a/src/error/kind.rs b/src/error/kind.rs index b93601d9585..1d27f433d62 100644 --- a/src/error/kind.rs +++ b/src/error/kind.rs @@ -8,8 +8,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let result = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let result = Command::new("prog") /// .arg(Arg::new("speed") /// .possible_value("fast") /// .possible_value("slow")) @@ -24,8 +24,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, arg, ErrorKind}; - /// let result = App::new("prog") + /// # use clap::{Command, arg, ErrorKind}; + /// let result = Command::new("prog") /// .arg(arg!(--flag "some flag")) /// .try_get_matches_from(vec!["prog", "--other"]); /// assert!(result.is_err()); @@ -42,9 +42,9 @@ pub enum ErrorKind { /// #[cfg_attr(not(feature = "suggestions"), doc = " ```no_run")] #[cfg_attr(feature = "suggestions", doc = " ```")] - /// # use clap::{App, Arg, ErrorKind, }; - /// let result = App::new("prog") - /// .subcommand(App::new("config") + /// # use clap::{Command, Arg, ErrorKind, }; + /// let result = Command::new("prog") + /// .subcommand(Command::new("config") /// .about("Used for configuration") /// .arg(Arg::new("config_file") /// .help("The configuration file to use") @@ -69,9 +69,9 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind, }; - /// let result = App::new("prog") - /// .subcommand(App::new("config") + /// # use clap::{Command, Arg, ErrorKind, }; + /// let result = Command::new("prog") + /// .subcommand(Command::new("config") /// .about("Used for configuration") /// .arg(Arg::new("config_file") /// .help("The configuration file to use") @@ -92,8 +92,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("color") /// .takes_value(true) /// .forbid_empty_values(true) @@ -108,8 +108,8 @@ pub enum ErrorKind { /// sign to provide values. /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let res = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let res = Command::new("prog") /// .arg(Arg::new("color") /// .takes_value(true) /// .require_equals(true) @@ -126,7 +126,7 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind}; /// fn is_numeric(val: &str) -> Result<(), String> { /// match val.parse::() { /// Ok(..) => Ok(()), @@ -134,7 +134,7 @@ pub enum ErrorKind { /// } /// } /// - /// let result = App::new("prog") + /// let result = Command::new("prog") /// .arg(Arg::new("num") /// .validator(is_numeric)) /// .try_get_matches_from(vec!["prog", "NotANumber"]); @@ -149,8 +149,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let result = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let result = Command::new("prog") /// .arg(Arg::new("arg") /// .max_values(2)) /// .try_get_matches_from(vec!["prog", "too", "many", "values"]); @@ -166,8 +166,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let result = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let result = Command::new("prog") /// .arg(Arg::new("some_opt") /// .long("opt") /// .min_values(3)) @@ -184,8 +184,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let result = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let result = Command::new("prog") /// .arg(Arg::new("verbosity") /// .short('v') /// .max_occurrences(2)) @@ -203,8 +203,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let result = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let result = Command::new("prog") /// .arg(Arg::new("some_opt") /// .long("opt") /// .takes_value(true) @@ -224,8 +224,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let result = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let result = Command::new("prog") /// .arg(Arg::new("debug") /// .long("debug") /// .conflicts_with("color")) @@ -242,8 +242,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let result = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let result = Command::new("prog") /// .arg(Arg::new("debug") /// .required(true)) /// .try_get_matches_from(vec!["prog"]); @@ -252,16 +252,16 @@ pub enum ErrorKind { /// ``` MissingRequiredArgument, - /// Occurs when a subcommand is required (as defined by [`App::subcommand_required`]), + /// Occurs when a subcommand is required (as defined by [`Command::subcommand_required`]), /// but the user does not provide one. /// /// # Examples /// /// ```rust - /// # use clap::{App, ErrorKind}; - /// let err = App::new("prog") + /// # use clap::{Command, ErrorKind}; + /// let err = Command::new("prog") /// .subcommand_required(true) - /// .subcommand(App::new("test")) + /// .subcommand(Command::new("test")) /// .try_get_matches_from(vec![ /// "myprog", /// ]); @@ -270,7 +270,7 @@ pub enum ErrorKind { /// # ; /// ``` /// - /// [`App::subcommand_required`]: crate::App::subcommand_required + /// [`Command::subcommand_required`]: crate::Command::subcommand_required MissingSubcommand, /// Occurs when the user provides multiple values to an argument which doesn't allow that. @@ -278,8 +278,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let result = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let result = Command::new("prog") /// .arg(Arg::new("debug") /// .long("debug") /// .multiple_occurrences(false)) @@ -293,7 +293,7 @@ pub enum ErrorKind { /// /// To allow arbitrary data /// - Set [`Arg::allow_invalid_utf8`] for argument values - /// - Set [`App::allow_invalid_utf8_for_external_subcommands`] for external-subcommand + /// - Set [`Command::allow_invalid_utf8_for_external_subcommands`] for external-subcommand /// values /// /// # Platform Specific @@ -304,10 +304,10 @@ pub enum ErrorKind { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] - /// # use clap::{App, Arg, ErrorKind}; + /// # use clap::{Command, Arg, ErrorKind}; /// # use std::os::unix::ffi::OsStringExt; /// # use std::ffi::OsString; - /// let result = App::new("prog") + /// let result = Command::new("prog") /// .arg(Arg::new("utf8") /// .short('u') /// .takes_value(true)) @@ -319,7 +319,7 @@ pub enum ErrorKind { /// ``` /// /// [`Arg::allow_invalid_utf8`]: crate::Arg::allow_invalid_utf8 - /// [`App::allow_invalid_utf8_for_external_subcommands`]: crate::App::allow_invalid_utf8_for_external_subcommands + /// [`Command::allow_invalid_utf8_for_external_subcommands`]: crate::Command::allow_invalid_utf8_for_external_subcommands InvalidUtf8, /// Not a true "error" as it means `--help` or similar was used. @@ -331,8 +331,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let result = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let result = Command::new("prog") /// .try_get_matches_from(vec!["prog", "--help"]); /// assert!(result.is_err()); /// assert_eq!(result.unwrap_err().kind(), ErrorKind::DisplayHelp); @@ -340,16 +340,16 @@ pub enum ErrorKind { DisplayHelp, /// Occurs when either an argument or a [`Subcommand`] is required, as defined by - /// [`App::arg_required_else_help`] , but the user did not provide + /// [`Command::arg_required_else_help`] , but the user did not provide /// one. /// /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind, }; - /// let result = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind, }; + /// let result = Command::new("prog") /// .arg_required_else_help(true) - /// .subcommand(App::new("config") + /// .subcommand(Command::new("config") /// .about("Used for configuration") /// .arg(Arg::new("config_file") /// .help("The configuration file to use"))) @@ -359,7 +359,7 @@ pub enum ErrorKind { /// ``` /// /// [`Subcommand`]: crate::Subcommand - /// [`App::arg_required_else_help`]: crate::App::arg_required_else_help + /// [`Command::arg_required_else_help`]: crate::Command::arg_required_else_help DisplayHelpOnMissingArgumentOrSubcommand, /// Not a true "error" as it means `--version` or similar was used. @@ -368,8 +368,8 @@ pub enum ErrorKind { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, ErrorKind}; - /// let result = App::new("prog") + /// # use clap::{Command, Arg, ErrorKind}; + /// let result = Command::new("prog") /// .version("3.0") /// .try_get_matches_from(vec!["prog", "--version"]); /// assert!(result.is_err()); diff --git a/src/error/mod.rs b/src/error/mod.rs index 75aaa5131b8..2b8b8380db9 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -17,7 +17,7 @@ use crate::{ output::fmt::Colorizer, parse::features::suggestions, util::{color::ColorChoice, safe_exit, SUCCESS_CODE, USAGE_CODE}, - App, AppSettings, + AppSettings, Command, }; mod context; @@ -34,9 +34,9 @@ pub type Result = StdResult; /// Command Line Argument Parser Error /// -/// See [`App::error`] to create an error. +/// See [`Command::error`] to create an error. /// -/// [`App::error`]: crate::App::error +/// [`Command::error`]: crate::Command::error #[derive(Debug)] pub struct Error { inner: Box, @@ -64,24 +64,24 @@ impl Error { /// Create an unformatted error /// /// This is for you need to pass the error up to - /// a place that has access to the `App` at which point you can call [`Error::format`]. + /// a place that has access to the `Command` at which point you can call [`Error::format`]. /// - /// Prefer [`App::error`] for generating errors. + /// Prefer [`Command::error`] for generating errors. /// - /// [`App::error`]: crate::App::error + /// [`Command::error`]: crate::Command::error pub fn raw(kind: ErrorKind, message: impl std::fmt::Display) -> Self { Self::new(kind).set_message(message.to_string()) } - /// Format the existing message with the App's context + /// Format the existing message with the Command's context #[must_use] - pub fn format(mut self, app: &mut App) -> Self { - app._build(); - let usage = app.render_usage(); + pub fn format(mut self, cmd: &mut Command) -> Self { + cmd._build(); + let usage = cmd.render_usage(); if let Some(message) = self.inner.message.as_mut() { - message.format(app, usage); + message.format(cmd, usage); } - self.with_app(app) + self.with_cmd(cmd) } /// Type of error for programmatic processing @@ -131,9 +131,9 @@ impl Error { /// /// # Example /// ```no_run - /// use clap::App; + /// use clap::Command; /// - /// match App::new("App").try_get_matches() { + /// match Command::new("Command").try_get_matches() { /// Ok(matches) => { /// // do_something /// }, @@ -147,10 +147,10 @@ impl Error { self.formatted().print() } - /// Deprecated, replaced with [`App::error`] + /// Deprecated, replaced with [`Command::error`] /// - /// [`App::error`]: crate::App::error - #[deprecated(since = "3.0.0", note = "Replaced with `App::error`")] + /// [`Command::error`]: crate::Command::error + #[deprecated(since = "3.0.0", note = "Replaced with `Command::error`")] #[doc(hidden)] pub fn with_description(description: String, kind: ErrorKind) -> Self { Error::raw(kind, description) @@ -174,17 +174,17 @@ impl Error { } #[inline(never)] - fn for_app(kind: ErrorKind, app: &App, colorizer: Colorizer, info: Vec) -> Self { + fn for_app(kind: ErrorKind, cmd: &Command, colorizer: Colorizer, info: Vec) -> Self { Self::new(kind) .set_message(colorizer) - .with_app(app) + .with_cmd(cmd) .set_info(info) } - pub(crate) fn with_app(self, app: &App) -> Self { - self.set_wait_on_exit(app.is_set(AppSettings::WaitOnError)) - .set_color(app.get_color()) - .set_help_flag(get_help_flag(app)) + pub(crate) fn with_cmd(self, cmd: &Command) -> Self { + self.set_wait_on_exit(cmd.is_set(AppSettings::WaitOnError)) + .set_color(cmd.get_color()) + .set_help_flag(get_help_flag(cmd)) } pub(crate) fn set_message(mut self, message: impl Into) -> Self { @@ -246,25 +246,25 @@ impl Error { .find_map(|(k, v)| (*k == kind).then(|| v)) } - pub(crate) fn display_help(app: &App, colorizer: Colorizer) -> Self { - Self::for_app(ErrorKind::DisplayHelp, app, colorizer, vec![]) + pub(crate) fn display_help(cmd: &Command, colorizer: Colorizer) -> Self { + Self::for_app(ErrorKind::DisplayHelp, cmd, colorizer, vec![]) } - pub(crate) fn display_help_error(app: &App, colorizer: Colorizer) -> Self { + pub(crate) fn display_help_error(cmd: &Command, colorizer: Colorizer) -> Self { Self::for_app( ErrorKind::DisplayHelpOnMissingArgumentOrSubcommand, - app, + cmd, colorizer, vec![], ) } - pub(crate) fn display_version(app: &App, colorizer: Colorizer) -> Self { - Self::for_app(ErrorKind::DisplayVersion, app, colorizer, vec![]) + pub(crate) fn display_version(cmd: &Command, colorizer: Colorizer) -> Self { + Self::for_app(ErrorKind::DisplayVersion, cmd, colorizer, vec![]) } pub(crate) fn argument_conflict( - app: &App, + cmd: &Command, arg: &Arg, mut others: Vec, usage: String, @@ -276,7 +276,7 @@ impl Error { _ => ContextValue::Strings(others), }; Self::new(ErrorKind::ArgumentConflict) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ ( @@ -288,10 +288,10 @@ impl Error { ]) } - pub(crate) fn empty_value(app: &App, good_vals: &[&str], arg: &Arg, usage: String) -> Self { + pub(crate) fn empty_value(cmd: &Command, good_vals: &[&str], arg: &Arg, usage: String) -> Self { let info = vec![arg.to_string()]; let mut err = Self::new(ErrorKind::EmptyValue) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ ( @@ -309,10 +309,10 @@ impl Error { err } - pub(crate) fn no_equals(app: &App, arg: String, usage: String) -> Self { + pub(crate) fn no_equals(cmd: &Command, arg: String, usage: String) -> Self { let info = vec![arg.to_string()]; Self::new(ErrorKind::NoEquals) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ (ContextKind::InvalidArg, ContextValue::String(arg)), @@ -321,7 +321,7 @@ impl Error { } pub(crate) fn invalid_value( - app: &App, + cmd: &Command, bad_val: String, good_vals: &[&str], arg: &Arg, @@ -332,7 +332,7 @@ impl Error { let suggestion = suggestions::did_you_mean(&bad_val, good_vals.iter()).pop(); let mut err = Self::new(ErrorKind::InvalidValue) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ ( @@ -356,7 +356,7 @@ impl Error { } pub(crate) fn invalid_subcommand( - app: &App, + cmd: &Command, subcmd: String, did_you_mean: String, name: String, @@ -365,7 +365,7 @@ impl Error { let info = vec![subcmd.clone()]; let suggestion = format!("{} -- {}", name, subcmd); Self::new(ErrorKind::InvalidSubcommand) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ (ContextKind::InvalidSubcommand, ContextValue::String(subcmd)), @@ -381,11 +381,11 @@ impl Error { ]) } - pub(crate) fn unrecognized_subcommand(app: &App, subcmd: String, name: String) -> Self { + pub(crate) fn unrecognized_subcommand(cmd: &Command, subcmd: String, name: String) -> Self { let info = vec![subcmd.clone()]; let usage = format!("USAGE:\n {} ", name); Self::new(ErrorKind::UnrecognizedSubcommand) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ (ContextKind::InvalidSubcommand, ContextValue::String(subcmd)), @@ -394,13 +394,13 @@ impl Error { } pub(crate) fn missing_required_argument( - app: &App, + cmd: &Command, required: Vec, usage: String, ) -> Self { let info = required.clone(); Self::new(ErrorKind::MissingRequiredArgument) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ (ContextKind::InvalidArg, ContextValue::Strings(required)), @@ -408,10 +408,10 @@ impl Error { ]) } - pub(crate) fn missing_subcommand(app: &App, name: String, usage: String) -> Self { + pub(crate) fn missing_subcommand(cmd: &Command, name: String, usage: String) -> Self { let info = vec![]; Self::new(ErrorKind::MissingSubcommand) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ (ContextKind::InvalidSubcommand, ContextValue::String(name)), @@ -419,16 +419,16 @@ impl Error { ]) } - pub(crate) fn invalid_utf8(app: &App, usage: String) -> Self { + pub(crate) fn invalid_utf8(cmd: &Command, usage: String) -> Self { let info = vec![]; Self::new(ErrorKind::InvalidUtf8) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([(ContextKind::Usage, ContextValue::String(usage))]) } pub(crate) fn too_many_occurrences( - app: &App, + cmd: &Command, arg: &Arg, max_occurs: usize, curr_occurs: usize, @@ -440,7 +440,7 @@ impl Error { max_occurs.to_string(), ]; Self::new(ErrorKind::TooManyOccurrences) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ ( @@ -459,10 +459,10 @@ impl Error { ]) } - pub(crate) fn too_many_values(app: &App, val: String, arg: String, usage: String) -> Self { + pub(crate) fn too_many_values(cmd: &Command, val: String, arg: String, usage: String) -> Self { let info = vec![arg.to_string(), val.clone()]; Self::new(ErrorKind::TooManyValues) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ (ContextKind::InvalidArg, ContextValue::String(arg)), @@ -472,7 +472,7 @@ impl Error { } pub(crate) fn too_few_values( - app: &App, + cmd: &Command, arg: &Arg, min_vals: usize, curr_vals: usize, @@ -480,7 +480,7 @@ impl Error { ) -> Self { let info = vec![arg.to_string(), curr_vals.to_string(), min_vals.to_string()]; Self::new(ErrorKind::TooFewValues) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ ( @@ -515,7 +515,7 @@ impl Error { } pub(crate) fn wrong_number_of_values( - app: &App, + cmd: &Command, arg: &Arg, num_vals: usize, curr_vals: usize, @@ -523,7 +523,7 @@ impl Error { ) -> Self { let info = vec![arg.to_string(), curr_vals.to_string(), num_vals.to_string()]; Self::new(ErrorKind::WrongNumberOfValues) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ ( @@ -542,10 +542,10 @@ impl Error { ]) } - pub(crate) fn unexpected_multiple_usage(app: &App, arg: &Arg, usage: String) -> Self { + pub(crate) fn unexpected_multiple_usage(cmd: &Command, arg: &Arg, usage: String) -> Self { let info = vec![arg.to_string()]; Self::new(ErrorKind::UnexpectedMultipleUsage) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ ( @@ -557,14 +557,14 @@ impl Error { } pub(crate) fn unknown_argument( - app: &App, + cmd: &Command, arg: String, did_you_mean: Option<(String, Option)>, usage: String, ) -> Self { let info = vec![arg.to_string()]; let mut err = Self::new(ErrorKind::UnknownArgument) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ (ContextKind::InvalidArg, ContextValue::String(arg)), @@ -585,10 +585,10 @@ impl Error { err } - pub(crate) fn unnecessary_double_dash(app: &App, arg: String, usage: String) -> Self { + pub(crate) fn unnecessary_double_dash(cmd: &Command, arg: String, usage: String) -> Self { let info = vec![arg.to_string()]; Self::new(ErrorKind::UnknownArgument) - .with_app(app) + .with_cmd(cmd) .set_info(info) .extend_context_unchecked([ (ContextKind::InvalidArg, ContextValue::String(arg)), @@ -1046,10 +1046,10 @@ fn put_usage(c: &mut Colorizer, usage: impl Into) { c.none(usage); } -fn get_help_flag(app: &App) -> Option<&'static str> { - if !app.is_disable_help_flag_set() { +fn get_help_flag(cmd: &Command) -> Option<&'static str> { + if !cmd.is_disable_help_flag_set() { Some("--help") - } else if app.has_subcommands() && !app.is_disable_help_subcommand_set() { + } else if cmd.has_subcommands() && !cmd.is_disable_help_subcommand_set() { Some("help") } else { None @@ -1087,17 +1087,17 @@ pub(crate) enum Message { } impl Message { - fn format(&mut self, app: &App, usage: String) { + fn format(&mut self, cmd: &Command, usage: String) { match self { Message::Raw(s) => { - let mut c = Colorizer::new(true, app.get_color()); + let mut c = Colorizer::new(true, cmd.get_color()); let mut message = String::new(); std::mem::swap(s, &mut message); start_error(&mut c); c.none(message); put_usage(&mut c, usage); - try_help(&mut c, get_help_flag(app)); + try_help(&mut c, get_help_flag(cmd)); *self = Self::Formatted(c); } Message::Formatted(_) => {} diff --git a/src/lib.rs b/src/lib.rs index 369ee0d7d58..6e4c3b8b1a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,8 +26,9 @@ #[cfg(not(feature = "std"))] compile_error!("`std` feature is currently required to build `clap`"); +pub use crate::build::Command; pub use crate::build::{ - App, AppFlags, AppSettings, Arg, ArgFlags, ArgGroup, ArgSettings, PossibleValue, ValueHint, + AppFlags, AppSettings, Arg, ArgFlags, ArgGroup, ArgSettings, PossibleValue, ValueHint, }; pub use crate::error::Error; pub use crate::parse::{ArgMatches, Indices, OsValues, ValueSource, Values}; @@ -38,6 +39,9 @@ pub use crate::derive::{ArgEnum, Args, FromArgMatches, IntoApp, Parser, Subcomma pub use crate::error::{ErrorKind, Result}; +#[allow(deprecated)] +pub use crate::build::App; + #[cfg(feature = "yaml")] #[doc(hidden)] #[deprecated( @@ -81,10 +85,10 @@ const INTERNAL_ERROR_MSG: &str = "Fatal internal error. Please consider filing a report at https://github.com/clap-rs/clap/issues"; const INVALID_UTF8: &str = "unexpected invalid UTF-8 code point"; -/// Deprecated, replaced with [`App::new`], unless you were looking for [Subcommand] +/// Deprecated, replaced with [`Command::new`], unless you were looking for [Subcommand] #[deprecated( since = "3.0.0", - note = "Replaced with `App::new` unless you intended the `Subcommand` trait" + note = "Replaced with `Command::new` unless you intended the `Subcommand` trait" )] #[doc(hidden)] #[derive(Debug, Copy, Clone)] @@ -92,12 +96,12 @@ pub struct SubCommand {} #[allow(deprecated)] impl SubCommand { - /// Deprecated, replaced with [`App::new`]. + /// Deprecated, replaced with [`Command::new`]. /// Did you mean Subcommand (lower-case c)? - #[deprecated(since = "3.0.0", note = "Replaced with `App::new`")] + #[deprecated(since = "3.0.0", note = "Replaced with `Command::new`")] #[doc(hidden)] pub fn with_name<'help>(name: &str) -> App<'help> { - App::new(name) + Command::new(name) } /// Deprecated in [Issue #3087](https://github.com/clap-rs/clap/issues/3087), maybe [`clap::Parser`][crate::Parser] would fit your use case? @@ -109,6 +113,6 @@ impl SubCommand { #[doc(hidden)] pub fn from_yaml(yaml: &yaml_rust::Yaml) -> App { #![allow(deprecated)] - App::from_yaml(yaml) + Command::from_yaml(yaml) } } diff --git a/src/macros.rs b/src/macros.rs index e6a3bc11f17..49467a616e2 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -186,9 +186,9 @@ macro_rules! arg_enum { /// ```no_run /// # #[macro_use] /// # extern crate clap; -/// # use clap::App; +/// # use clap::Command; /// # fn main() { -/// let m = App::new("app") +/// let m = Command::new("cmd") /// .version(crate_version!()) /// .get_matches(); /// # } @@ -201,7 +201,7 @@ macro_rules! crate_version { }; } -/// Allows you to pull the authors for the app from your Cargo.toml at +/// Allows you to pull the authors for the command from your Cargo.toml at /// compile time in the form: /// `"author1 lastname :author2 lastname "` /// @@ -215,9 +215,9 @@ macro_rules! crate_version { /// ```no_run /// # #[macro_use] /// # extern crate clap; -/// # use clap::App; +/// # use clap::Command; /// # fn main() { -/// let m = App::new("app") +/// let m = Command::new("cmd") /// .author(crate_authors!("\n")) /// .get_matches(); /// # } @@ -245,9 +245,9 @@ macro_rules! crate_authors { /// ```no_run /// # #[macro_use] /// # extern crate clap; -/// # use clap::App; +/// # use clap::Command; /// # fn main() { -/// let m = App::new("app") +/// let m = Command::new("cmd") /// .about(crate_description!()) /// .get_matches(); /// # } @@ -267,9 +267,9 @@ macro_rules! crate_description { /// ```no_run /// # #[macro_use] /// # extern crate clap; -/// # use clap::App; +/// # use clap::Command; /// # fn main() { -/// let m = App::new(crate_name!()) +/// let m = Command::new(crate_name!()) /// .get_matches(); /// # } /// ``` @@ -281,7 +281,7 @@ macro_rules! crate_name { }; } -/// Allows you to build the `App` instance from your Cargo.toml at compile time. +/// Allows you to build the `Command` instance from your Cargo.toml at compile time. /// /// Equivalent to using the `crate_*!` macros with their respective fields. /// @@ -308,34 +308,34 @@ macro_rules! crate_name { #[macro_export] macro_rules! app_from_crate { () => {{ - let mut app = $crate::App::new($crate::crate_name!()).version($crate::crate_version!()); + let mut cmd = $crate::Command::new($crate::crate_name!()).version($crate::crate_version!()); let author = $crate::crate_authors!(", "); if !author.is_empty() { - app = app.author(author) + cmd = cmd.author(author) } let about = $crate::crate_description!(); if !about.is_empty() { - app = app.about(about) + cmd = cmd.about(about) } - app + cmd }}; ($sep:expr) => {{ - let mut app = $crate::App::new($crate::crate_name!()).version($crate::crate_version!()); + let mut cmd = $crate::Command::new($crate::crate_name!()).version($crate::crate_version!()); let author = $crate::crate_authors!($sep); if !author.is_empty() { - app = app.author(author) + cmd = cmd.author(author) } let about = $crate::crate_description!(); if !about.is_empty() { - app = app.about(about) + cmd = cmd.about(about) } - app + cmd }}; } @@ -607,8 +607,8 @@ macro_rules! arg_impl { /// # Examples /// /// ```rust -/// # use clap::{App, Arg, arg}; -/// App::new("prog") +/// # use clap::{Command, Arg, arg}; +/// Command::new("prog") /// .args(&[ /// arg!(--config "a required file for the configuration and no short"), /// arg!(-d --debug ... "turns on debugging information and allows multiples"), @@ -688,7 +688,7 @@ macro_rules! clap_app { (@app ($builder:expr) (@subcommand $name:ident => $($tail:tt)*) $($tt:tt)*) => { $crate::clap_app!{ @app ($builder.subcommand( - $crate::clap_app!{ @app ($crate::App::new(stringify!($name))) $($tail)* } + $crate::clap_app!{ @app ($crate::Command::new(stringify!($name))) $($tail)* } )) $($tt)* } @@ -780,15 +780,15 @@ macro_rules! clap_app { // Build a subcommand outside of an app. (@subcommand $name:ident => $($tail:tt)*) => { - $crate::clap_app!{ @app ($crate::App::new(stringify!($name))) $($tail)* } + $crate::clap_app!{ @app ($crate::Command::new(stringify!($name))) $($tail)* } }; // Start the magic (($name:expr) => $($tail:tt)*) => {{ - $crate::clap_app!{ @app ($crate::App::new($name)) $($tail)*} + $crate::clap_app!{ @app ($crate::Command::new($name)) $($tail)*} }}; ($name:ident => $($tail:tt)*) => {{ - $crate::clap_app!{ @app ($crate::App::new(stringify!($name))) $($tail)*} + $crate::clap_app!{ @app ($crate::Command::new(stringify!($name))) $($tail)*} }}; } diff --git a/src/output/help.rs b/src/output/help.rs index b1faad889d9..7f5fb3bd7bc 100644 --- a/src/output/help.rs +++ b/src/output/help.rs @@ -9,7 +9,7 @@ use std::{ // Internal use crate::{ - build::{arg::display_arg_val, App, Arg}, + build::{display_arg_val, Arg, Command}, output::{fmt::Colorizer, Usage}, }; @@ -20,17 +20,17 @@ use textwrap::core::display_width; /// `clap` Help Writer. /// /// Wraps a writer stream providing different methods to generate help for `clap` objects. -pub(crate) struct Help<'help, 'app, 'writer> { +pub(crate) struct Help<'help, 'cmd, 'writer> { writer: HelpWriter<'writer>, - app: &'app App<'help>, - usage: &'app Usage<'help, 'app>, + cmd: &'cmd Command<'help>, + usage: &'cmd Usage<'help, 'cmd>, next_line_help: bool, term_w: usize, use_long: bool, } // Public Functions -impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { +impl<'help, 'cmd, 'writer> Help<'help, 'cmd, 'writer> { const DEFAULT_TEMPLATE: &'static str = "\ {before-help}{bin} {version}\n\ {author-with-newline}{about-with-newline}\n\ @@ -48,27 +48,27 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { /// Create a new `Help` instance. pub(crate) fn new( writer: HelpWriter<'writer>, - app: &'app App<'help>, - usage: &'app Usage<'help, 'app>, + cmd: &'cmd Command<'help>, + usage: &'cmd Usage<'help, 'cmd>, use_long: bool, ) -> Self { debug!("Help::new"); - let term_w = match app.get_term_width() { + let term_w = match cmd.get_term_width() { Some(0) => usize::MAX, Some(w) => w, None => cmp::min( dimensions().map_or(100, |(w, _)| w), - match app.get_max_term_width() { + match cmd.get_max_term_width() { None | Some(0) => usize::MAX, Some(mw) => mw, }, ), }; - let next_line_help = app.is_next_line_help_set(); + let next_line_help = cmd.is_next_line_help_set(); Help { writer, - app, + cmd, usage, next_line_help, term_w, @@ -80,20 +80,20 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { pub(crate) fn write_help(&mut self) -> io::Result<()> { debug!("Help::write_help"); - if let Some(h) = self.app.get_override_help() { + if let Some(h) = self.cmd.get_override_help() { self.none(h)?; - } else if let Some(tmpl) = self.app.get_help_template() { + } else if let Some(tmpl) = self.cmd.get_help_template() { self.write_templated_help(tmpl)?; } else { let pos = self - .app + .cmd .get_positionals() .any(|arg| should_show_arg(self.use_long, arg)); let non_pos = self - .app + .cmd .get_non_positionals() .any(|arg| should_show_arg(self.use_long, arg)); - let subcmds = self.app.has_visible_subcommands(); + let subcmds = self.cmd.has_visible_subcommands(); if non_pos || pos || subcmds { self.write_templated_help(Self::DEFAULT_TEMPLATE)?; @@ -121,7 +121,7 @@ macro_rules! write_method { } // Methods to write Arg help. -impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { +impl<'help, 'cmd, 'writer> Help<'help, 'cmd, 'writer> { #[inline(never)] fn good + AsRef<[u8]>>(&mut self, msg: T) -> io::Result<()> { write_method!(self, msg, good) @@ -353,11 +353,11 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { fn write_before_help(&mut self) -> io::Result<()> { debug!("Help::write_before_help"); let before_help = if self.use_long { - self.app + self.cmd .get_before_long_help() - .or_else(|| self.app.get_before_help()) + .or_else(|| self.cmd.get_before_help()) } else { - self.app.get_before_help() + self.cmd.get_before_help() }; if let Some(output) = before_help { self.none(text_wrapper(&output.replace("{n}", "\n"), self.term_w))?; @@ -369,11 +369,11 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { fn write_after_help(&mut self) -> io::Result<()> { debug!("Help::write_after_help"); let after_help = if self.use_long { - self.app + self.cmd .get_after_long_help() - .or_else(|| self.app.get_after_help()) + .or_else(|| self.cmd.get_after_help()) } else { - self.app.get_after_help() + self.cmd.get_after_help() }; if let Some(output) = after_help { self.none("\n\n")?; @@ -610,9 +610,9 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { fn write_about(&mut self, before_new_line: bool, after_new_line: bool) -> io::Result<()> { let about = if self.use_long { - self.app.get_long_about().or_else(|| self.app.get_about()) + self.cmd.get_long_about().or_else(|| self.cmd.get_about()) } else { - self.app.get_about() + self.cmd.get_about() }; if let Some(output) = about { if before_new_line { @@ -627,7 +627,7 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { } fn write_author(&mut self, before_new_line: bool, after_new_line: bool) -> io::Result<()> { - if let Some(author) = self.app.get_author() { + if let Some(author) = self.cmd.get_author() { if before_new_line { self.none("\n")?; } @@ -641,9 +641,9 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { fn write_version(&mut self) -> io::Result<()> { let version = self - .app + .cmd .get_version() - .or_else(|| self.app.get_long_version()); + .or_else(|| self.cmd.get_long_version()); if let Some(output) = version { self.none(text_wrapper(output, self.term_w))?; } @@ -652,28 +652,28 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { } /// Methods to write a single subcommand -impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { +impl<'help, 'cmd, 'writer> Help<'help, 'cmd, 'writer> { fn write_subcommand( &mut self, sc_str: &str, - app: &App<'help>, + cmd: &Command<'help>, next_line_help: bool, longest: usize, ) -> io::Result<()> { debug!("Help::write_subcommand"); - let spec_vals = &self.sc_spec_vals(app); + let spec_vals = &self.sc_spec_vals(cmd); - let about = app + let about = cmd .get_about() - .or_else(|| app.get_long_about()) + .or_else(|| cmd.get_long_about()) .unwrap_or(""); self.subcmd(sc_str, next_line_help, longest)?; self.help(false, about, spec_vals, next_line_help, longest) } - fn sc_spec_vals(&self, a: &App) -> String { + fn sc_spec_vals(&self, a: &Command) -> String { debug!("Help::sc_spec_vals: a={}", a.get_name()); let mut spec_vals = vec![]; if 0 < a.get_all_aliases().count() || 0 < a.get_all_short_flag_aliases().count() { @@ -704,13 +704,18 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { spec_vals.join(" ") } - fn subcommand_next_line_help(&self, app: &App<'help>, spec_vals: &str, longest: usize) -> bool { + fn subcommand_next_line_help( + &self, + cmd: &Command<'help>, + spec_vals: &str, + longest: usize, + ) -> bool { if self.next_line_help | self.use_long { // setting_next_line true } else { // force_next_line - let h = app.get_about().unwrap_or(""); + let h = cmd.get_about().unwrap_or(""); let h_w = display_width(h) + display_width(spec_vals); let taken = longest + 12; self.term_w >= taken @@ -732,25 +737,25 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { } // Methods to write Parser help. -impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { +impl<'help, 'cmd, 'writer> Help<'help, 'cmd, 'writer> { /// Writes help for all arguments (options, flags, args, subcommands) /// including titles of a Parser Object to the wrapped stream. pub(crate) fn write_all_args(&mut self) -> io::Result<()> { debug!("Help::write_all_args"); let pos = self - .app + .cmd .get_positionals_with_no_heading() .filter(|arg| should_show_arg(self.use_long, arg)) .collect::>(); let non_pos = self - .app + .cmd .get_non_positionals_with_no_heading() .filter(|arg| should_show_arg(self.use_long, arg)) .collect::>(); - let subcmds = self.app.has_visible_subcommands(); + let subcmds = self.cmd.has_visible_subcommands(); let custom_headings = self - .app + .cmd .get_arguments() .filter_map(|arg| arg.get_help_heading()) .collect::>(); @@ -775,7 +780,7 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { if !custom_headings.is_empty() { for heading in custom_headings { let args = self - .app + .cmd .get_arguments() .filter(|a| { if let Some(help_heading) = a.get_help_heading() { @@ -803,13 +808,13 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { } self.warning( - self.app + self.cmd .get_subcommand_help_heading() .unwrap_or("SUBCOMMANDS"), )?; self.warning(":\n")?; - self.write_subcommands(self.app)?; + self.write_subcommands(self.cmd)?; } Ok(()) @@ -818,7 +823,7 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { /// Will use next line help on writing subcommands. fn will_subcommands_wrap<'a>( &self, - subcommands: impl IntoIterator>, + subcommands: impl IntoIterator>, longest: usize, ) -> bool where @@ -834,12 +839,12 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { } /// Writes help for subcommands of a Parser Object to the wrapped stream. - fn write_subcommands(&mut self, app: &App<'help>) -> io::Result<()> { + fn write_subcommands(&mut self, cmd: &Command<'help>) -> io::Result<()> { debug!("Help::write_subcommands"); // The shortest an arg can legally be is 2 (i.e. '-x') let mut longest = 2; let mut ord_v = Vec::new(); - for subcommand in app + for subcommand in cmd .get_subcommands() .filter(|subcommand| should_show_subcommand(subcommand)) { @@ -858,7 +863,7 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { debug!("Help::write_subcommands longest = {}", longest); - let next_line_help = self.will_subcommands_wrap(app.get_subcommands(), longest); + let next_line_help = self.will_subcommands_wrap(cmd.get_subcommands(), longest); let mut first = true; for (_, sc_str, sc) in &ord_v { @@ -876,15 +881,15 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { fn write_bin_name(&mut self) -> io::Result<()> { debug!("Help::write_bin_name"); - let bin_name = if let Some(bn) = self.app.get_bin_name() { + let bin_name = if let Some(bn) = self.cmd.get_bin_name() { if bn.contains(' ') { // In case we're dealing with subcommands i.e. git mv is translated to git-mv bn.replace(' ', "-") } else { - text_wrapper(&self.app.get_name().replace("{n}", "\n"), self.term_w) + text_wrapper(&self.cmd.get_name().replace("{n}", "\n"), self.term_w) } } else { - text_wrapper(&self.app.get_name().replace("{n}", "\n"), self.term_w) + text_wrapper(&self.cmd.get_name().replace("{n}", "\n"), self.term_w) }; self.good(&bin_name)?; Ok(()) @@ -892,12 +897,12 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { } // Methods to write Parser help using templates. -impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { +impl<'help, 'cmd, 'writer> Help<'help, 'cmd, 'writer> { /// Write help to stream for the parser in the format defined by the template. /// - /// For details about the template language see [`App::help_template`]. + /// For details about the template language see [`Command::help_template`]. /// - /// [`App::help_template`]: App::help_template() + /// [`Command::help_template`]: Command::help_template() fn write_templated_help(&mut self, template: &str) -> io::Result<()> { debug!("Help::write_templated_help"); @@ -975,13 +980,13 @@ impl<'help, 'app, 'writer> Help<'help, 'app, 'writer> { "options" => { // Include even those with a heading as we don't have a good way of // handling help_heading in the template. - self.write_args(&self.app.get_non_positionals().collect::>())?; + self.write_args(&self.cmd.get_non_positionals().collect::>())?; } "positionals" => { - self.write_args(&self.app.get_positionals().collect::>())?; + self.write_args(&self.cmd.get_positionals().collect::>())?; } "subcommands" => { - self.write_subcommands(self.app)?; + self.write_subcommands(self.cmd)?; } "after-help" => { self.write_after_help()?; @@ -1022,7 +1027,7 @@ fn should_show_arg(use_long: bool, arg: &Arg) -> bool { || arg.is_next_line_help_set() } -fn should_show_subcommand(subcommand: &App) -> bool { +fn should_show_subcommand(subcommand: &Command) -> bool { !subcommand.is_hide_set() } diff --git a/src/output/usage.rs b/src/output/usage.rs index ecbf85b6310..45cfa746cf5 100644 --- a/src/output/usage.rs +++ b/src/output/usage.rs @@ -2,26 +2,26 @@ use indexmap::IndexSet; // Internal use crate::build::AppSettings as AS; -use crate::build::{App, Arg, ArgPredicate}; +use crate::build::{Arg, ArgPredicate, Command}; use crate::parse::ArgMatcher; use crate::util::ChildGraph; use crate::util::Id; use crate::INTERNAL_ERROR_MSG; -pub(crate) struct Usage<'help, 'app> { - app: &'app App<'help>, - required: Option<&'app ChildGraph>, +pub(crate) struct Usage<'help, 'cmd> { + cmd: &'cmd Command<'help>, + required: Option<&'cmd ChildGraph>, } -impl<'help, 'app> Usage<'help, 'app> { - pub(crate) fn new(app: &'app App<'help>) -> Self { +impl<'help, 'cmd> Usage<'help, 'cmd> { + pub(crate) fn new(cmd: &'cmd Command<'help>) -> Self { Usage { - app, + cmd, required: None, } } - pub(crate) fn required(mut self, required: &'app ChildGraph) -> Self { + pub(crate) fn required(mut self, required: &'cmd ChildGraph) -> Self { self.required = Some(required); self } @@ -39,7 +39,7 @@ impl<'help, 'app> Usage<'help, 'app> { // Creates a usage string (*without title*) if one was not provided by the user manually. pub(crate) fn create_usage_no_title(&self, used: &[Id]) -> String { debug!("Usage::create_usage_no_title"); - if let Some(u) = self.app.get_override_usage() { + if let Some(u) = self.cmd.get_override_usage() { String::from(&*u) } else if used.is_empty() { self.create_help_usage(true) @@ -53,10 +53,10 @@ impl<'help, 'app> Usage<'help, 'app> { debug!("Usage::create_help_usage; incl_reqs={:?}", incl_reqs); let mut usage = String::with_capacity(75); let name = self - .app + .cmd .get_usage_name() - .or_else(|| self.app.get_bin_name()) - .unwrap_or_else(|| self.app.get_name()); + .or_else(|| self.cmd.get_bin_name()) + .unwrap_or_else(|| self.cmd.get_name()); usage.push_str(name); let req_string = if incl_reqs { self.get_required_usage_from(&[], None, false) @@ -70,27 +70,27 @@ impl<'help, 'app> Usage<'help, 'app> { usage.push_str(" [OPTIONS]"); } - let allow_missing_positional = self.app.is_allow_missing_positional_set(); + let allow_missing_positional = self.cmd.is_allow_missing_positional_set(); if !allow_missing_positional { usage.push_str(&req_string); } - let has_last = self.app.get_positionals().any(|p| p.is_last_set()); + let has_last = self.cmd.get_positionals().any(|p| p.is_last_set()); // places a '--' in the usage string if there are args and options // supporting multiple values if self - .app + .cmd .get_non_positionals() .any(|o| o.is_multiple_values_set()) - && self.app.get_positionals().any(|p| !p.is_required_set()) - && !(self.app.has_visible_subcommands() || self.app.is_allow_external_subcommands_set()) + && self.cmd.get_positionals().any(|p| !p.is_required_set()) + && !(self.cmd.has_visible_subcommands() || self.cmd.is_allow_external_subcommands_set()) && !has_last { usage.push_str(" [--]"); } let not_req_or_hidden = |p: &Arg| (!p.is_required_set() || p.is_last_set()) && !p.is_hide_set(); - if self.app.get_positionals().any(not_req_or_hidden) { + if self.cmd.get_positionals().any(not_req_or_hidden) { if let Some(args_tag) = self.get_args_tag(incl_reqs) { usage.push_str(&*args_tag); } else { @@ -98,13 +98,13 @@ impl<'help, 'app> Usage<'help, 'app> { } if has_last && incl_reqs { let pos = self - .app + .cmd .get_positionals() .find(|p| p.is_last_set()) .expect(INTERNAL_ERROR_MSG); debug!("Usage::create_help_usage: '{}' has .last(true)", pos.name); let req = pos.is_required_set(); - if req && self.app.get_positionals().any(|p| !p.is_required_set()) { + if req && self.cmd.get_positionals().any(|p| !p.is_required_set()) { usage.push_str(" -- <"); } else if req { usage.push_str(" [--] <"); @@ -125,16 +125,16 @@ impl<'help, 'app> Usage<'help, 'app> { } // incl_reqs is only false when this function is called recursively - if self.app.has_visible_subcommands() && incl_reqs - || self.app.is_allow_external_subcommands_set() + if self.cmd.has_visible_subcommands() && incl_reqs + || self.cmd.is_allow_external_subcommands_set() { - let placeholder = self.app.get_subcommand_value_name().unwrap_or("SUBCOMMAND"); + let placeholder = self.cmd.get_subcommand_value_name().unwrap_or("SUBCOMMAND"); #[allow(deprecated)] - if self.app.is_subcommand_negates_reqs_set() - || self.app.is_args_conflicts_with_subcommands_set() + if self.cmd.is_subcommand_negates_reqs_set() + || self.cmd.is_args_conflicts_with_subcommands_set() { usage.push_str("\n "); - if !self.app.is_args_conflicts_with_subcommands_set() { + if !self.cmd.is_args_conflicts_with_subcommands_set() { usage.push_str(&*self.create_help_usage(false)); } else { usage.push_str(&*name); @@ -142,8 +142,8 @@ impl<'help, 'app> Usage<'help, 'app> { usage.push_str(" <"); usage.push_str(placeholder); usage.push('>'); - } else if self.app.is_subcommand_required_set() - || self.app.is_set(AS::SubcommandRequiredElseHelp) + } else if self.cmd.is_subcommand_required_set() + || self.cmd.is_set(AS::SubcommandRequiredElseHelp) { usage.push_str(" <"); usage.push_str(placeholder); @@ -171,15 +171,15 @@ impl<'help, 'app> Usage<'help, 'app> { .fold(String::new(), |acc, s| acc + " " + s); usage.push_str( - self.app + self.cmd .get_usage_name() - .or_else(|| self.app.get_bin_name()) - .unwrap_or_else(|| self.app.get_name()), + .or_else(|| self.cmd.get_bin_name()) + .unwrap_or_else(|| self.cmd.get_name()), ); usage.push_str(&*r_string); - if self.app.is_subcommand_required_set() { + if self.cmd.is_subcommand_required_set() { usage.push_str(" <"); - usage.push_str(self.app.get_subcommand_value_name().unwrap_or("SUBCOMMAND")); + usage.push_str(self.cmd.get_subcommand_value_name().unwrap_or("SUBCOMMAND")); usage.push('>'); } usage.shrink_to_fit(); @@ -191,17 +191,17 @@ impl<'help, 'app> Usage<'help, 'app> { debug!("Usage::get_args_tag; incl_reqs = {:?}", incl_reqs); let mut count = 0; for pos in self - .app + .cmd .get_positionals() .filter(|pos| !pos.is_required_set()) .filter(|pos| !pos.is_hide_set()) .filter(|pos| !pos.is_last_set()) { debug!("Usage::get_args_tag:iter:{}", pos.name); - let required = self.app.groups_for_arg(&pos.id).any(|grp_s| { + let required = self.cmd.groups_for_arg(&pos.id).any(|grp_s| { debug!("Usage::get_args_tag:iter:{:?}:iter:{:?}", pos.name, grp_s); // if it's part of a required group we don't want to count it - self.app.get_groups().any(|g| g.required && (g.id == grp_s)) + self.cmd.get_groups().any(|g| g.required && (g.id == grp_s)) }); if !required { count += 1; @@ -212,23 +212,23 @@ impl<'help, 'app> Usage<'help, 'app> { } } - if !self.app.is_dont_collapse_args_in_usage_set() && count > 1 { + if !self.cmd.is_dont_collapse_args_in_usage_set() && count > 1 { debug!("Usage::get_args_tag:iter: More than one, returning [ARGS]"); // [ARGS] None } else if count == 1 && incl_reqs { let pos = self - .app + .cmd .get_positionals() .find(|pos| { !pos.is_required_set() && !pos.is_hide_set() && !pos.is_last_set() - && !self.app.groups_for_arg(&pos.id).any(|grp_s| { + && !self.cmd.groups_for_arg(&pos.id).any(|grp_s| { debug!("Usage::get_args_tag:iter:{:?}:iter:{:?}", pos.name, grp_s); // if it's part of a required group we don't want to count it - self.app.get_groups().any(|g| g.required && (g.id == grp_s)) + self.cmd.get_groups().any(|g| g.required && (g.id == grp_s)) }) }) .expect(INTERNAL_ERROR_MSG); @@ -243,13 +243,13 @@ impl<'help, 'app> Usage<'help, 'app> { pos.name_no_brackets(), pos.multiple_str() )) - } else if self.app.is_dont_collapse_args_in_usage_set() - && self.app.has_positionals() + } else if self.cmd.is_dont_collapse_args_in_usage_set() + && self.cmd.has_positionals() && incl_reqs { debug!("Usage::get_args_tag:iter: Don't collapse returning all"); Some( - self.app + self.cmd .get_positionals() .filter(|pos| !pos.is_required_set()) .filter(|pos| !pos.is_hide_set()) @@ -261,7 +261,7 @@ impl<'help, 'app> Usage<'help, 'app> { } else if !incl_reqs { debug!("Usage::get_args_tag:iter: incl_reqs=false, building secondary usage string"); let highest_req_pos = self - .app + .cmd .get_positionals() .filter_map(|pos| { if pos.is_required_set() && !pos.is_last_set() { @@ -271,9 +271,9 @@ impl<'help, 'app> Usage<'help, 'app> { } }) .max() - .unwrap_or_else(|| Some(self.app.get_positionals().count())); + .unwrap_or_else(|| Some(self.cmd.get_positionals().count())); Some( - self.app + self.cmd .get_positionals() .filter(|pos| pos.index <= highest_req_pos) .filter(|pos| !pos.is_required_set()) @@ -291,7 +291,7 @@ impl<'help, 'app> Usage<'help, 'app> { // Determines if we need the `[OPTIONS]` tag in the usage string fn needs_options_tag(&self) -> bool { debug!("Usage::needs_options_tag"); - 'outer: for f in self.app.get_non_positionals() { + 'outer: for f in self.cmd.get_non_positionals() { debug!("Usage::needs_options_tag:iter: f={}", f.name); // Don't print `[OPTIONS]` just for help or version @@ -308,9 +308,9 @@ impl<'help, 'app> Usage<'help, 'app> { debug!("Usage::needs_options_tag:iter Option is required"); continue; } - for grp_s in self.app.groups_for_arg(&f.id) { + for grp_s in self.cmd.groups_for_arg(&f.id) { debug!("Usage::needs_options_tag:iter:iter: grp_s={:?}", grp_s); - if self.app.get_groups().any(|g| g.id == grp_s && g.required) { + if self.cmd.get_groups().any(|g| g.id == grp_s && g.required) { debug!("Usage::needs_options_tag:iter:iter: Group is required"); continue 'outer; } @@ -348,7 +348,7 @@ impl<'help, 'app> Usage<'help, 'app> { let required = if let Some(required) = self.required { required } else { - required_owned = self.app.required_graph(); + required_owned = self.cmd.required_graph(); &required_owned }; @@ -367,7 +367,7 @@ impl<'help, 'app> Usage<'help, 'app> { required.then(|| req_arg.clone()) }; - for aa in self.app.unroll_arg_requires(is_relevant, a) { + for aa in self.cmd.unroll_arg_requires(is_relevant, a) { // if we don't check for duplicates here this causes duplicate error messages // see https://github.com/clap-rs/clap/issues/2770 unrolled_reqs.insert(aa); @@ -383,33 +383,33 @@ impl<'help, 'app> Usage<'help, 'app> { ); let args_in_groups = self - .app + .cmd .get_groups() .filter(|gn| required.contains(&gn.id)) - .flat_map(|g| self.app.unroll_args_in_group(&g.id)) + .flat_map(|g| self.cmd.unroll_args_in_group(&g.id)) .collect::>(); for a in unrolled_reqs .iter() .chain(incls.iter()) - .filter(|name| !self.app.get_positionals().any(|p| &&p.id == name)) - .filter(|name| !self.app.get_groups().any(|g| &&g.id == name)) + .filter(|name| !self.cmd.get_positionals().any(|p| &&p.id == name)) + .filter(|name| !self.cmd.get_groups().any(|g| &&g.id == name)) .filter(|name| !args_in_groups.contains(name)) .filter(|name| !(matcher.is_some() && matcher.as_ref().unwrap().contains(name))) { debug!("Usage::get_required_usage_from:iter:{:?}", a); - let arg = self.app.find(a).expect(INTERNAL_ERROR_MSG).to_string(); + let arg = self.cmd.find(a).expect(INTERNAL_ERROR_MSG).to_string(); ret_val.push(arg); } let mut g_vec: Vec = vec![]; for g in unrolled_reqs .iter() - .filter(|n| self.app.get_groups().any(|g| g.id == **n)) + .filter(|n| self.cmd.get_groups().any(|g| g.id == **n)) { // don't print requirement for required groups that have an arg. if let Some(m) = matcher { let have_group_entry = self - .app + .cmd .unroll_args_in_group(g) .iter() .any(|arg| m.contains(arg)); @@ -418,7 +418,7 @@ impl<'help, 'app> Usage<'help, 'app> { } } - let elem = self.app.format_group(g); + let elem = self.cmd.format_group(g); if !g_vec.contains(&elem) { g_vec.push(elem); } @@ -428,9 +428,9 @@ impl<'help, 'app> Usage<'help, 'app> { let mut pvec = unrolled_reqs .iter() .chain(incls.iter()) - .filter(|a| self.app.get_positionals().any(|p| &&p.id == a)) + .filter(|a| self.cmd.get_positionals().any(|p| &&p.id == a)) .filter(|&pos| matcher.map_or(true, |m| !m.contains(pos))) - .filter_map(|pos| self.app.find(pos)) + .filter_map(|pos| self.cmd.find(pos)) .filter(|&pos| incl_last || !pos.is_last_set()) .filter(|pos| !args_in_groups.contains(&pos.id)) .map(|pos| (pos.index.unwrap(), pos)) diff --git a/src/parse/arg_matcher.rs b/src/parse/arg_matcher.rs index 8a6833bd7b3..323fb5b9abc 100644 --- a/src/parse/arg_matcher.rs +++ b/src/parse/arg_matcher.rs @@ -3,7 +3,7 @@ use std::{collections::HashMap, ffi::OsString, mem, ops::Deref}; // Internal use crate::{ - build::{App, Arg, ArgPredicate}, + build::{Arg, ArgPredicate, Command}, parse::{ArgMatches, MatchedArg, SubCommand, ValueSource}, util::Id, }; @@ -15,22 +15,22 @@ use indexmap::map::Entry; pub(crate) struct ArgMatcher(ArgMatches); impl ArgMatcher { - pub(crate) fn new(_app: &App) -> Self { + pub(crate) fn new(_cmd: &Command) -> Self { ArgMatcher(ArgMatches { #[cfg(debug_assertions)] valid_args: { - let args = _app.get_arguments().map(|a| a.id.clone()); - let groups = _app.get_groups().map(|g| g.id.clone()); + let args = _cmd.get_arguments().map(|a| a.id.clone()); + let groups = _cmd.get_groups().map(|g| g.id.clone()); args.chain(groups).collect() }, #[cfg(debug_assertions)] - valid_subcommands: _app.get_subcommands().map(|sc| sc.get_id()).collect(), + valid_subcommands: _cmd.get_subcommands().map(|sc| sc.get_id()).collect(), // HACK: Allow an external subcommand's ArgMatches be a stand-in for any ArgMatches // since users can't detect it and avoid the asserts. // // See clap-rs/clap#3263 #[cfg(debug_assertions)] - disable_asserts: _app.is_allow_external_subcommands_set(), + disable_asserts: _cmd.is_allow_external_subcommands_set(), ..Default::default() }) } diff --git a/src/parse/features/suggestions.rs b/src/parse/features/suggestions.rs index ddb9c17dca6..76d16ac829a 100644 --- a/src/parse/features/suggestions.rs +++ b/src/parse/features/suggestions.rs @@ -2,7 +2,7 @@ use std::cmp::Ordering; // Internal -use crate::build::App; +use crate::build::Command; /// Produces multiple strings from a given list of possible values which are similar /// to the passed in value `v` within a certain confidence by least confidence. @@ -37,7 +37,7 @@ pub(crate) fn did_you_mean_flag<'a, 'help, I, T>( arg: &str, remaining_args: &[&str], longs: I, - subcommands: impl IntoIterator>, + subcommands: impl IntoIterator>, ) -> Option<(String, Option)> where 'help: 'a, diff --git a/src/parse/matches/arg_matches.rs b/src/parse/matches/arg_matches.rs index dbc86b5c21c..3815f8e1aba 100644 --- a/src/parse/matches/arg_matches.rs +++ b/src/parse/matches/arg_matches.rs @@ -20,14 +20,14 @@ use crate::{Error, INVALID_UTF8}; /// Container for parse results. /// /// Used to get information about the arguments that were supplied to the program at runtime by -/// the user. New instances of this struct are obtained by using the [`App::get_matches`] family of +/// the user. New instances of this struct are obtained by using the [`Command::get_matches`] family of /// methods. /// /// # Examples /// /// ```no_run -/// # use clap::{App, Arg}; -/// let matches = App::new("MyApp") +/// # use clap::{Command, Arg}; +/// let matches = Command::new("MyApp") /// .arg(Arg::new("out") /// .long("output") /// .required(true) @@ -65,7 +65,7 @@ use crate::{Error, INVALID_UTF8}; /// } /// } /// ``` -/// [`App::get_matches`]: crate::App::get_matches() +/// [`Command::get_matches`]: crate::Command::get_matches() #[derive(Debug, Clone, Default, PartialEq, Eq)] pub struct ArgMatches { #[cfg(debug_assertions)] @@ -84,17 +84,17 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let mut app = App::new("myapp") + /// # use clap::{Command, Arg}; + /// let mut cmd = Command::new("myapp") /// .arg(Arg::new("output") /// .takes_value(true)); /// - /// let m = app + /// let m = cmd /// .try_get_matches_from_mut(vec!["myapp", "something"]) /// .unwrap(); /// assert!(m.args_present()); /// - /// let m = app + /// let m = cmd /// .try_get_matches_from_mut(vec!["myapp"]) /// .unwrap(); /// assert!(! m.args_present()); @@ -125,8 +125,8 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myapp") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myapp") /// .arg(Arg::new("output") /// .takes_value(true)) /// .get_matches_from(vec!["myapp", "something"]); @@ -172,11 +172,11 @@ impl ArgMatches { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] - /// # use clap::{App, arg}; + /// # use clap::{Command, arg}; /// use std::ffi::OsString; /// use std::os::unix::ffi::{OsStrExt,OsStringExt}; /// - /// let m = App::new("utf8") + /// let m = Command::new("utf8") /// .arg(arg!( "some arg") /// .allow_invalid_utf8(true)) /// .get_matches_from(vec![OsString::from("myprog"), @@ -223,11 +223,11 @@ impl ArgMatches { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] - /// # use clap::{App, arg}; + /// # use clap::{Command, arg}; /// use std::ffi::OsString; /// use std::os::unix::ffi::{OsStrExt,OsStringExt}; /// - /// let m = App::new("utf8") + /// let m = Command::new("utf8") /// .arg(arg!( "some arg") /// .allow_invalid_utf8(true)) /// .get_matches_from(vec![OsString::from("myprog"), @@ -263,8 +263,8 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myprog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myprog") /// .arg(Arg::new("output") /// .multiple_occurrences(true) /// .short('o') @@ -325,11 +325,11 @@ impl ArgMatches { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] - /// # use clap::{App, arg}; + /// # use clap::{Command, arg}; /// use std::ffi::OsString; /// use std::os::unix::ffi::OsStringExt; /// - /// let m = App::new("utf8") + /// let m = Command::new("utf8") /// .arg(arg!( ... "some arg") /// .allow_invalid_utf8(true)) /// .get_matches_from(vec![OsString::from("myprog"), @@ -374,11 +374,11 @@ impl ArgMatches { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] - /// # use clap::{App, arg}; + /// # use clap::{Command, arg}; /// use std::ffi::{OsStr,OsString}; /// use std::os::unix::ffi::{OsStrExt,OsStringExt}; /// - /// let m = App::new("utf8") + /// let m = Command::new("utf8") /// .arg(arg!( ... "some arg") /// .allow_invalid_utf8(true)) /// .get_matches_from(vec![OsString::from("myprog"), @@ -430,8 +430,8 @@ impl ArgMatches { /// # Examples /// /// ``` - /// # use clap::{App, arg}; - /// let matches = App::new("myapp") + /// # use clap::{Command, arg}; + /// let matches = Command::new("myapp") /// .arg(arg!([length] "Set the length to use as a pos whole num i.e. 20")) /// .get_matches_from(&["test", "12"]); /// @@ -480,8 +480,8 @@ impl ArgMatches { /// # Examples /// /// ``` - /// # use clap::{App, arg}; - /// let matches = App::new("myapp") + /// # use clap::{Command, arg}; + /// let matches = Command::new("myapp") /// .arg(arg!([length] "Set the length to use as a pos whole num i.e. 20")) /// .get_matches_from(&["test", "12"]); /// @@ -523,8 +523,8 @@ impl ArgMatches { /// # Examples /// /// ``` - /// # use clap::{App, arg}; - /// let matches = App::new("myapp") + /// # use clap::{Command, arg}; + /// let matches = Command::new("myapp") /// .arg(arg!([length] ... "A sequence of integers because integers are neat!")) /// .get_matches_from(&["test", "12", "77", "40"]); /// @@ -570,8 +570,8 @@ impl ArgMatches { /// # Examples /// /// ``` - /// # use clap::{App, arg}; - /// let matches = App::new("myapp") + /// # use clap::{Command, arg}; + /// let matches = Command::new("myapp") /// .arg(arg!([length] ... "A sequence of integers because integers are neat!")) /// .get_matches_from(&["test", "12", "77", "40"]); /// @@ -604,8 +604,8 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myprog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myprog") /// .arg(Arg::new("debug") /// .short('d')) /// .get_matches_from(vec![ @@ -638,8 +638,8 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myprog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myprog") /// .arg(Arg::new("debug") /// .short('d')) /// .get_matches_from(vec![ @@ -674,8 +674,8 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myprog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myprog") /// .arg(Arg::new("debug") /// .short('d') /// .multiple_occurrences(true)) @@ -689,8 +689,8 @@ impl ArgMatches { /// This next example shows that counts actual uses of the argument, not just `-`'s /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myprog") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myprog") /// .arg(Arg::new("debug") /// .short('d') /// .multiple_occurrences(true)) @@ -737,8 +737,8 @@ impl ArgMatches { /// in an `ArgMatches` struct for querying. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myapp") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myapp") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("option") @@ -755,8 +755,8 @@ impl ArgMatches { /// Now notice, if we use one of the other styles of options: /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myapp") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myapp") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("option") @@ -774,8 +774,8 @@ impl ArgMatches { /// flags. Let's also throw in the final option style for good measure. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myapp") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myapp") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("flag2") @@ -800,8 +800,8 @@ impl ArgMatches { /// One final combination of flags/options to see how they combine: /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myapp") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myapp") /// .arg(Arg::new("flag") /// .short('f')) /// .arg(Arg::new("flag2") @@ -826,8 +826,8 @@ impl ArgMatches { /// The last part to mention is when values are sent in multiple groups with a [delimiter]. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myapp") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myapp") /// .arg(Arg::new("option") /// .short('o') /// .use_value_delimiter(true) @@ -867,8 +867,8 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myapp") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myapp") /// .arg(Arg::new("option") /// .short('o') /// .use_value_delimiter(true) @@ -885,8 +885,8 @@ impl ArgMatches { /// Another quick example is when flags and options are used together /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myapp") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myapp") /// .arg(Arg::new("option") /// .short('o') /// .takes_value(true) @@ -908,8 +908,8 @@ impl ArgMatches { /// index. /// /// ```rust - /// # use clap::{App, Arg}; - /// let m = App::new("myapp") + /// # use clap::{Command, Arg}; + /// let m = Command::new("myapp") /// .arg(Arg::new("option") /// .short('o') /// .takes_value(true) @@ -942,11 +942,11 @@ impl ArgMatches { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg, }; - /// let app_m = App::new("git") - /// .subcommand(App::new("clone")) - /// .subcommand(App::new("push")) - /// .subcommand(App::new("commit")) + /// # use clap::{Command, Arg, }; + /// let app_m = Command::new("git") + /// .subcommand(Command::new("clone")) + /// .subcommand(Command::new("push")) + /// .subcommand(Command::new("commit")) /// .get_matches(); /// /// match app_m.subcommand() { @@ -962,9 +962,9 @@ impl ArgMatches { /// with pattern matching! /// /// ```rust - /// # use clap::App; + /// # use clap::Command; /// // Assume there is an external subcommand named "subcmd" - /// let app_m = App::new("myprog") + /// let app_m = Command::new("myprog") /// .allow_external_subcommands(true) /// .get_matches_from(vec![ /// "myprog", "subcmd", "--option", "value", "-fff", "--flag" @@ -981,7 +981,7 @@ impl ArgMatches { /// _ => {}, /// } /// ``` - /// [subcommand]: crate::App::subcommand + /// [subcommand]: crate::Command::subcommand #[inline] pub fn subcommand(&self) -> Option<(&str, &ArgMatches)> { self.subcommand.as_ref().map(|sc| (&*sc.name, &sc.matches)) @@ -1000,11 +1000,11 @@ impl ArgMatches { /// # Examples /// /// ```rust - /// # use clap::{App, Arg, }; - /// let app_m = App::new("myprog") + /// # use clap::{Command, Arg, }; + /// let app_m = Command::new("myprog") /// .arg(Arg::new("debug") /// .short('d')) - /// .subcommand(App::new("test") + /// .subcommand(Command::new("test") /// .arg(Arg::new("opt") /// .long("option") /// .takes_value(true))) @@ -1022,8 +1022,8 @@ impl ArgMatches { /// } /// ``` /// - /// [subcommand]: crate::App::subcommand - /// [`App`]: crate::App + /// [subcommand]: crate::Command::subcommand + /// [`Command`]: crate::Command pub fn subcommand_matches(&self, id: T) -> Option<&ArgMatches> { self.get_subcommand(&id.into()).map(|sc| &sc.matches) } @@ -1035,11 +1035,11 @@ impl ArgMatches { /// # Examples /// /// ```no_run - /// # use clap::{App, Arg, }; - /// let app_m = App::new("git") - /// .subcommand(App::new("clone")) - /// .subcommand(App::new("push")) - /// .subcommand(App::new("commit")) + /// # use clap::{Command, Arg, }; + /// let app_m = Command::new("git") + /// .subcommand(Command::new("clone")) + /// .subcommand(Command::new("push")) + /// .subcommand(Command::new("commit")) /// .get_matches(); /// /// match app_m.subcommand_name() { @@ -1049,8 +1049,8 @@ impl ArgMatches { /// _ => {}, // Either no subcommand or one not tested for... /// } /// ``` - /// [subcommand]: crate::App::subcommand - /// [`App`]: crate::App + /// [subcommand]: crate::Command::subcommand + /// [`Command`]: crate::Command #[inline] pub fn subcommand_name(&self) -> Option<&str> { self.subcommand.as_ref().map(|sc| &*sc.name) @@ -1167,8 +1167,8 @@ pub(crate) struct SubCommand { /// # Examples /// /// ```rust -/// # use clap::{App, Arg}; -/// let m = App::new("myapp") +/// # use clap::{Command, Arg}; +/// let m = Command::new("myapp") /// .arg(Arg::new("output") /// .short('o') /// .multiple_occurrences(true) @@ -1264,11 +1264,11 @@ impl<'a> Default for GroupedValues<'a> { /// #[cfg_attr(not(unix), doc = " ```ignore")] #[cfg_attr(unix, doc = " ```")] -/// # use clap::{App, arg}; +/// # use clap::{Command, arg}; /// use std::ffi::OsString; /// use std::os::unix::ffi::{OsStrExt,OsStringExt}; /// -/// let m = App::new("utf8") +/// let m = Command::new("utf8") /// .arg(arg!( "some arg") /// .allow_invalid_utf8(true)) /// .get_matches_from(vec![OsString::from("myprog"), @@ -1320,8 +1320,8 @@ impl Default for OsValues<'_> { /// # Examples /// /// ```rust -/// # use clap::{App, Arg}; -/// let m = App::new("myapp") +/// # use clap::{Command, Arg}; +/// let m = Command::new("myapp") /// .arg(Arg::new("output") /// .short('o') /// .multiple_values(true) @@ -1438,7 +1438,7 @@ mod tests { #[test] fn values_exact_size() { - let l = crate::App::new("test") + let l = crate::Command::new("test") .arg( crate::Arg::new("POTATO") .takes_value(true) @@ -1455,7 +1455,7 @@ mod tests { #[test] fn os_values_exact_size() { - let l = crate::App::new("test") + let l = crate::Command::new("test") .arg( crate::Arg::new("POTATO") .takes_value(true) @@ -1473,7 +1473,7 @@ mod tests { #[test] fn indices_exact_size() { - let l = crate::App::new("test") + let l = crate::Command::new("test") .arg( crate::Arg::new("POTATO") .takes_value(true) diff --git a/src/parse/parser.rs b/src/parse/parser.rs index 980b2615094..9321b2822c5 100644 --- a/src/parse/parser.rs +++ b/src/parse/parser.rs @@ -9,7 +9,7 @@ use os_str_bytes::RawOsStr; // Internal use crate::build::AppSettings as AS; -use crate::build::{App, Arg}; +use crate::build::{Arg, Command}; use crate::error::Error as ClapError; use crate::error::Result as ClapResult; use crate::mkeymap::KeyType; @@ -20,8 +20,8 @@ use crate::parse::{Validator, ValueSource}; use crate::util::{color::ColorChoice, Id}; use crate::{INTERNAL_ERROR_MSG, INVALID_UTF8}; -pub(crate) struct Parser<'help, 'app> { - pub(crate) app: &'app mut App<'help>, +pub(crate) struct Parser<'help, 'cmd> { + pub(crate) cmd: &'cmd mut Command<'help>, pub(crate) overridden: RefCell>, seen: Vec, cur_idx: Cell, @@ -33,10 +33,10 @@ pub(crate) struct Parser<'help, 'app> { } // Initializing Methods -impl<'help, 'app> Parser<'help, 'app> { - pub(crate) fn new(app: &'app mut App<'help>) -> Self { +impl<'help, 'cmd> Parser<'help, 'cmd> { + pub(crate) fn new(cmd: &'cmd mut Command<'help>) -> Self { Parser { - app, + cmd, overridden: Default::default(), seen: Vec::new(), cur_idx: Cell::new(0), @@ -48,16 +48,16 @@ impl<'help, 'app> Parser<'help, 'app> { // Should we color the help? pub(crate) fn color_help(&self) -> ColorChoice { #[cfg(feature = "color")] - if self.app.is_disable_colored_help_set() { + if self.cmd.is_disable_colored_help_set() { return ColorChoice::Never; } - self.app.get_color() + self.cmd.get_color() } } // Parsing Methods -impl<'help, 'app> Parser<'help, 'app> { +impl<'help, 'cmd> Parser<'help, 'cmd> { // The actual parsing function #[allow(clippy::cognitive_complexity)] pub(crate) fn get_matches_with( @@ -80,17 +80,17 @@ impl<'help, 'app> Parser<'help, 'app> { // Count of positional args let positional_count = self - .app + .cmd .get_keymap() .keys() .filter(|x| x.is_position()) .count(); // If any arg sets .last(true) - let contains_last = self.app.get_arguments().any(|x| x.is_last_set()); + let contains_last = self.cmd.get_arguments().any(|x| x.is_last_set()); while let Some((arg_os, remaining_args)) = it.next() { // Recover the replaced items if any. - if let Some(replaced_items) = self.app.get_replacement(arg_os) { + if let Some(replaced_items) = self.cmd.get_replacement(arg_os) { debug!( "Parser::get_matches_with: found replacer: {:?}, target: {:?}", arg_os, replaced_items @@ -114,16 +114,16 @@ impl<'help, 'app> Parser<'help, 'app> { // argument may be set to .multiple_values(true) or `.multiple_occurrences(true)` let low_index_mults = is_second_to_last && self - .app + .cmd .get_positionals() .any(|a| a.is_multiple() && (positional_count != a.index.unwrap_or(0))) && self - .app + .cmd .get_positionals() .last() .map_or(false, |p_name| !p_name.is_last_set()); - let missing_pos = self.app.is_allow_missing_positional_set() + let missing_pos = self.cmd.is_allow_missing_positional_set() && is_second_to_last && !trailing_values; @@ -139,7 +139,7 @@ impl<'help, 'app> Parser<'help, 'app> { if low_index_mults || missing_pos { let skip_current = if let Some(n) = remaining_args.get(0) { if let Some(p) = self - .app + .cmd .get_positionals() .find(|p| p.index == Some(pos_counter)) { @@ -165,7 +165,7 @@ impl<'help, 'app> Parser<'help, 'app> { pos_counter } } else if trailing_values - && (self.app.is_allow_missing_positional_set() || contains_last) + && (self.cmd.is_allow_missing_positional_set() || contains_last) { // Came to -- and one positional has .last(true) set, so we go immediately // to the last (highest index) positional @@ -178,7 +178,7 @@ impl<'help, 'app> Parser<'help, 'app> { // Has the user already passed '--'? Meaning only positional args follow if !trailing_values { - if self.app.is_subcommand_precedence_over_arg_set() + if self.cmd.is_subcommand_precedence_over_arg_set() || !matches!(parse_state, ParseState::Opt(_) | ParseState::Pos(_)) { // Does the arg match a subcommand name, or any of its aliases (if defined) @@ -187,7 +187,7 @@ impl<'help, 'app> Parser<'help, 'app> { if let Some(sc_name) = sc_name { if sc_name == "help" && !self.is_set(AS::NoAutoHelp) - && !self.app.is_disable_help_subcommand_set() + && !self.cmd.is_disable_help_subcommand_set() { self.parse_help_subcommand(remaining_args)?; } @@ -232,9 +232,9 @@ impl<'help, 'app> Parser<'help, 'app> { } ParseResult::EqualsNotProvided { arg } => { return Err(ClapError::no_equals( - self.app, + self.cmd, arg, - Usage::new(self.app).create_usage_with_title(&[]), + Usage::new(self.cmd).create_usage_with_title(&[]), )); } ParseResult::NoMatchingArg { arg } => { @@ -246,10 +246,10 @@ impl<'help, 'app> Parser<'help, 'app> { } ParseResult::UnneededAttachedValue { rest, used, arg } => { return Err(ClapError::too_many_values( - self.app, + self.cmd, rest, arg, - Usage::new(self.app).create_usage_no_title(&used), + Usage::new(self.cmd).create_usage_no_title(&used), )) } ParseResult::HelpFlag => { @@ -321,17 +321,17 @@ impl<'help, 'app> Parser<'help, 'app> { } ParseResult::EqualsNotProvided { arg } => { return Err(ClapError::no_equals( - self.app, + self.cmd, arg, - Usage::new(self.app).create_usage_with_title(&[]), + Usage::new(self.cmd).create_usage_with_title(&[]), )) } ParseResult::NoMatchingArg { arg } => { return Err(ClapError::unknown_argument( - self.app, + self.cmd, arg, None, - Usage::new(self.app).create_usage_with_title(&[]), + Usage::new(self.cmd).create_usage_with_title(&[]), )); } ParseResult::HelpFlag => { @@ -353,7 +353,7 @@ impl<'help, 'app> Parser<'help, 'app> { // get the option so we can check the settings let parse_result = self.add_val_to_arg( - &self.app[id], + &self.cmd[id], &arg_os, matcher, ValueSource::CommandLine, @@ -370,17 +370,17 @@ impl<'help, 'app> Parser<'help, 'app> { } } - if let Some(p) = self.app.get_keymap().get(&pos_counter) { + if let Some(p) = self.cmd.get_keymap().get(&pos_counter) { if p.is_last_set() && !trailing_values { return Err(ClapError::unknown_argument( - self.app, + self.cmd, arg_os.to_str_lossy().into_owned(), None, - Usage::new(self.app).create_usage_with_title(&[]), + Usage::new(self.cmd).create_usage_with_title(&[]), )); } - if self.app.is_trailing_var_arg_set() && pos_counter == positional_count { + if self.cmd.is_trailing_var_arg_set() && pos_counter == positional_count { trailing_values = true; } @@ -410,29 +410,29 @@ impl<'help, 'app> Parser<'help, 'app> { parse_state = ParseState::Pos(p.id.clone()); } valid_arg_found = true; - } else if self.app.is_allow_external_subcommands_set() { + } else if self.cmd.is_allow_external_subcommands_set() { // Get external subcommand name let sc_name = match arg_os.to_str() { Some(s) => s.to_string(), None => { return Err(ClapError::invalid_utf8( - self.app, - Usage::new(self.app).create_usage_with_title(&[]), + self.cmd, + Usage::new(self.cmd).create_usage_with_title(&[]), )); } }; // Collect the external subcommand args - let mut sc_m = ArgMatcher::new(self.app); + let mut sc_m = ArgMatcher::new(self.cmd); while let Some((v, _)) = it.next() { let allow_invalid_utf8 = self - .app + .cmd .is_allow_invalid_utf8_for_external_subcommands_set(); if !allow_invalid_utf8 && v.to_str().is_none() { return Err(ClapError::invalid_utf8( - self.app, - Usage::new(self.app).create_usage_with_title(&[]), + self.cmd, + Usage::new(self.cmd).create_usage_with_title(&[]), )); } sc_m.add_val_to( @@ -461,7 +461,7 @@ impl<'help, 'app> Parser<'help, 'app> { if let Some(ref pos_sc_name) = subcmd_name { let sc_name = self - .app + .cmd .find_subcommand(pos_sc_name) .expect(INTERNAL_ERROR_MSG) .get_name() @@ -483,14 +483,14 @@ impl<'help, 'app> Parser<'help, 'app> { // If the arg matches a subcommand name, or any of its aliases (if defined) if self.possible_subcommand(arg_os, valid_arg_found).is_some() { return ClapError::unnecessary_double_dash( - self.app, + self.cmd, arg_os.to_str_lossy().into_owned(), - Usage::new(self.app).create_usage_with_title(&[]), + Usage::new(self.cmd).create_usage_with_title(&[]), ); } } let candidates = - suggestions::did_you_mean(&arg_os.to_str_lossy(), self.app.all_subcommand_names()); + suggestions::did_you_mean(&arg_os.to_str_lossy(), self.cmd.all_subcommand_names()); // If the argument looks like a subcommand. if !candidates.is_empty() { let candidates: Vec<_> = candidates @@ -498,33 +498,33 @@ impl<'help, 'app> Parser<'help, 'app> { .map(|candidate| format!("'{}'", candidate)) .collect(); return ClapError::invalid_subcommand( - self.app, + self.cmd, arg_os.to_str_lossy().into_owned(), candidates.join(" or "), - self.app + self.cmd .get_bin_name() - .unwrap_or_else(|| self.app.get_name()) + .unwrap_or_else(|| self.cmd.get_name()) .to_owned(), - Usage::new(self.app).create_usage_with_title(&[]), + Usage::new(self.cmd).create_usage_with_title(&[]), ); } // If the argument must be a subcommand. - if !self.app.has_args() || self.app.is_infer_subcommands_set() && self.app.has_subcommands() + if !self.cmd.has_args() || self.cmd.is_infer_subcommands_set() && self.cmd.has_subcommands() { return ClapError::unrecognized_subcommand( - self.app, + self.cmd, arg_os.to_str_lossy().into_owned(), - self.app + self.cmd .get_bin_name() - .unwrap_or_else(|| self.app.get_name()) + .unwrap_or_else(|| self.cmd.get_name()) .to_owned(), ); } ClapError::unknown_argument( - self.app, + self.cmd, arg_os.to_str_lossy().into_owned(), None, - Usage::new(self.app).create_usage_with_title(&[]), + Usage::new(self.cmd).create_usage_with_title(&[]), ) } @@ -532,12 +532,12 @@ impl<'help, 'app> Parser<'help, 'app> { fn possible_subcommand(&self, arg_os: &RawOsStr, valid_arg_found: bool) -> Option<&str> { debug!("Parser::possible_subcommand: arg={:?}", arg_os); - if !(self.app.is_args_conflicts_with_subcommands_set() && valid_arg_found) { - if self.app.is_infer_subcommands_set() { + if !(self.cmd.is_args_conflicts_with_subcommands_set() && valid_arg_found) { + if self.cmd.is_infer_subcommands_set() { // For subcommand `test`, we accepts it's prefix: `t`, `te`, // `tes` and `test`. let v = self - .app + .cmd .all_subcommand_names() .filter(|s| RawOsStr::from_str(s).starts_with_os(arg_os)) .collect::>(); @@ -549,7 +549,7 @@ impl<'help, 'app> Parser<'help, 'app> { // If there is any ambiguity, fallback to non-infer subcommand // search. } - if let Some(sc) = self.app.find_subcommand(arg_os) { + if let Some(sc) = self.cmd.find_subcommand(arg_os) { return Some(sc.get_name()); } } @@ -559,9 +559,9 @@ impl<'help, 'app> Parser<'help, 'app> { // Checks if the arg matches a long flag subcommand name, or any of its aliases (if defined) fn possible_long_flag_subcommand(&self, arg_os: &RawOsStr) -> Option<&str> { debug!("Parser::possible_long_flag_subcommand: arg={:?}", arg_os); - if self.app.is_infer_subcommands_set() { + if self.cmd.is_infer_subcommands_set() { let options = self - .app + .cmd .get_subcommands() .fold(Vec::new(), |mut options, sc| { if let Some(long) = sc.get_long_flag() { @@ -584,7 +584,7 @@ impl<'help, 'app> Parser<'help, 'app> { return Some(sc); } } - } else if let Some(sc_name) = self.app.find_long_subcmd(arg_os) { + } else if let Some(sc_name) = self.cmd.find_long_subcmd(arg_os) { return Some(sc_name); } None @@ -594,13 +594,13 @@ impl<'help, 'app> Parser<'help, 'app> { debug!("Parser::parse_help_subcommand"); let mut bin_name = self - .app + .cmd .get_bin_name() - .unwrap_or_else(|| self.app.get_name()) + .unwrap_or_else(|| self.cmd.get_name()) .to_owned(); let mut sc = { - let mut sc = self.app.clone(); + let mut sc = self.cmd.clone(); for cmd in cmds.iter() { sc = if let Some(c) = sc.find_subcommand(cmd) { @@ -609,11 +609,11 @@ impl<'help, 'app> Parser<'help, 'app> { c } else { return Err(ClapError::unrecognized_subcommand( - self.app, + self.cmd, cmd.to_string_lossy().into_owned(), - self.app + self.cmd .get_bin_name() - .unwrap_or_else(|| self.app.get_name()) + .unwrap_or_else(|| self.cmd.get_name()) .to_owned(), )); } @@ -639,9 +639,9 @@ impl<'help, 'app> Parser<'help, 'app> { next, current_positional.name ); - if self.app.is_allow_hyphen_values_set() - || self.app[¤t_positional.id].is_allow_hyphen_values_set() - || (self.app.is_allow_negative_numbers_set() + if self.cmd.is_allow_hyphen_values_set() + || self.cmd[¤t_positional.id].is_allow_hyphen_values_set() + || (self.cmd.is_allow_negative_numbers_set() && next.to_str_lossy().parse::().is_ok()) { // If allow hyphen, this isn't a new arg. @@ -672,9 +672,9 @@ impl<'help, 'app> Parser<'help, 'app> { ) -> ClapResult<()> { debug!("Parser::parse_subcommand"); - let partial_parsing_enabled = self.app.is_ignore_errors_set(); + let partial_parsing_enabled = self.cmd.is_ignore_errors_set(); - if let Some(sc) = self.app._build_subcommand(sc_name) { + if let Some(sc) = self.cmd._build_subcommand(sc_name) { let mut sc_matcher = ArgMatcher::new(sc); debug!( @@ -720,9 +720,9 @@ impl<'help, 'app> Parser<'help, 'app> { arg ); - if let Some(help) = self.app.find(&Id::help_hash()) { + if let Some(help) = self.cmd.find(&Id::help_hash()) { if let Some(h) = help.long { - if arg == h && !self.is_set(AS::NoAutoHelp) && !self.app.is_disable_help_flag_set() + if arg == h && !self.is_set(AS::NoAutoHelp) && !self.cmd.is_disable_help_flag_set() { debug!("Help"); return Some(ParseResult::HelpFlag); @@ -730,11 +730,11 @@ impl<'help, 'app> Parser<'help, 'app> { } } - if let Some(version) = self.app.find(&Id::version_hash()) { + if let Some(version) = self.cmd.find(&Id::version_hash()) { if let Some(v) = version.long { if arg == v && !self.is_set(AS::NoAutoVersion) - && !self.app.is_disable_version_flag_set() + && !self.cmd.is_disable_version_flag_set() { debug!("Version"); return Some(ParseResult::VersionFlag); @@ -753,9 +753,9 @@ impl<'help, 'app> Parser<'help, 'app> { arg ); - if let Some(help) = self.app.find(&Id::help_hash()) { + if let Some(help) = self.cmd.find(&Id::help_hash()) { if let Some(h) = help.short { - if arg == h && !self.is_set(AS::NoAutoHelp) && !self.app.is_disable_help_flag_set() + if arg == h && !self.is_set(AS::NoAutoHelp) && !self.cmd.is_disable_help_flag_set() { debug!("Help"); return Some(ParseResult::HelpFlag); @@ -763,11 +763,11 @@ impl<'help, 'app> Parser<'help, 'app> { } } - if let Some(version) = self.app.find(&Id::version_hash()) { + if let Some(version) = self.cmd.find(&Id::version_hash()) { if let Some(v) = version.short { if arg == v && !self.is_set(AS::NoAutoVersion) - && !self.app.is_disable_version_flag_set() + && !self.cmd.is_disable_version_flag_set() { debug!("Version"); return Some(ParseResult::VersionFlag); @@ -791,10 +791,10 @@ impl<'help, 'app> Parser<'help, 'app> { // Subcommands aren't checked because we prefer short help for them, deferring to // `cmd subcmd --help` for more. - self.app.get_long_about().is_some() - || self.app.get_before_long_help().is_some() - || self.app.get_after_long_help().is_some() - || self.app.get_arguments().any(should_long) + self.cmd.get_long_about().is_some() + || self.cmd.get_before_long_help().is_some() + || self.cmd.get_after_long_help().is_some() + || self.cmd.get_arguments().any(should_long) } fn parse_long_arg( @@ -809,7 +809,7 @@ impl<'help, 'app> Parser<'help, 'app> { debug!("Parser::parse_long_arg"); if matches!(parse_state, ParseState::Opt(opt) | ParseState::Pos(opt) if - self.app[opt].is_allow_hyphen_values_set()) + self.cmd[opt].is_allow_hyphen_values_set()) { return ParseResult::MaybeHyphenValue; } @@ -831,15 +831,15 @@ impl<'help, 'app> Parser<'help, 'app> { (long_arg, None) }; - let opt = if let Some(opt) = self.app.get_keymap().get(&*arg.to_os_str()) { + let opt = if let Some(opt) = self.cmd.get_keymap().get(&*arg.to_os_str()) { debug!( "Parser::parse_long_arg: Found valid opt or flag '{}'", opt.to_string() ); Some(opt) - } else if self.app.is_infer_long_args_set() { + } else if self.cmd.is_infer_long_args_set() { let arg_str = arg.to_str_lossy(); - self.app.get_arguments().find(|a| { + self.cmd.get_arguments().find(|a| { a.long.map_or(false, |long| long.starts_with(&*arg_str)) || a.aliases .iter() @@ -859,12 +859,12 @@ impl<'help, 'app> Parser<'help, 'app> { ); self.parse_opt(val, opt, matcher, trailing_values) } else if let Some(rest) = val { - let required = self.app.required_graph(); + let required = self.cmd.required_graph(); debug!("Parser::parse_long_arg: Got invalid literal `{:?}`", rest); let used: Vec = matcher .arg_names() .filter(|&n| { - self.app + self.cmd .find(n) .map_or(true, |a| !(a.is_hide_set() || required.contains(&a.id))) }) @@ -884,7 +884,7 @@ impl<'help, 'app> Parser<'help, 'app> { } } else if let Some(sc_name) = self.possible_long_flag_subcommand(arg) { ParseResult::FlagSubCommand(sc_name.to_string()) - } else if self.app.is_allow_hyphen_values_set() { + } else if self.cmd.is_allow_hyphen_values_set() { ParseResult::MaybeHyphenValue } else { ParseResult::NoMatchingArg { @@ -907,21 +907,21 @@ impl<'help, 'app> Parser<'help, 'app> { let arg = short_arg.to_str_lossy(); #[allow(clippy::blocks_in_if_conditions)] - if self.app.is_allow_negative_numbers_set() && arg.parse::().is_ok() { + if self.cmd.is_allow_negative_numbers_set() && arg.parse::().is_ok() { debug!("Parser::parse_short_arg: negative number"); return ParseResult::MaybeHyphenValue; - } else if self.app.is_allow_hyphen_values_set() - && arg.chars().any(|c| !self.app.contains_short(c)) + } else if self.cmd.is_allow_hyphen_values_set() + && arg.chars().any(|c| !self.cmd.contains_short(c)) { debug!("Parser::parse_short_args: contains non-short flag"); return ParseResult::MaybeHyphenValue; } else if matches!(parse_state, ParseState::Opt(opt) | ParseState::Pos(opt) - if self.app[opt].is_allow_hyphen_values_set()) + if self.cmd[opt].is_allow_hyphen_values_set()) { debug!("Parser::parse_short_args: prior arg accepts hyphenated values",); return ParseResult::MaybeHyphenValue; } else if self - .app + .cmd .get_keymap() .get(&pos_counter) .map_or(false, |arg| { @@ -954,7 +954,7 @@ impl<'help, 'app> Parser<'help, 'app> { // concatenated value: -oval // Option: -o // Value: val - if let Some(opt) = self.app.get_keymap().get(&c) { + if let Some(opt) = self.cmd.get_keymap().get(&c) { debug!( "Parser::parse_short_arg:iter:{}: Found valid opt or flag", c @@ -990,7 +990,7 @@ impl<'help, 'app> Parser<'help, 'app> { } } - return if let Some(sc_name) = self.app.find_short_subcmd(c) { + return if let Some(sc_name) = self.cmd.find_short_subcmd(c) { debug!("Parser::parse_short_arg:iter:{}: subcommand={}", c, sc_name); let name = sc_name.to_string(); let done_short_args = { @@ -1082,7 +1082,7 @@ impl<'help, 'app> Parser<'help, 'app> { debug!("Parser::parse_opt: More arg vals required..."); self.inc_occurrence_of_arg(matcher, opt); matcher.new_val_group(&opt.id); - for group in self.app.groups_for_arg(&opt.id) { + for group in self.cmd.groups_for_arg(&opt.id) { matcher.new_val_group(&group); } ParseResult::Opt(opt.id.clone()) @@ -1102,9 +1102,9 @@ impl<'help, 'app> Parser<'help, 'app> { debug!( "Parser::add_val_to_arg; trailing_values={:?}, DontDelimTrailingVals={:?}", trailing_values, - self.app.is_dont_delimit_trailing_values_set() + self.cmd.is_dont_delimit_trailing_values_set() ); - if !(trailing_values && self.app.is_dont_delimit_trailing_values_set()) { + if !(trailing_values && self.cmd.is_dont_delimit_trailing_values_set()) { if let Some(delim) = arg.val_delim { let terminator = arg.terminator.map(OsStr::new); let vals = val @@ -1149,7 +1149,7 @@ impl<'help, 'app> Parser<'help, 'app> { // If not appending, create a new val group and then append vals in. if !append { matcher.new_val_group(&arg.id); - for group in self.app.groups_for_arg(&arg.id) { + for group in self.cmd.groups_for_arg(&arg.id) { matcher.new_val_group(&group); } } @@ -1176,7 +1176,7 @@ impl<'help, 'app> Parser<'help, 'app> { ); // Increment or create the group "args" - for group in self.app.groups_for_arg(&arg.id) { + for group in self.cmd.groups_for_arg(&arg.id) { matcher.add_val_to(&group, val.clone(), ty, append); } @@ -1208,7 +1208,7 @@ impl<'help, 'app> Parser<'help, 'app> { // Override anything that can override us let mut transitive = Vec::new(); for arg_id in matcher.arg_names() { - if let Some(overrider) = self.app.find(arg_id) { + if let Some(overrider) = self.cmd.find(arg_id) { if overrider.overrides.contains(&arg.id) { transitive.push(&overrider.id); } @@ -1224,12 +1224,12 @@ impl<'help, 'app> Parser<'help, 'app> { pub(crate) fn add_defaults(&mut self, matcher: &mut ArgMatcher, trailing_values: bool) { debug!("Parser::add_defaults"); - for o in self.app.get_opts() { + for o in self.cmd.get_opts() { debug!("Parser::add_defaults:iter:{}:", o.name); self.add_value(o, matcher, ValueSource::DefaultValue, trailing_values); } - for p in self.app.get_positionals() { + for p in self.cmd.get_positionals() { debug!("Parser::add_defaults:iter:{}:", p.name); self.add_value(p, matcher, ValueSource::DefaultValue, trailing_values); } @@ -1362,7 +1362,7 @@ impl<'help, 'app> Parser<'help, 'app> { ) -> ClapResult<()> { use crate::util::str_to_bool; - self.app.get_arguments().try_for_each(|a| { + self.cmd.get_arguments().try_for_each(|a| { // Use env only if the arg was absent among command line args, // early return if this is not the case. if matcher @@ -1424,14 +1424,14 @@ impl<'help, 'app> Parser<'help, 'app> { matcher.inc_occurrence_of_arg(arg); // Increment or create the group "args" - for group in self.app.groups_for_arg(&arg.id) { + for group in self.cmd.groups_for_arg(&arg.id) { matcher.inc_occurrence_of_group(&group); } } } // Error, Help, and Version Methods -impl<'help, 'app> Parser<'help, 'app> { +impl<'help, 'cmd> Parser<'help, 'cmd> { /// Is only used for the long flag(which is the only one needs fuzzy searching) fn did_you_mean_error( &mut self, @@ -1442,7 +1442,7 @@ impl<'help, 'app> Parser<'help, 'app> { debug!("Parser::did_you_mean_error: arg={}", arg); // Didn't match a flag or option let longs = self - .app + .cmd .get_keymap() .keys() .filter_map(|x| match x { @@ -1456,21 +1456,21 @@ impl<'help, 'app> Parser<'help, 'app> { arg, remaining_args, longs.iter().map(|x| &x[..]), - self.app.get_subcommands_mut(), + self.cmd.get_subcommands_mut(), ); // Add the arg to the matches to build a proper usage string if let Some((name, _)) = did_you_mean.as_ref() { - if let Some(opt) = self.app.get_keymap().get(&name.as_ref()) { + if let Some(opt) = self.cmd.get_keymap().get(&name.as_ref()) { self.inc_occurrence_of_arg(matcher, opt); } } - let required = self.app.required_graph(); + let required = self.cmd.required_graph(); let used: Vec = matcher .arg_names() .filter(|n| { - self.app + self.cmd .find(n) .map_or(true, |a| !(required.contains(&a.id) || a.is_hide_set())) }) @@ -1478,19 +1478,19 @@ impl<'help, 'app> Parser<'help, 'app> { .collect(); ClapError::unknown_argument( - self.app, + self.cmd, format!("--{}", arg), did_you_mean, - Usage::new(self.app) + Usage::new(self.cmd) .required(&required) .create_usage_with_title(&*used), ) } pub(crate) fn write_help_err(&self) -> ClapResult { - let usage = Usage::new(self.app); + let usage = Usage::new(self.cmd); let mut c = Colorizer::new(true, self.color_help()); - Help::new(HelpWriter::Buffer(&mut c), self.app, &usage, false).write_help()?; + Help::new(HelpWriter::Buffer(&mut c), self.cmd, &usage, false).write_help()?; Ok(c) } @@ -1501,29 +1501,29 @@ impl<'help, 'app> Parser<'help, 'app> { ); use_long = use_long && self.use_long_help(); - let usage = Usage::new(self.app); + let usage = Usage::new(self.cmd); let mut c = Colorizer::new(false, self.color_help()); - match Help::new(HelpWriter::Buffer(&mut c), self.app, &usage, use_long).write_help() { + match Help::new(HelpWriter::Buffer(&mut c), self.cmd, &usage, use_long).write_help() { Err(e) => e.into(), - _ => ClapError::display_help(self.app, c), + _ => ClapError::display_help(self.cmd, c), } } fn version_err(&self, use_long: bool) -> ClapError { debug!("Parser::version_err"); - let msg = self.app._render_version(use_long); + let msg = self.cmd._render_version(use_long); let mut c = Colorizer::new(false, self.color_help()); c.none(msg); - ClapError::display_version(self.app, c) + ClapError::display_version(self.cmd, c) } } // Query Methods -impl<'help, 'app> Parser<'help, 'app> { +impl<'help, 'cmd> Parser<'help, 'cmd> { pub(crate) fn is_set(&self, s: AS) -> bool { - self.app.is_set(s) + self.cmd.is_set(s) } } diff --git a/src/parse/validator.rs b/src/parse/validator.rs index 712f6dbbfde..18e1bb7609e 100644 --- a/src/parse/validator.rs +++ b/src/parse/validator.rs @@ -1,5 +1,5 @@ // Internal -use crate::build::{App, AppSettings, Arg, ArgPredicate, PossibleValue}; +use crate::build::{AppSettings, Arg, ArgPredicate, Command, PossibleValue}; use crate::error::{Error, Result as ClapResult}; use crate::output::Usage; use crate::parse::{ArgMatcher, MatchedArg, ParseState, Parser}; @@ -7,14 +7,14 @@ use crate::util::ChildGraph; use crate::util::Id; use crate::{INTERNAL_ERROR_MSG, INVALID_UTF8}; -pub(crate) struct Validator<'help, 'app, 'parser> { - p: &'parser mut Parser<'help, 'app>, +pub(crate) struct Validator<'help, 'cmd, 'parser> { + p: &'parser mut Parser<'help, 'cmd>, required: ChildGraph, } -impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { - pub(crate) fn new(p: &'parser mut Parser<'help, 'app>) -> Self { - let required = p.app.required_graph(); +impl<'help, 'cmd, 'parser> Validator<'help, 'cmd, 'parser> { + pub(crate) fn new(p: &'parser mut Parser<'help, 'cmd>) -> Self { + let required = p.cmd.required_graph(); Validator { p, required } } @@ -35,7 +35,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { if let ParseState::Opt(a) = parse_state { debug!("Validator::validate: needs_val_of={:?}", a); - let o = &self.p.app[&a]; + let o = &self.p.cmd[&a]; let should_err = if let Some(v) = matcher.args.get(&o.id) { v.all_val_groups_empty() && !(o.min_vals.is_some() && o.min_vals.unwrap() == 0) } else { @@ -43,51 +43,51 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { }; if should_err { return Err(Error::empty_value( - self.p.app, + self.p.cmd, &o.possible_vals .iter() .filter_map(PossibleValue::get_visible_name) .collect::>(), o, - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&[]), )); } } - if !has_subcmd && self.p.app.is_arg_required_else_help_set() { + if !has_subcmd && self.p.cmd.is_arg_required_else_help_set() { let num_user_values = matcher .arg_names() .filter(|arg_id| matcher.check_explicit(arg_id, ArgPredicate::IsPresent)) .count(); if num_user_values == 0 { let message = self.p.write_help_err()?; - return Err(Error::display_help_error(self.p.app, message)); + return Err(Error::display_help_error(self.p.cmd, message)); } } #[allow(deprecated)] - if !has_subcmd && self.p.app.is_subcommand_required_set() { + if !has_subcmd && self.p.cmd.is_subcommand_required_set() { let bn = self .p - .app + .cmd .get_bin_name() - .unwrap_or_else(|| self.p.app.get_name()); + .unwrap_or_else(|| self.p.cmd.get_name()); return Err(Error::missing_subcommand( - self.p.app, + self.p.cmd, bn.to_string(), - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&[]), )); - } else if !has_subcmd && self.p.app.is_set(AppSettings::SubcommandRequiredElseHelp) { + } else if !has_subcmd && self.p.cmd.is_set(AppSettings::SubcommandRequiredElseHelp) { debug!("Validator::new::get_matches_with: SubcommandRequiredElseHelp=true"); let message = self.p.write_help_err()?; - return Err(Error::display_help_error(self.p.app, message)); + return Err(Error::display_help_error(self.p.cmd, message)); } self.validate_conflicts(matcher)?; - if !(self.p.app.is_subcommand_negates_reqs_set() && has_subcmd) { + if !(self.p.cmd.is_subcommand_negates_reqs_set() && has_subcmd) { self.validate_required(matcher)?; } self.validate_matched_args(matcher)?; @@ -109,8 +109,8 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { val ); return Err(Error::invalid_utf8( - self.p.app, - Usage::new(self.p.app) + self.p.cmd, + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&[]), )); @@ -130,21 +130,21 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { .arg_names() .filter(|arg_id| matcher.check_explicit(arg_id, ArgPredicate::IsPresent)) .filter(|&n| { - self.p.app.find(n).map_or(true, |a| { + self.p.cmd.find(n).map_or(true, |a| { !(a.is_hide_set() || self.required.contains(&a.id)) }) }) .cloned() .collect(); return Err(Error::invalid_value( - self.p.app, + self.p.cmd, val_str.into_owned(), &arg.possible_vals .iter() .filter_map(PossibleValue::get_visible_name) .collect::>(), arg, - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&used), )); @@ -153,13 +153,13 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { if arg.is_forbid_empty_values_set() && val.is_empty() && matcher.contains(&arg.id) { debug!("Validator::validate_arg_values: illegal empty val found"); return Err(Error::empty_value( - self.p.app, + self.p.cmd, &arg.possible_vals .iter() .filter_map(PossibleValue::get_visible_name) .collect::>(), arg, - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&[]), )); @@ -175,7 +175,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { val.to_string_lossy().into_owned(), e, ) - .with_app(self.p.app)); + .with_cmd(self.p.cmd)); } else { debug!("good"); } @@ -190,7 +190,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { val.to_string_lossy().into(), e, ) - .with_app(self.p.app)); + .with_cmd(self.p.cmd)); } else { debug!("good"); } @@ -208,10 +208,10 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { for arg_id in matcher .arg_names() .filter(|arg_id| matcher.check_explicit(arg_id, ArgPredicate::IsPresent)) - .filter(|arg_id| self.p.app.find(arg_id).is_some()) + .filter(|arg_id| self.p.cmd.find(arg_id).is_some()) { debug!("Validator::validate_conflicts::iter: id={:?}", arg_id); - let conflicts = conflicts.gather_conflicts(self.p.app, matcher, arg_id); + let conflicts = conflicts.gather_conflicts(self.p.cmd, matcher, arg_id); self.build_conflict_err(arg_id, &conflicts, matcher)?; } @@ -227,7 +227,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { .filter_map(|name| { debug!("Validator::validate_exclusive:iter:{:?}", name); self.p - .app + .cmd .find(name) // Find `arg`s which are exclusive but also appear with other args. .filter(|&arg| arg.is_exclusive_set() && args_count > 1) @@ -235,10 +235,10 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { // Throw an error for the first conflict found. .try_for_each(|arg| { Err(Error::argument_conflict( - self.p.app, + self.p.cmd, arg, Vec::new(), - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&[]), )) @@ -260,24 +260,24 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { let conflicts = conflict_ids .iter() .flat_map(|c_id| { - if self.p.app.find_group(c_id).is_some() { - self.p.app.unroll_args_in_group(c_id) + if self.p.cmd.find_group(c_id).is_some() { + self.p.cmd.unroll_args_in_group(c_id) } else { vec![c_id.clone()] } }) .filter_map(|c_id| { seen.insert(c_id.clone()).then(|| { - let c_arg = self.p.app.find(&c_id).expect(INTERNAL_ERROR_MSG); + let c_arg = self.p.cmd.find(&c_id).expect(INTERNAL_ERROR_MSG); c_arg.to_string() }) }) .collect(); - let former_arg = self.p.app.find(name).expect(INTERNAL_ERROR_MSG); + let former_arg = self.p.cmd.find(name).expect(INTERNAL_ERROR_MSG); let usg = self.build_conflict_err_usage(matcher, conflict_ids); Err(Error::argument_conflict( - self.p.app, former_arg, conflicts, usg, + self.p.cmd, former_arg, conflicts, usg, )) } @@ -290,13 +290,13 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { .collect(); let required: Vec = used_filtered .iter() - .filter_map(|key| self.p.app.find(key)) + .filter_map(|key| self.p.cmd.find(key)) .flat_map(|arg| arg.requires.iter().map(|item| &item.1)) .filter(|key| !used_filtered.contains(key) && !conflicting_keys.contains(key)) .chain(used_filtered.iter()) .cloned() .collect(); - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&required) } @@ -308,16 +308,16 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { .filter(|arg_id| matcher.check_explicit(arg_id, ArgPredicate::IsPresent)) { debug!("Validator::gather_requires:iter:{:?}", name); - if let Some(arg) = self.p.app.find(name) { + if let Some(arg) = self.p.cmd.find(name) { let is_relevant = |(val, req_arg): &(ArgPredicate<'_>, Id)| -> Option { let required = matcher.check_explicit(&arg.id, *val); required.then(|| req_arg.clone()) }; - for req in self.p.app.unroll_arg_requires(is_relevant, &arg.id) { + for req in self.p.cmd.unroll_arg_requires(is_relevant, &arg.id) { self.required.insert(req); } - } else if let Some(g) = self.p.app.find_group(name) { + } else if let Some(g) = self.p.cmd.find_group(name) { debug!("Validator::gather_requires:iter:{:?}:group", name); for r in &g.requires { self.required.insert(r.clone()); @@ -334,7 +334,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { name, ma.vals_flatten() ); - if let Some(arg) = self.p.app.find(name) { + if let Some(arg) = self.p.cmd.find(name) { self.validate_arg_num_vals(arg, ma)?; self.validate_arg_values(arg, ma, matcher)?; self.validate_arg_num_occurs(arg, ma)?; @@ -354,9 +354,9 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { if ma.get_occurrences() > 1 && !a.is_multiple_occurrences_set() && !a.is_positional() { // Not the first time, and we don't allow multiples return Err(Error::unexpected_multiple_usage( - self.p.app, + self.p.cmd, a, - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&[]), )); @@ -369,11 +369,11 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { let occurs = ma.get_occurrences() as usize; if occurs > max_occurs { return Err(Error::too_many_occurrences( - self.p.app, + self.p.cmd, a, max_occurs, occurs, - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&[]), )); @@ -396,7 +396,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { if should_err { debug!("Validator::validate_arg_num_vals: Sending error WrongNumberOfValues"); return Err(Error::wrong_number_of_values( - self.p.app, + self.p.cmd, a, num, if a.is_multiple_occurrences_set() { @@ -404,7 +404,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { } else { total_num }, - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&[]), )); @@ -415,7 +415,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { if ma.num_vals() > num { debug!("Validator::validate_arg_num_vals: Sending error TooManyValues"); return Err(Error::too_many_values( - self.p.app, + self.p.cmd, ma.vals_flatten() .last() .expect(INTERNAL_ERROR_MSG) @@ -423,7 +423,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { .expect(INVALID_UTF8) .to_string(), a.to_string(), - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&[]), )); @@ -434,11 +434,11 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { if ma.num_vals() < num && num != 0 { debug!("Validator::validate_arg_num_vals: Sending error TooFewValues"); return Err(Error::too_few_values( - self.p.app, + self.p.cmd, a, num, ma.num_vals(), - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&[]), )); @@ -451,13 +451,13 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { // Issue 1105 (https://github.com/clap-rs/clap/issues/1105) if a.is_takes_value_set() && !min_vals_zero && ma.all_val_groups_empty() { return Err(Error::empty_value( - self.p.app, + self.p.cmd, &a.possible_vals .iter() .filter_map(PossibleValue::get_visible_name) .collect::>(), a, - Usage::new(self.p.app) + Usage::new(self.p.cmd) .required(&self.required) .create_usage_with_title(&[]), )); @@ -471,16 +471,16 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { for arg_or_group in self.required.iter().filter(|r| !matcher.contains(r)) { debug!("Validator::validate_required:iter:aog={:?}", arg_or_group); - if let Some(arg) = self.p.app.find(arg_or_group) { + if let Some(arg) = self.p.cmd.find(arg_or_group) { debug!("Validator::validate_required:iter: This is an arg"); if !self.is_missing_required_ok(arg, matcher) { return self.missing_required_error(matcher, vec![]); } - } else if let Some(group) = self.p.app.find_group(arg_or_group) { + } else if let Some(group) = self.p.cmd.find_group(arg_or_group) { debug!("Validator::validate_required:iter: This is a group"); if !self .p - .app + .cmd .unroll_args_in_group(&group.id) .iter() .any(|a| matcher.contains(a)) @@ -491,7 +491,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { } // Validate the conditionally required args - for a in self.p.app.get_arguments() { + for a in self.p.cmd.get_arguments() { for (other, val) in &a.r_ifs { if matcher.check_explicit(other, ArgPredicate::Equals(std::ffi::OsStr::new(*val))) && !matcher.contains(&a.id) @@ -524,7 +524,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { matcher.contains(conf) || self .p - .app + .cmd .find_group(conf) .map_or(false, |g| g.args.iter().any(|arg| matcher.contains(arg))) }) @@ -534,7 +534,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { debug!("Validator::validate_required_unless"); let failed_args: Vec<_> = self .p - .app + .cmd .get_arguments() .filter(|&a| { (!a.r_unless.is_empty() || !a.r_unless_all.is_empty()) @@ -567,7 +567,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { self.required ); - let usg = Usage::new(self.p.app).required(&self.required); + let usg = Usage::new(self.p.cmd).required(&self.required); let req_args = usg.get_required_usage_from(&incl, Some(matcher), true); @@ -582,7 +582,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { .filter(|n| { // Filter out the args we don't want to specify. self.p - .app + .cmd .find(n) .map_or(true, |a| !a.is_hide_set() && !self.required.contains(&a.id)) }) @@ -591,7 +591,7 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> { .collect(); Err(Error::missing_required_argument( - self.p.app, + self.p.cmd, req_args, usg.create_usage_with_title(&used), )) @@ -608,7 +608,7 @@ impl Conflicts { Self::default() } - fn gather_conflicts(&mut self, app: &App, matcher: &ArgMatcher, arg_id: &Id) -> Vec { + fn gather_conflicts(&mut self, cmd: &Command, matcher: &ArgMatcher, arg_id: &Id) -> Vec { debug!("Conflicts::gather_conflicts"); let mut conflicts = Vec::new(); for other_arg_id in matcher @@ -620,13 +620,13 @@ impl Conflicts { } if self - .gather_direct_conflicts(app, arg_id) + .gather_direct_conflicts(cmd, arg_id) .contains(other_arg_id) { conflicts.push(other_arg_id.clone()); } if self - .gather_direct_conflicts(app, other_arg_id) + .gather_direct_conflicts(cmd, other_arg_id) .contains(arg_id) { conflicts.push(other_arg_id.clone()); @@ -635,12 +635,12 @@ impl Conflicts { conflicts } - fn gather_direct_conflicts(&mut self, app: &App, arg_id: &Id) -> &[Id] { + fn gather_direct_conflicts(&mut self, cmd: &Command, arg_id: &Id) -> &[Id] { self.potential.entry(arg_id.clone()).or_insert_with(|| { - let conf = if let Some(arg) = app.find(arg_id) { + let conf = if let Some(arg) = cmd.find(arg_id) { let mut conf = arg.blacklist.clone(); - for group_id in app.groups_for_arg(arg_id) { - let group = app.find_group(&group_id).expect(INTERNAL_ERROR_MSG); + for group_id in cmd.groups_for_arg(arg_id) { + let group = cmd.find_group(&group_id).expect(INTERNAL_ERROR_MSG); conf.extend(group.conflicts.iter().cloned()); if !group.multiple { for member_id in &group.args { @@ -651,7 +651,7 @@ impl Conflicts { } } conf - } else if let Some(group) = app.find_group(arg_id) { + } else if let Some(group) = cmd.find_group(arg_id) { group.conflicts.clone() } else { debug_assert!(false, "id={:?} is unknown", arg_id); diff --git a/src/util/color.rs b/src/util/color.rs index 272a6c91688..15c9901a079 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -13,8 +13,8 @@ pub enum ColorChoice { /// #[cfg_attr(not(feature = "color"), doc = " ```ignore")] #[cfg_attr(feature = "color", doc = " ```no_run")] - /// # use clap::{App, ColorChoice}; - /// App::new("myprog") + /// # use clap::{Command, ColorChoice}; + /// Command::new("myprog") /// .color(ColorChoice::Auto) /// .get_matches(); /// ``` @@ -30,8 +30,8 @@ pub enum ColorChoice { /// #[cfg_attr(not(feature = "color"), doc = " ```ignore")] #[cfg_attr(feature = "color", doc = " ```no_run")] - /// # use clap::{App, ColorChoice}; - /// App::new("myprog") + /// # use clap::{Command, ColorChoice}; + /// Command::new("myprog") /// .color(ColorChoice::Always) /// .get_matches(); /// ``` @@ -47,8 +47,8 @@ pub enum ColorChoice { /// #[cfg_attr(not(feature = "color"), doc = " ```ignore")] #[cfg_attr(feature = "color", doc = " ```no_run")] - /// # use clap::{App, ColorChoice}; - /// App::new("myprog") + /// # use clap::{Command, ColorChoice}; + /// Command::new("myprog") /// .color(ColorChoice::Never) /// .get_matches(); /// ``` diff --git a/tests/builder/app_settings.rs b/tests/builder/app_settings.rs index d7252cf1749..c48c9590944 100644 --- a/tests/builder/app_settings.rs +++ b/tests/builder/app_settings.rs @@ -1,6 +1,6 @@ use crate::utils; -use clap::{arg, error::ErrorKind, App, AppSettings, Arg}; +use clap::{arg, error::ErrorKind, AppSettings, Arg, Command}; static ALLOW_EXT_SC: &str = "clap-test v1.4.8 @@ -82,21 +82,21 @@ SUBCOMMANDS: #[test] fn setting() { #![allow(deprecated)] - let m = App::new("setting").args_override_self(true); + let m = Command::new("setting").args_override_self(true); assert!(m.is_set(AppSettings::AllArgsOverrideSelf)); } #[test] fn global_setting() { #![allow(deprecated)] - let m = App::new("global_setting").args_override_self(true); + let m = Command::new("global_setting").args_override_self(true); assert!(m.is_set(AppSettings::AllArgsOverrideSelf)); } #[test] fn unset_setting() { #![allow(deprecated)] - let m = App::new("unset_setting").args_override_self(true); + let m = Command::new("unset_setting").args_override_self(true); assert!(m.is_set(AppSettings::AllArgsOverrideSelf)); let m = m.args_override_self(false); @@ -106,7 +106,7 @@ fn unset_setting() { #[test] fn unset_global_setting() { #![allow(deprecated)] - let m = App::new("unset_global_setting").args_override_self(true); + let m = Command::new("unset_global_setting").args_override_self(true); assert!(m.is_set(AppSettings::AllArgsOverrideSelf)); let m = m.args_override_self(false); @@ -116,7 +116,7 @@ fn unset_global_setting() { #[test] fn setting_bitor() { #![allow(deprecated)] - let m = App::new("setting_bitor").setting( + let m = Command::new("setting_bitor").setting( AppSettings::InferSubcommands | AppSettings::Hidden | AppSettings::DisableHelpSubcommand, ); @@ -128,7 +128,7 @@ fn setting_bitor() { #[test] fn unset_setting_bitor() { #![allow(deprecated)] - let m = App::new("unset_setting_bitor") + let m = Command::new("unset_setting_bitor") .setting(AppSettings::InferSubcommands) .setting(AppSettings::Hidden) .setting(AppSettings::DisableHelpSubcommand); @@ -147,20 +147,20 @@ fn unset_setting_bitor() { #[test] fn sub_command_negate_required() { - App::new("sub_command_negate") + Command::new("sub_command_negate") .subcommand_negates_reqs(true) .arg(Arg::new("test").required(true).index(1)) - .subcommand(App::new("sub1")) + .subcommand(Command::new("sub1")) .try_get_matches_from(vec!["myprog", "sub1"]) .unwrap(); } #[test] fn sub_command_negate_required_2() { - let result = App::new("sub_command_negate") + let result = Command::new("sub_command_negate") .subcommand_negates_reqs(true) .arg(Arg::new("test").required(true).index(1)) - .subcommand(App::new("sub1")) + .subcommand(Command::new("sub1")) .try_get_matches_from(vec![""]); assert!(result.is_err()); let err = result.err().unwrap(); @@ -169,9 +169,9 @@ fn sub_command_negate_required_2() { #[test] fn sub_command_required() { - let result = App::new("sc_required") + let result = Command::new("sc_required") .subcommand_required(true) - .subcommand(App::new("sub1")) + .subcommand(Command::new("sub1")) .try_get_matches_from(vec![""]); assert!(result.is_err()); let err = result.err().unwrap(); @@ -180,7 +180,7 @@ fn sub_command_required() { #[test] fn arg_required_else_help() { - let result = App::new("arg_required") + let result = Command::new("arg_required") .arg_required_else_help(true) .arg(Arg::new("test").index(1)) .try_get_matches_from(vec![""]); @@ -195,7 +195,7 @@ fn arg_required_else_help() { #[test] fn arg_required_else_help_over_req_arg() { - let result = App::new("arg_required") + let result = Command::new("arg_required") .arg_required_else_help(true) .arg(Arg::new("test").index(1).required(true)) .try_get_matches_from(vec![""]); @@ -210,10 +210,10 @@ fn arg_required_else_help_over_req_arg() { #[test] fn arg_required_else_help_over_req_subcommand() { - let result = App::new("sub_required") + let result = Command::new("sub_required") .arg_required_else_help(true) .subcommand_required(true) - .subcommand(App::new("sub1")) + .subcommand(Command::new("sub1")) .try_get_matches_from(vec![""]); assert!(result.is_err()); @@ -226,7 +226,7 @@ fn arg_required_else_help_over_req_subcommand() { #[test] fn arg_required_else_help_with_default() { - let result = App::new("arg_required") + let result = Command::new("arg_required") .arg_required_else_help(true) .arg(arg!(--input ).required(false).default_value("-")) .try_get_matches_from(vec![""]); @@ -241,7 +241,7 @@ fn arg_required_else_help_with_default() { #[test] fn arg_required_else_help_error_message() { - let app = App::new("test") + let cmd = Command::new("test") .arg_required_else_help(true) .version("1.0") .arg( @@ -251,7 +251,7 @@ fn arg_required_else_help_error_message() { .long("info"), ); assert!(utils::compare_output( - app, + cmd, "test", ARG_REQUIRED_ELSE_HELP, true // Unlike normal displaying of help, we should provide a fatal exit code @@ -261,9 +261,9 @@ fn arg_required_else_help_error_message() { #[test] fn subcommand_required_else_help() { #![allow(deprecated)] - let result = App::new("test") + let result = Command::new("test") .setting(AppSettings::SubcommandRequiredElseHelp) - .subcommand(App::new("info")) + .subcommand(Command::new("info")) .try_get_matches_from(&[""]); assert!(result.is_err()); @@ -277,12 +277,12 @@ fn subcommand_required_else_help() { #[test] fn subcommand_required_else_help_error_message() { #![allow(deprecated)] - let app = App::new("test") + let cmd = Command::new("test") .setting(AppSettings::SubcommandRequiredElseHelp) .version("1.0") - .subcommand(App::new("info").arg(Arg::new("filename"))); + .subcommand(Command::new("info").arg(Arg::new("filename"))); assert!(utils::compare_output( - app, + cmd, "test", SUBCOMMAND_REQUIRED_ELSE_HELP, true // Unlike normal displaying of help, we should provide a fatal exit code @@ -292,10 +292,10 @@ fn subcommand_required_else_help_error_message() { #[cfg(not(feature = "suggestions"))] #[test] fn infer_subcommands_fail_no_args() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test")) - .subcommand(App::new("temp")) + .subcommand(Command::new("test")) + .subcommand(Command::new("temp")) .try_get_matches_from(vec!["prog", "te"]); assert!(m.is_err(), "{:#?}", m.unwrap()); assert_eq!(m.unwrap_err().kind(), ErrorKind::UnrecognizedSubcommand); @@ -304,10 +304,10 @@ fn infer_subcommands_fail_no_args() { #[cfg(feature = "suggestions")] #[test] fn infer_subcommands_fail_no_args() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test")) - .subcommand(App::new("temp")) + .subcommand(Command::new("test")) + .subcommand(Command::new("temp")) .try_get_matches_from(vec!["prog", "te"]); assert!(m.is_err(), "{:#?}", m.unwrap()); assert_eq!(m.unwrap_err().kind(), ErrorKind::InvalidSubcommand); @@ -315,11 +315,11 @@ fn infer_subcommands_fail_no_args() { #[test] fn infer_subcommands_fail_with_args() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) .arg(Arg::new("some")) - .subcommand(App::new("test")) - .subcommand(App::new("temp")) + .subcommand(Command::new("test")) + .subcommand(Command::new("temp")) .try_get_matches_from(vec!["prog", "t"]); assert!(m.is_ok(), "{:?}", m.unwrap_err().kind()); assert_eq!(m.unwrap().value_of("some"), Some("t")); @@ -327,11 +327,11 @@ fn infer_subcommands_fail_with_args() { #[test] fn infer_subcommands_fail_with_args2() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) .arg(Arg::new("some")) - .subcommand(App::new("test")) - .subcommand(App::new("temp")) + .subcommand(Command::new("test")) + .subcommand(Command::new("temp")) .try_get_matches_from(vec!["prog", "te"]); assert!(m.is_ok(), "{:?}", m.unwrap_err().kind()); assert_eq!(m.unwrap().value_of("some"), Some("te")); @@ -339,9 +339,9 @@ fn infer_subcommands_fail_with_args2() { #[test] fn infer_subcommands_pass() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test")) + .subcommand(Command::new("test")) .try_get_matches_from(vec!["prog", "te"]) .unwrap(); assert_eq!(m.subcommand_name(), Some("test")); @@ -349,10 +349,10 @@ fn infer_subcommands_pass() { #[test] fn infer_subcommands_pass_close() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test")) - .subcommand(App::new("temp")) + .subcommand(Command::new("test")) + .subcommand(Command::new("temp")) .try_get_matches_from(vec!["prog", "tes"]) .unwrap(); assert_eq!(m.subcommand_name(), Some("test")); @@ -360,11 +360,11 @@ fn infer_subcommands_pass_close() { #[test] fn infer_subcommands_pass_exact_match() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test")) - .subcommand(App::new("testa")) - .subcommand(App::new("testb")) + .subcommand(Command::new("test")) + .subcommand(Command::new("testa")) + .subcommand(Command::new("testb")) .try_get_matches_from(vec!["prog", "test"]) .unwrap(); assert_eq!(m.subcommand_name(), Some("test")); @@ -373,10 +373,10 @@ fn infer_subcommands_pass_exact_match() { #[cfg(feature = "suggestions")] #[test] fn infer_subcommands_fail_suggestions() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test")) - .subcommand(App::new("temp")) + .subcommand(Command::new("test")) + .subcommand(Command::new("temp")) .try_get_matches_from(vec!["prog", "temps"]); assert!(m.is_err(), "{:#?}", m.unwrap()); assert_eq!(m.unwrap_err().kind(), ErrorKind::InvalidSubcommand); @@ -385,10 +385,10 @@ fn infer_subcommands_fail_suggestions() { #[cfg(not(feature = "suggestions"))] #[test] fn infer_subcommands_fail_suggestions() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test")) - .subcommand(App::new("temp")) + .subcommand(Command::new("test")) + .subcommand(Command::new("temp")) .try_get_matches_from(vec!["prog", "temps"]); assert!(m.is_err(), "{:#?}", m.unwrap()); assert_eq!(m.unwrap_err().kind(), ErrorKind::UnrecognizedSubcommand); @@ -396,7 +396,7 @@ fn infer_subcommands_fail_suggestions() { #[test] fn no_bin_name() { - let result = App::new("arg_required") + let result = Command::new("arg_required") .no_binary_name(true) .arg(Arg::new("test").required(true).index(1)) .try_get_matches_from(vec!["testing"]); @@ -407,7 +407,7 @@ fn no_bin_name() { #[test] fn skip_possible_values() { - let app = App::new("test") + let cmd = Command::new("test") .author("Kevin K.") .about("tests stuff") .version("1.3") @@ -420,7 +420,7 @@ fn skip_possible_values() { ]); assert!(utils::compare_output( - app, + cmd, "test --help", SKIP_POS_VALS, false @@ -429,7 +429,7 @@ fn skip_possible_values() { #[test] fn stop_delim_values_only_pos_follows() { - let r = App::new("onlypos") + let r = Command::new("onlypos") .dont_delimit_trailing_values(true) .args(&[ arg!(f: -f "some opt").required(false), @@ -448,7 +448,7 @@ fn stop_delim_values_only_pos_follows() { #[test] fn dont_delim_values_trailingvararg() { - let m = App::new("positional") + let m = Command::new("positional") .trailing_var_arg(true) .dont_delimit_trailing_values(true) .arg(arg!([opt] ... "some pos")) @@ -463,7 +463,7 @@ fn dont_delim_values_trailingvararg() { #[test] fn delim_values_only_pos_follows() { - let r = App::new("onlypos") + let r = Command::new("onlypos") .args(&[arg!(f: -f [flag] "some opt"), arg!([arg] ... "some arg")]) .try_get_matches_from(vec!["", "--", "-f", "-g,x"]); assert!(r.is_ok(), "{}", r.unwrap_err()); @@ -478,7 +478,7 @@ fn delim_values_only_pos_follows() { #[test] fn delim_values_trailingvararg() { - let m = App::new("positional") + let m = Command::new("positional") .trailing_var_arg(true) .arg(arg!([opt] ... "some pos")) .try_get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"]) @@ -492,7 +492,7 @@ fn delim_values_trailingvararg() { #[test] fn delim_values_only_pos_follows_with_delim() { - let r = App::new("onlypos") + let r = Command::new("onlypos") .args(&[ arg!(f: -f [flag] "some opt"), arg!([arg] ... "some arg").use_value_delimiter(true), @@ -510,7 +510,7 @@ fn delim_values_only_pos_follows_with_delim() { #[test] fn delim_values_trailingvararg_with_delim() { - let m = App::new("positional") + let m = Command::new("positional") .trailing_var_arg(true) .arg(arg!([opt] ... "some pos").use_value_delimiter(true)) .try_get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"]) @@ -524,7 +524,7 @@ fn delim_values_trailingvararg_with_delim() { #[test] fn leading_hyphen_short() { - let res = App::new("leadhy") + let res = Command::new("leadhy") .allow_hyphen_values(true) .arg(Arg::new("some")) .arg(Arg::new("other").short('o')) @@ -538,7 +538,7 @@ fn leading_hyphen_short() { #[test] fn leading_hyphen_long() { - let res = App::new("leadhy") + let res = Command::new("leadhy") .allow_hyphen_values(true) .arg(Arg::new("some")) .arg(Arg::new("other").short('o')) @@ -552,7 +552,7 @@ fn leading_hyphen_long() { #[test] fn leading_hyphen_opt() { - let res = App::new("leadhy") + let res = Command::new("leadhy") .allow_hyphen_values(true) .arg(Arg::new("some").takes_value(true).long("opt")) .arg(Arg::new("other").short('o')) @@ -566,7 +566,7 @@ fn leading_hyphen_opt() { #[test] fn allow_negative_numbers() { - let res = App::new("negnum") + let res = Command::new("negnum") .allow_negative_numbers(true) .arg(Arg::new("panum")) .arg(Arg::new("onum").short('o').takes_value(true)) @@ -579,7 +579,7 @@ fn allow_negative_numbers() { #[test] fn allow_negative_numbers_fail() { - let res = App::new("negnum") + let res = Command::new("negnum") .allow_negative_numbers(true) .arg(Arg::new("panum")) .arg(Arg::new("onum").short('o').takes_value(true)) @@ -590,7 +590,7 @@ fn allow_negative_numbers_fail() { #[test] fn leading_double_hyphen_trailingvararg() { - let m = App::new("positional") + let m = Command::new("positional") .trailing_var_arg(true) .allow_hyphen_values(true) .arg(arg!([opt] ... "some pos")) @@ -605,9 +605,9 @@ fn leading_double_hyphen_trailingvararg() { #[test] fn disable_help_subcommand() { - let result = App::new("disablehelp") + let result = Command::new("disablehelp") .disable_help_subcommand(true) - .subcommand(App::new("sub1")) + .subcommand(Command::new("sub1")) .try_get_matches_from(vec!["", "help"]); assert!(result.is_err()); let err = result.err().unwrap(); @@ -616,7 +616,7 @@ fn disable_help_subcommand() { #[test] fn dont_collapse_args() { - let app = App::new("clap-test") + let cmd = Command::new("clap-test") .version("v1.4.8") .dont_collapse_args_in_usage(true) .args(&[ @@ -625,7 +625,7 @@ fn dont_collapse_args() { Arg::new("arg3").help("some"), ]); assert!(utils::compare_output( - app, + cmd, "clap-test --help", DONT_COLLAPSE_ARGS, false @@ -634,7 +634,7 @@ fn dont_collapse_args() { #[test] fn require_eq() { - let app = App::new("clap-test").version("v1.4.8").arg( + let cmd = Command::new("clap-test").version("v1.4.8").arg( Arg::new("opt") .long("opt") .short('o') @@ -644,7 +644,7 @@ fn require_eq() { .help("some"), ); assert!(utils::compare_output( - app, + cmd, "clap-test --help", REQUIRE_EQUALS, false @@ -653,12 +653,14 @@ fn require_eq() { #[test] fn args_negate_subcommands_one_level() { - let res = App::new("disablehelp") + let res = Command::new("disablehelp") .args_conflicts_with_subcommands(true) .subcommand_negates_reqs(true) .arg(arg!( "some arg")) .arg(arg!( "some arg")) - .subcommand(App::new("sub1").subcommand(App::new("sub2").subcommand(App::new("sub3")))) + .subcommand( + Command::new("sub1").subcommand(Command::new("sub2").subcommand(Command::new("sub3"))), + ) .try_get_matches_from(vec!["", "pickles", "sub1"]); assert!(res.is_ok(), "error: {:?}", res.unwrap_err().kind()); let m = res.unwrap(); @@ -667,18 +669,18 @@ fn args_negate_subcommands_one_level() { #[test] fn args_negate_subcommands_two_levels() { - let res = App::new("disablehelp") + let res = Command::new("disablehelp") .args_conflicts_with_subcommands(true) .subcommand_negates_reqs(true) .arg(arg!( "some arg")) .arg(arg!( "some arg")) .subcommand( - App::new("sub1") + Command::new("sub1") .args_conflicts_with_subcommands(true) .subcommand_negates_reqs(true) .arg(arg!( "some")) .arg(arg!( "some")) - .subcommand(App::new("sub2").subcommand(App::new("sub3"))), + .subcommand(Command::new("sub2").subcommand(Command::new("sub3"))), ) .try_get_matches_from(vec!["", "sub1", "arg", "sub2"]); assert!(res.is_ok(), "error: {:?}", res.unwrap_err().kind()); @@ -691,9 +693,9 @@ fn args_negate_subcommands_two_levels() { #[test] fn propagate_vals_down() { - let m = App::new("myprog") + let m = Command::new("myprog") .arg(arg!([cmd] "command to run").global(true)) - .subcommand(App::new("foo")) + .subcommand(Command::new("foo")) .try_get_matches_from(vec!["myprog", "set", "foo"]); assert!(m.is_ok(), "{:?}", m.unwrap_err().kind()); let m = m.unwrap(); @@ -704,7 +706,7 @@ fn propagate_vals_down() { #[test] fn allow_missing_positional() { - let m = App::new("test") + let m = Command::new("test") .allow_missing_positional(true) .arg(arg!([src] "some file").default_value("src")) .arg(arg!( "some file")) @@ -717,7 +719,7 @@ fn allow_missing_positional() { #[test] fn allow_missing_positional_no_default() { - let m = App::new("test") + let m = Command::new("test") .allow_missing_positional(true) .arg(arg!([src] "some file")) .arg(arg!( "some file")) @@ -730,7 +732,7 @@ fn allow_missing_positional_no_default() { #[test] fn missing_positional_no_hyphen() { - let r = App::new("bench") + let r = Command::new("bench") .allow_missing_positional(true) .arg(arg!([BENCH] "some bench")) .arg(arg!([ARGS] ... "some args")) @@ -751,7 +753,7 @@ fn missing_positional_no_hyphen() { #[test] fn missing_positional_hyphen() { - let r = App::new("bench") + let r = Command::new("bench") .allow_missing_positional(true) .arg(arg!([BENCH] "some bench")) .arg(arg!([ARGS] ... "some args")) @@ -772,7 +774,7 @@ fn missing_positional_hyphen() { #[test] fn missing_positional_hyphen_far_back() { - let r = App::new("bench") + let r = Command::new("bench") .allow_missing_positional(true) .arg(arg!([BENCH1] "some bench")) .arg(arg!([BENCH2] "some bench")) @@ -799,7 +801,7 @@ fn missing_positional_hyphen_far_back() { #[test] fn missing_positional_hyphen_req_error() { - let r = App::new("bench") + let r = Command::new("bench") .allow_missing_positional(true) .arg(arg!([BENCH1] "some bench")) .arg(arg!( "some bench")) @@ -811,7 +813,7 @@ fn missing_positional_hyphen_req_error() { #[test] fn issue_1066_allow_leading_hyphen_and_unknown_args() { - let res = App::new("prog") + let res = Command::new("prog") .allow_hyphen_values(true) .arg(arg!(--"some-argument")) .try_get_matches_from(vec!["prog", "hello"]); @@ -822,7 +824,7 @@ fn issue_1066_allow_leading_hyphen_and_unknown_args() { #[test] fn issue_1066_allow_leading_hyphen_and_unknown_args_no_vals() { - let res = App::new("prog") + let res = Command::new("prog") .allow_hyphen_values(true) .arg(arg!(--"some-argument")) .try_get_matches_from(vec!["prog", "--hello"]); @@ -833,7 +835,7 @@ fn issue_1066_allow_leading_hyphen_and_unknown_args_no_vals() { #[test] fn issue_1066_allow_leading_hyphen_and_unknown_args_option() { - let res = App::new("prog") + let res = Command::new("prog") .allow_hyphen_values(true) .arg(arg!(--"some-argument" )) .try_get_matches_from(vec!["prog", "-hello"]); @@ -844,7 +846,7 @@ fn issue_1066_allow_leading_hyphen_and_unknown_args_option() { #[test] fn issue_1437_allow_hyphen_values_for_positional_arg() { - let m = App::new("tmp") + let m = Command::new("tmp") .arg( Arg::new("pat") .allow_hyphen_values(true) @@ -858,11 +860,11 @@ fn issue_1437_allow_hyphen_values_for_positional_arg() { #[test] fn issue_1093_allow_ext_sc() { - let app = App::new("clap-test") + let cmd = Command::new("clap-test") .version("v1.4.8") .allow_external_subcommands(true); assert!(utils::compare_output( - app, + cmd, "clap-test --help", ALLOW_EXT_SC, false @@ -871,7 +873,7 @@ fn issue_1093_allow_ext_sc() { #[test] fn allow_ext_sc_when_sc_required() { - let res = App::new("clap-test") + let res = Command::new("clap-test") .version("v1.4.8") .allow_external_subcommands(true) .allow_invalid_utf8_for_external_subcommands(true) @@ -891,11 +893,11 @@ fn allow_ext_sc_when_sc_required() { #[test] fn external_subcommand_looks_like_built_in() { - let res = App::new("cargo") + let res = Command::new("cargo") .version("1.26.0") .allow_external_subcommands(true) .allow_invalid_utf8_for_external_subcommands(true) - .subcommand(App::new("install")) + .subcommand(Command::new("install")) .try_get_matches_from(vec!["cargo", "install-update", "foo"]); assert!(res.is_ok(), "{}", res.unwrap_err()); let m = res.unwrap(); @@ -911,7 +913,7 @@ fn external_subcommand_looks_like_built_in() { #[test] fn aaos_flags() { // flags - let res = App::new("posix") + let res = Command::new("posix") .args_override_self(true) .arg(arg!(--flag "some flag")) .try_get_matches_from(vec!["", "--flag", "--flag"]); @@ -924,7 +926,7 @@ fn aaos_flags() { #[test] fn aaos_flags_mult() { // flags with multiple - let res = App::new("posix") + let res = Command::new("posix") .args_override_self(true) .arg(arg!(--flag ... "some flag")) .try_get_matches_from(vec!["", "--flag", "--flag", "--flag", "--flag"]); @@ -937,7 +939,7 @@ fn aaos_flags_mult() { #[test] fn aaos_opts() { // opts - let res = App::new("posix") + let res = Command::new("posix") .args_override_self(true) .arg(arg!(--opt "some option")) .try_get_matches_from(vec!["", "--opt=some", "--opt=other"]); @@ -951,7 +953,7 @@ fn aaos_opts() { #[test] fn aaos_opts_w_other_overrides() { // opts with other overrides - let res = App::new("posix") + let res = Command::new("posix") .args_override_self(true) .arg(arg!(--opt "some option").required(false)) .arg( @@ -971,7 +973,7 @@ fn aaos_opts_w_other_overrides() { #[test] fn aaos_opts_w_other_overrides_rev() { // opts with other overrides, rev - let res = App::new("posix") + let res = Command::new("posix") .args_override_self(true) .arg(arg!(--opt "some option").required(true)) .arg( @@ -990,7 +992,7 @@ fn aaos_opts_w_other_overrides_rev() { #[test] fn aaos_opts_w_other_overrides_2() { // opts with other overrides - let res = App::new("posix") + let res = Command::new("posix") .args_override_self(true) .arg( arg!(--opt "some option") @@ -1010,7 +1012,7 @@ fn aaos_opts_w_other_overrides_2() { #[test] fn aaos_opts_w_other_overrides_rev_2() { // opts with other overrides, rev - let res = App::new("posix") + let res = Command::new("posix") .args_override_self(true) .arg( arg!(--opt "some option") @@ -1029,7 +1031,7 @@ fn aaos_opts_w_other_overrides_rev_2() { #[test] fn aaos_opts_mult() { // opts with multiple - let res = App::new("posix") + let res = Command::new("posix") .args_override_self(true) .arg( arg!(--opt ... "some option") @@ -1052,7 +1054,7 @@ fn aaos_opts_mult() { #[test] fn aaos_opts_mult_req_delims() { // opts with multiple and require delims - let res = App::new("posix") + let res = Command::new("posix") .args_override_self(true) .arg(arg!(--opt ... "some option").multiple_values(true)) .try_get_matches_from(vec![ @@ -1078,7 +1080,7 @@ fn aaos_opts_mult_req_delims() { #[test] fn aaos_pos_mult() { // opts with multiple - let res = App::new("posix") + let res = Command::new("posix") .args_override_self(true) .arg(arg!([val] ... "some pos")) .try_get_matches_from(vec!["", "some", "other", "value"]); @@ -1094,7 +1096,7 @@ fn aaos_pos_mult() { #[test] fn aaos_option_use_delim_false() { - let m = App::new("posix") + let m = Command::new("posix") .args_override_self(true) .arg(arg!(--opt "some option").use_value_delimiter(false)) .try_get_matches_from(vec!["", "--opt=some,other", "--opt=one,two"]) @@ -1109,21 +1111,21 @@ fn aaos_option_use_delim_false() { #[test] fn no_auto_help() { - let app = App::new("myprog") + let cmd = Command::new("myprog") .setting(AppSettings::NoAutoHelp) - .subcommand(App::new("foo")); + .subcommand(Command::new("foo")); - let result = app.clone().try_get_matches_from("myprog --help".split(' ')); + let result = cmd.clone().try_get_matches_from("myprog --help".split(' ')); assert!(result.is_ok(), "{}", result.unwrap_err()); assert!(result.unwrap().is_present("help")); - let result = app.clone().try_get_matches_from("myprog -h".split(' ')); + let result = cmd.clone().try_get_matches_from("myprog -h".split(' ')); assert!(result.is_ok(), "{}", result.unwrap_err()); assert!(result.unwrap().is_present("help")); - let result = app.clone().try_get_matches_from("myprog help".split(' ')); + let result = cmd.clone().try_get_matches_from("myprog help".split(' ')); assert!(result.is_ok(), "{}", result.unwrap_err()); assert_eq!(result.unwrap().subcommand_name(), Some("help")); @@ -1131,18 +1133,18 @@ fn no_auto_help() { #[test] fn no_auto_version() { - let app = App::new("myprog") + let cmd = Command::new("myprog") .version("3.0") .setting(AppSettings::NoAutoVersion); - let result = app + let result = cmd .clone() .try_get_matches_from("myprog --version".split(' ')); assert!(result.is_ok(), "{}", result.unwrap_err()); assert!(result.unwrap().is_present("version")); - let result = app.clone().try_get_matches_from("myprog -V".split(' ')); + let result = cmd.clone().try_get_matches_from("myprog -V".split(' ')); assert!(result.is_ok(), "{}", result.unwrap_err()); assert!(result.unwrap().is_present("version")); @@ -1150,19 +1152,19 @@ fn no_auto_version() { #[test] fn no_auto_version_mut_arg() { - let app = App::new("myprog") + let cmd = Command::new("myprog") .version("3.0") .mut_arg("version", |v| v.help("custom help")) .setting(AppSettings::NoAutoVersion); - let result = app + let result = cmd .clone() .try_get_matches_from("myprog --version".split(' ')); assert!(result.is_ok(), "{}", result.unwrap_err()); assert!(result.unwrap().is_present("version")); - let result = app.clone().try_get_matches_from("myprog -V".split(' ')); + let result = cmd.clone().try_get_matches_from("myprog -V".split(' ')); assert!(result.is_ok(), "{}", result.unwrap_err()); assert!(result.unwrap().is_present("version")); @@ -1171,12 +1173,12 @@ fn no_auto_version_mut_arg() { #[test] #[cfg(feature = "color")] fn color_is_global() { - let mut app = App::new("myprog") + let mut cmd = Command::new("myprog") .color(clap::ColorChoice::Never) - .subcommand(App::new("foo")); - app._build_all(); - assert_eq!(app.get_color(), clap::ColorChoice::Never); + .subcommand(Command::new("foo")); + cmd._build_all(); + assert_eq!(cmd.get_color(), clap::ColorChoice::Never); - let sub = app.get_subcommands().collect::>()[0]; + let sub = cmd.get_subcommands().collect::>()[0]; assert_eq!(sub.get_color(), clap::ColorChoice::Never); } diff --git a/tests/builder/arg_aliases.rs b/tests/builder/arg_aliases.rs index 3800fa80885..f8401674ff6 100644 --- a/tests/builder/arg_aliases.rs +++ b/tests/builder/arg_aliases.rs @@ -1,6 +1,6 @@ use crate::utils; -use clap::{arg, App, Arg}; +use clap::{arg, Arg, Command}; static SC_VISIBLE_ALIAS_HELP: &str = "ct-test 1.2 Some help @@ -30,7 +30,7 @@ OPTIONS: #[test] fn single_alias_of_option() { - let a = App::new("single_alias") + let a = Command::new("single_alias") .arg( Arg::new("alias") .long("alias") @@ -47,7 +47,7 @@ fn single_alias_of_option() { #[test] fn multiple_aliases_of_option() { - let a = App::new("multiple_aliases").arg( + let a = Command::new("multiple_aliases").arg( Arg::new("aliases") .long("aliases") .takes_value(true) @@ -90,7 +90,7 @@ fn multiple_aliases_of_option() { #[test] fn single_alias_of_flag() { - let a = App::new("test") + let a = Command::new("test") .arg(Arg::new("flag").long("flag").alias("alias")) .try_get_matches_from(vec!["", "--alias"]); assert!(a.is_ok(), "{}", a.unwrap_err()); @@ -100,7 +100,7 @@ fn single_alias_of_flag() { #[test] fn multiple_aliases_of_flag() { - let a = App::new("test").arg(Arg::new("flag").long("flag").aliases(&[ + let a = Command::new("test").arg(Arg::new("flag").long("flag").aliases(&[ "invisible", "set", "of", @@ -132,9 +132,9 @@ fn multiple_aliases_of_flag() { #[test] fn alias_on_a_subcommand_option() { - let m = App::new("test") + let m = Command::new("test") .subcommand( - App::new("some").arg( + Command::new("some").arg( Arg::new("test") .short('t') .long("test") @@ -155,8 +155,8 @@ fn alias_on_a_subcommand_option() { #[test] fn invisible_arg_aliases_help_output() { - let app = App::new("ct").author("Salim Afiune").subcommand( - App::new("test") + let cmd = Command::new("ct").author("Salim Afiune").subcommand( + Command::new("test") .about("Some help") .version("1.2") .arg( @@ -169,7 +169,7 @@ fn invisible_arg_aliases_help_output() { .arg(arg!(-f - -flag).aliases(&["unseeable", "flg1", "anyway"])), ); assert!(utils::compare_output( - app, + cmd, "ct test --help", SC_INVISIBLE_ALIAS_HELP, false @@ -178,8 +178,8 @@ fn invisible_arg_aliases_help_output() { #[test] fn visible_arg_aliases_help_output() { - let app = App::new("ct").author("Salim Afiune").subcommand( - App::new("test") + let cmd = Command::new("ct").author("Salim Afiune").subcommand( + Command::new("test") .about("Some help") .version("1.2") .arg( @@ -198,7 +198,7 @@ fn visible_arg_aliases_help_output() { ), ); assert!(utils::compare_output( - app, + cmd, "ct test --help", SC_VISIBLE_ALIAS_HELP, false diff --git a/tests/builder/arg_aliases_short.rs b/tests/builder/arg_aliases_short.rs index 0b0fc30516e..5069bcb799d 100644 --- a/tests/builder/arg_aliases_short.rs +++ b/tests/builder/arg_aliases_short.rs @@ -1,6 +1,6 @@ use crate::utils; -use clap::{arg, App, Arg}; +use clap::{arg, Arg, Command}; static SC_VISIBLE_ALIAS_HELP: &str = "ct-test 1.2 Some help @@ -30,7 +30,7 @@ OPTIONS: #[test] fn single_short_alias_of_option() { - let a = App::new("single_alias") + let a = Command::new("single_alias") .arg( Arg::new("alias") .long("alias") @@ -47,7 +47,7 @@ fn single_short_alias_of_option() { #[test] fn multiple_short_aliases_of_option() { - let a = App::new("multiple_aliases").arg( + let a = Command::new("multiple_aliases").arg( Arg::new("aliases") .long("aliases") .takes_value(true) @@ -84,7 +84,7 @@ fn multiple_short_aliases_of_option() { #[test] fn single_short_alias_of_flag() { - let a = App::new("test") + let a = Command::new("test") .arg(Arg::new("flag").long("flag").short_alias('f')) .try_get_matches_from(vec!["", "-f"]); assert!(a.is_ok(), "{}", a.unwrap_err()); @@ -94,7 +94,7 @@ fn single_short_alias_of_flag() { #[test] fn multiple_short_aliases_of_flag() { - let a = App::new("test").arg( + let a = Command::new("test").arg( Arg::new("flag") .long("flag") .short_aliases(&['a', 'b', 'c', 'd', 'e']), @@ -124,9 +124,9 @@ fn multiple_short_aliases_of_flag() { #[test] fn short_alias_on_a_subcommand_option() { - let m = App::new("test") + let m = Command::new("test") .subcommand( - App::new("some").arg( + Command::new("some").arg( Arg::new("test") .short('t') .long("test") @@ -151,8 +151,8 @@ fn short_alias_on_a_subcommand_option() { #[test] fn invisible_short_arg_aliases_help_output() { - let app = App::new("ct").author("Salim Afiune").subcommand( - App::new("test") + let cmd = Command::new("ct").author("Salim Afiune").subcommand( + Command::new("test") .about("Some help") .version("1.2") .arg( @@ -165,7 +165,7 @@ fn invisible_short_arg_aliases_help_output() { .arg(arg!(-f - -flag).short_aliases(&['x', 'y', 'z'])), ); assert!(utils::compare_output( - app, + cmd, "ct test --help", SC_INVISIBLE_ALIAS_HELP, false @@ -174,8 +174,8 @@ fn invisible_short_arg_aliases_help_output() { #[test] fn visible_short_arg_aliases_help_output() { - let app = App::new("ct").author("Salim Afiune").subcommand( - App::new("test") + let cmd = Command::new("ct").author("Salim Afiune").subcommand( + Command::new("test") .about("Some help") .version("1.2") .arg( @@ -195,7 +195,7 @@ fn visible_short_arg_aliases_help_output() { ), ); assert!(utils::compare_output( - app, + cmd, "ct test --help", SC_VISIBLE_ALIAS_HELP, false diff --git a/tests/builder/arg_matcher_assertions.rs b/tests/builder/arg_matcher_assertions.rs index fc87b29fffb..e2c2378e8f0 100644 --- a/tests/builder/arg_matcher_assertions.rs +++ b/tests/builder/arg_matcher_assertions.rs @@ -1,11 +1,11 @@ #[cfg(debug_assertions)] -use clap::{App, Arg}; +use clap::{Arg, Command}; #[test] #[cfg(debug_assertions)] #[should_panic = "`f` is not a name of an argument or a group."] fn arg_matches_if_present_wrong_arg() { - let m = App::new("test") + let m = Command::new("test") .arg(Arg::new("flag").short('f')) .try_get_matches_from(&["test", "-f"]) .unwrap(); @@ -18,7 +18,7 @@ fn arg_matches_if_present_wrong_arg() { #[cfg(debug_assertions)] #[should_panic = "`o` is not a name of an argument or a group."] fn arg_matches_value_of_wrong_arg() { - let m = App::new("test") + let m = Command::new("test") .arg(Arg::new("opt").short('o').takes_value(true)) .try_get_matches_from(&["test", "-o", "val"]) .unwrap(); @@ -31,8 +31,8 @@ fn arg_matches_value_of_wrong_arg() { #[cfg(debug_assertions)] #[should_panic = "`seed` is not a name of a subcommand."] fn arg_matches_subcommand_matches_wrong_sub() { - let m = App::new("test") - .subcommand(App::new("speed")) + let m = Command::new("test") + .subcommand(Command::new("speed")) .try_get_matches_from(&["test", "speed"]) .unwrap(); diff --git a/tests/builder/borrowed.rs b/tests/builder/borrowed.rs index c1e668052db..4b4cd39a2d2 100644 --- a/tests/builder/borrowed.rs +++ b/tests/builder/borrowed.rs @@ -1,4 +1,4 @@ -use clap::{App, Arg}; +use clap::{Arg, Command}; #[test] fn borrowed_args() { @@ -7,11 +7,11 @@ fn borrowed_args() { .short('S') .long("some-thing") .help("other help"); - let result = App::new("sub_command_negate") + let result = Command::new("sub_command_negate") .arg(Arg::new("test").index(1)) .arg(&arg) .arg(&arg2) - .subcommand(App::new("sub1").arg(&arg)) + .subcommand(Command::new("sub1").arg(&arg)) .try_get_matches_from(vec!["prog"]); assert!(result.is_ok(), "{}", result.unwrap_err()); } diff --git a/tests/builder/cargo.rs b/tests/builder/cargo.rs index 996a9d2fd5a..d2eb6822fa6 100644 --- a/tests/builder/cargo.rs +++ b/tests/builder/cargo.rs @@ -1,6 +1,8 @@ #![cfg(feature = "cargo")] -use clap::{crate_authors, crate_description, crate_name, crate_version, error::ErrorKind, App}; +use clap::{ + crate_authors, crate_description, crate_name, crate_version, error::ErrorKind, Command, +}; static DESCRIPTION_ONLY: &str = "prog 1 A simple to use, efficient, and full-featured Command Line Argument Parser @@ -26,7 +28,7 @@ OPTIONS: #[test] fn crate_version() { - let res = App::new("prog") + let res = Command::new("prog") .version(crate_version!()) .try_get_matches_from(vec!["prog", "--version"]); @@ -41,7 +43,7 @@ fn crate_version() { #[test] fn crate_description() { - let res = App::new("prog") + let res = Command::new("prog") .version("1") .about(crate_description!()) .try_get_matches_from(vec!["prog", "--help"]); @@ -54,7 +56,7 @@ fn crate_description() { #[test] fn crate_authors() { - let res = App::new("prog") + let res = Command::new("prog") .version("1") .author(crate_authors!()) .try_get_matches_from(vec!["prog", "--help"]); @@ -67,7 +69,7 @@ fn crate_authors() { #[test] fn crate_name() { - let res = App::new(crate_name!()) + let res = Command::new(crate_name!()) .version("3.0") .try_get_matches_from(vec!["clap", "--version"]); diff --git a/tests/builder/conflicts.rs b/tests/builder/conflicts.rs index f59a3bf5c14..8126c93b5f7 100644 --- a/tests/builder/conflicts.rs +++ b/tests/builder/conflicts.rs @@ -1,6 +1,6 @@ use crate::utils; -use clap::{arg, error::ErrorKind, App, Arg, ArgGroup}; +use clap::{arg, error::ErrorKind, Arg, ArgGroup, Command}; static CONFLICT_ERR: &str = "error: The argument '--flag' cannot be used with '-F' @@ -30,7 +30,7 @@ For more information try --help #[test] fn flag_conflict() { - let result = App::new("flag_conflict") + let result = Command::new("flag_conflict") .arg(arg!(-f --flag "some flag").conflicts_with("other")) .arg(arg!(-o --other "some flag")) .try_get_matches_from(vec!["myprog", "-f", "-o"]); @@ -41,7 +41,7 @@ fn flag_conflict() { #[test] fn flag_conflict_2() { - let result = App::new("flag_conflict") + let result = Command::new("flag_conflict") .arg(arg!(-f --flag "some flag").conflicts_with("other")) .arg(arg!(-o --other "some flag")) .try_get_matches_from(vec!["myprog", "-o", "-f"]); @@ -52,7 +52,7 @@ fn flag_conflict_2() { #[test] fn flag_conflict_with_all() { - let result = App::new("flag_conflict") + let result = Command::new("flag_conflict") .arg(arg!(-f --flag "some flag").conflicts_with_all(&["other"])) .arg(arg!(-o --other "some flag")) .try_get_matches_from(vec!["myprog", "-o", "-f"]); @@ -63,7 +63,7 @@ fn flag_conflict_with_all() { #[test] fn flag_conflict_with_everything() { - let result = App::new("flag_conflict") + let result = Command::new("flag_conflict") .arg(arg!(-f --flag "some flag").exclusive(true)) .arg(arg!(-o --other "some flag")) .try_get_matches_from(vec!["myprog", "-o", "-f"]); @@ -74,33 +74,33 @@ fn flag_conflict_with_everything() { #[test] fn arg_conflicts_with_group() { - let mut app = App::new("group_conflict") + let mut cmd = Command::new("group_conflict") .arg(arg!(-f --flag "some flag").conflicts_with("gr")) .group(ArgGroup::new("gr").arg("some").arg("other")) .arg(arg!(--some "some arg")) .arg(arg!(--other "other arg")); - let result = app.try_get_matches_from_mut(vec!["myprog", "--other", "-f"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other", "-f"]); assert!(result.is_err()); let err = result.err().unwrap(); assert_eq!(err.kind(), ErrorKind::ArgumentConflict); - let result = app.try_get_matches_from_mut(vec!["myprog", "-f", "--some"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "-f", "--some"]); assert!(result.is_err()); let err = result.err().unwrap(); assert_eq!(err.kind(), ErrorKind::ArgumentConflict); - let result = app.try_get_matches_from_mut(vec!["myprog", "--some"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some"]); if let Err(err) = result { panic!("{}", err); } - let result = app.try_get_matches_from_mut(vec!["myprog", "--other"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other"]); if let Err(err) = result { panic!("{}", err); } - let result = app.try_get_matches_from_mut(vec!["myprog", "--flag"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--flag"]); if let Err(err) = result { panic!("{}", err); } @@ -108,7 +108,7 @@ fn arg_conflicts_with_group() { #[test] fn arg_conflicts_with_group_with_multiple_sources() { - let mut app = clap::App::new("group_conflict") + let mut cmd = clap::Command::new("group_conflict") .arg(clap::arg!(-f --flag "some flag").conflicts_with("gr")) .group(clap::ArgGroup::new("gr").multiple(true)) .arg( @@ -123,29 +123,29 @@ fn arg_conflicts_with_group_with_multiple_sources() { .group("gr"), ); - let result = app.try_get_matches_from_mut(vec!["myprog", "-f"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "-f"]); if let Err(err) = result { panic!("{}", err); } - let result = app.try_get_matches_from_mut(vec!["myprog", "--some", "usb1"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some", "usb1"]); if let Err(err) = result { panic!("{}", err); } - let result = app.try_get_matches_from_mut(vec!["myprog", "--some", "usb1", "--other", "40"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some", "usb1", "--other", "40"]); if let Err(err) = result { panic!("{}", err); } - let result = app.try_get_matches_from_mut(vec!["myprog", "-f", "--some", "usb1"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "-f", "--some", "usb1"]); let err = result.err().unwrap(); assert_eq!(err.kind(), ErrorKind::ArgumentConflict); } #[test] fn group_conflicts_with_arg() { - let mut app = App::new("group_conflict") + let mut cmd = Command::new("group_conflict") .arg(arg!(-f --flag "some flag")) .group( ArgGroup::new("gr") @@ -156,27 +156,27 @@ fn group_conflicts_with_arg() { .arg(arg!(--some "some arg")) .arg(arg!(--other "other arg")); - let result = app.try_get_matches_from_mut(vec!["myprog", "--other", "-f"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other", "-f"]); assert!(result.is_err()); let err = result.err().unwrap(); assert_eq!(err.kind(), ErrorKind::ArgumentConflict); - let result = app.try_get_matches_from_mut(vec!["myprog", "-f", "--some"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "-f", "--some"]); assert!(result.is_err()); let err = result.err().unwrap(); assert_eq!(err.kind(), ErrorKind::ArgumentConflict); - let result = app.try_get_matches_from_mut(vec!["myprog", "--some"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some"]); if let Err(err) = result { panic!("{}", err); } - let result = app.try_get_matches_from_mut(vec!["myprog", "--other"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other"]); if let Err(err) = result { panic!("{}", err); } - let result = app.try_get_matches_from_mut(vec!["myprog", "--flag"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--flag"]); if let Err(err) = result { panic!("{}", err); } @@ -184,28 +184,28 @@ fn group_conflicts_with_arg() { #[test] fn arg_conflicts_with_required_group() { - let mut app = App::new("group_conflict") + let mut cmd = Command::new("group_conflict") .arg(arg!(-f --flag "some flag").conflicts_with("gr")) .group(ArgGroup::new("gr").required(true).arg("some").arg("other")) .arg(arg!(--some "some arg")) .arg(arg!(--other "other arg")); - let result = app.try_get_matches_from_mut(vec!["myprog", "--other", "-f"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other", "-f"]); assert!(result.is_err()); let err = result.err().unwrap(); assert_eq!(err.kind(), ErrorKind::ArgumentConflict); - let result = app.try_get_matches_from_mut(vec!["myprog", "-f", "--some"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "-f", "--some"]); assert!(result.is_err()); let err = result.err().unwrap(); assert_eq!(err.kind(), ErrorKind::ArgumentConflict); - let result = app.try_get_matches_from_mut(vec!["myprog", "--some"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some"]); if let Err(err) = result { panic!("{}", err); } - let result = app.try_get_matches_from_mut(vec!["myprog", "--other"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other"]); if let Err(err) = result { panic!("{}", err); } @@ -213,7 +213,7 @@ fn arg_conflicts_with_required_group() { #[test] fn required_group_conflicts_with_arg() { - let mut app = App::new("group_conflict") + let mut cmd = Command::new("group_conflict") .arg(arg!(-f --flag "some flag")) .group( ArgGroup::new("gr") @@ -225,22 +225,22 @@ fn required_group_conflicts_with_arg() { .arg(arg!(--some "some arg")) .arg(arg!(--other "other arg")); - let result = app.try_get_matches_from_mut(vec!["myprog", "--other", "-f"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other", "-f"]); assert!(result.is_err()); let err = result.err().unwrap(); assert_eq!(err.kind(), ErrorKind::ArgumentConflict); - let result = app.try_get_matches_from_mut(vec!["myprog", "-f", "--some"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "-f", "--some"]); assert!(result.is_err()); let err = result.err().unwrap(); assert_eq!(err.kind(), ErrorKind::ArgumentConflict); - let result = app.try_get_matches_from_mut(vec!["myprog", "--some"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--some"]); if let Err(err) = result { panic!("{}", err); } - let result = app.try_get_matches_from_mut(vec!["myprog", "--other"]); + let result = cmd.try_get_matches_from_mut(vec!["myprog", "--other"]); if let Err(err) = result { panic!("{}", err); } @@ -288,7 +288,7 @@ fn conflict_output_rev_with_required() { #[test] fn conflict_output_three_conflicting() { - let app = App::new("three_conflicting_arguments") + let cmd = Command::new("three_conflicting_arguments") .arg( Arg::new("one") .long("one") @@ -305,7 +305,7 @@ fn conflict_output_three_conflicting() { .conflicts_with_all(&["one", "two"]), ); assert!(utils::compare_output( - app, + cmd, "three_conflicting_arguments --one --two --three", CONFLICT_ERR_THREE, true, @@ -314,7 +314,7 @@ fn conflict_output_three_conflicting() { #[test] fn two_conflicting_arguments() { - let a = App::new("two_conflicting_arguments") + let a = Command::new("two_conflicting_arguments") .arg( Arg::new("develop") .long("develop") @@ -339,7 +339,7 @@ fn two_conflicting_arguments() { #[test] fn three_conflicting_arguments() { - let a = App::new("three_conflicting_arguments") + let a = Command::new("three_conflicting_arguments") .arg( Arg::new("one") .long("one") @@ -371,7 +371,7 @@ fn three_conflicting_arguments() { #[test] #[should_panic = "Argument 'config' cannot conflict with itself"] fn self_conflicting_arg() { - let _ = App::new("prog") + let _ = Command::new("prog") .arg(Arg::new("config").long("config").conflicts_with("config")) .try_get_matches_from(vec!["", "--config"]); } @@ -380,14 +380,14 @@ fn self_conflicting_arg() { #[test] #[should_panic = "Argument or group 'extra' specified in 'conflicts_with*' for 'config' does not exist"] fn conflicts_with_invalid_arg() { - let _ = App::new("prog") + let _ = Command::new("prog") .arg(Arg::new("config").long("config").conflicts_with("extra")) .try_get_matches_from(vec!["", "--config"]); } #[test] fn conflict_with_unused_default() { - let result = App::new("conflict") + let result = Command::new("conflict") .arg( arg!(-o --opt "some opt") .required(false) @@ -405,7 +405,7 @@ fn conflict_with_unused_default() { #[test] fn conflicts_with_alongside_default() { - let result = App::new("conflict") + let result = Command::new("conflict") .arg( arg!(-o --opt "some opt") .default_value("default") @@ -428,7 +428,7 @@ fn conflicts_with_alongside_default() { #[test] fn group_in_conflicts_with() { - let result = App::new("conflict") + let result = Command::new("conflict") .arg( Arg::new("opt") .long("opt") @@ -451,7 +451,7 @@ fn group_in_conflicts_with() { #[test] fn group_conflicts_with_default_value() { - let result = App::new("conflict") + let result = Command::new("conflict") .arg( Arg::new("opt") .long("opt") @@ -474,7 +474,7 @@ fn group_conflicts_with_default_value() { #[test] fn group_conflicts_with_default_arg() { - let result = App::new("conflict") + let result = Command::new("conflict") .arg(Arg::new("opt").long("opt").default_value("default")) .arg(Arg::new("flag").long("flag").group("one")) .group(ArgGroup::new("one").conflicts_with("opt")) diff --git a/tests/builder/default_missing_vals.rs b/tests/builder/default_missing_vals.rs index 40793043afa..52ed95226fa 100644 --- a/tests/builder/default_missing_vals.rs +++ b/tests/builder/default_missing_vals.rs @@ -1,8 +1,8 @@ -use clap::{arg, App, Arg, ArgMatches}; +use clap::{arg, Arg, ArgMatches, Command}; #[test] fn opt_missing() { - let r = App::new("df") + let r = Command::new("df") .arg( Arg::new("color") .long("color") @@ -21,7 +21,7 @@ fn opt_missing() { #[test] fn opt_present_with_missing_value() { - let r = App::new("df") + let r = Command::new("df") .arg( Arg::new("color") .long("color") @@ -40,7 +40,7 @@ fn opt_present_with_missing_value() { #[test] fn opt_present_with_value() { - let r = App::new("df") + let r = Command::new("df") .arg( Arg::new("color") .long("color") @@ -59,7 +59,7 @@ fn opt_present_with_value() { #[test] fn opt_present_with_empty_value() { - let r = App::new("df") + let r = Command::new("df") .arg( Arg::new("color") .long("color") @@ -80,7 +80,7 @@ fn opt_present_with_empty_value() { #[test] fn opt_default() { // assert no change to usual argument handling when adding default_missing_value() - let r = App::new("app") + let r = Command::new("cmd") .arg( arg!(o: -o [opt] "some opt") .default_value("default") @@ -96,7 +96,7 @@ fn opt_default() { #[test] fn opt_default_user_override() { // assert no change to usual argument handling when adding default_missing_value() - let r = App::new("app") + let r = Command::new("cmd") .arg( arg!(o: -o [opt] "some opt") .default_value("default") @@ -112,7 +112,7 @@ fn opt_default_user_override() { #[test] #[allow(clippy::bool_assert_comparison)] fn default_missing_value_flag_value() { - let app = App::new("test").arg( + let cmd = Command::new("test").arg( Arg::new("flag") .long("flag") .takes_value(true) @@ -127,12 +127,12 @@ fn default_missing_value_flag_value() { } assert_eq!( - flag_value(app.clone().try_get_matches_from(&["test"]).unwrap()), + flag_value(cmd.clone().try_get_matches_from(&["test"]).unwrap()), false ); assert_eq!( flag_value( - app.clone() + cmd.clone() .try_get_matches_from(&["test", "--flag"]) .unwrap() ), @@ -140,7 +140,7 @@ fn default_missing_value_flag_value() { ); assert_eq!( flag_value( - app.clone() + cmd.clone() .try_get_matches_from(&["test", "--flag=true"]) .unwrap() ), @@ -148,7 +148,7 @@ fn default_missing_value_flag_value() { ); assert_eq!( flag_value( - app.clone() + cmd.clone() .try_get_matches_from(&["test", "--flag=false"]) .unwrap() ), @@ -160,9 +160,9 @@ fn default_missing_value_flag_value() { #[test] #[should_panic = "Argument `arg`'s default_missing_value=value doesn't match possible values"] fn default_missing_values_are_possible_values() { - use clap::{App, Arg}; + use clap::{Arg, Command}; - let _ = App::new("test") + let _ = Command::new("test") .arg( Arg::new("arg") .possible_values(["one", "two"]) @@ -175,9 +175,9 @@ fn default_missing_values_are_possible_values() { #[test] #[should_panic = "Argument `arg`'s default_missing_value=value failed validation: invalid digit found in string"] fn default_missing_values_are_valid() { - use clap::{App, Arg}; + use clap::{Arg, Command}; - let _ = App::new("test") + let _ = Command::new("test") .arg( Arg::new("arg") .validator(|val| val.parse::().map_err(|e| e.to_string())) diff --git a/tests/builder/default_vals.rs b/tests/builder/default_vals.rs index 8c2777a378b..839024927f9 100644 --- a/tests/builder/default_vals.rs +++ b/tests/builder/default_vals.rs @@ -1,9 +1,9 @@ use crate::utils; -use clap::{arg, error::ErrorKind, App, Arg}; +use clap::{arg, error::ErrorKind, Arg, Command}; #[test] fn opts() { - let r = App::new("df") + let r = Command::new("df") .arg( arg!(o: -o "some opt") .required(false) @@ -18,7 +18,7 @@ fn opts() { #[test] fn opt_without_value_fail() { - let r = App::new("df") + let r = Command::new("df") .arg( arg!(o: -o "some opt") .required(false) @@ -36,7 +36,7 @@ fn opt_without_value_fail() { #[test] fn opt_user_override() { - let r = App::new("df") + let r = Command::new("df") .arg( arg!(--opt "some arg") .required(false) @@ -51,7 +51,7 @@ fn opt_user_override() { #[test] fn positionals() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!([arg] "some opt").default_value("default")) .try_get_matches_from(vec![""]); assert!(r.is_ok(), "{}", r.unwrap_err()); @@ -62,7 +62,7 @@ fn positionals() { #[test] fn positional_user_override() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!([arg] "some arg").default_value("default")) .try_get_matches_from(vec!["", "value"]); assert!(r.is_ok(), "{}", r.unwrap_err()); @@ -78,7 +78,7 @@ fn osstr_opts() { use std::ffi::OsStr; let expected = OsStr::new("default"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!(o: -o "some opt") .required(false) @@ -96,7 +96,7 @@ fn osstr_opt_user_override() { use std::ffi::OsStr; let default = OsStr::new("default"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!(--opt "some arg") .required(false) @@ -114,7 +114,7 @@ fn osstr_positionals() { use std::ffi::OsStr; let expected = OsStr::new("default"); - let r = App::new("df") + let r = Command::new("df") .arg(arg!([arg] "some opt").default_value_os(expected)) .try_get_matches_from(vec![""]); assert!(r.is_ok(), "{}", r.unwrap_err()); @@ -128,7 +128,7 @@ fn osstr_positional_user_override() { use std::ffi::OsStr; let default = OsStr::new("default"); - let r = App::new("df") + let r = Command::new("df") .arg(arg!([arg] "some arg").default_value_os(default)) .try_get_matches_from(vec!["", "value"]); assert!(r.is_ok(), "{}", r.unwrap_err()); @@ -141,7 +141,7 @@ fn osstr_positional_user_override() { #[test] fn default_if_arg_present_no_default() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(true)) .arg(arg!([arg] "some arg").default_value_if("opt", None, Some("default"))) .try_get_matches_from(vec!["", "--opt", "some"]); @@ -153,7 +153,7 @@ fn default_if_arg_present_no_default() { #[test] fn default_if_arg_present_no_default_user_override() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg(arg!([arg] "some arg").default_value_if("opt", None, Some("default"))) .try_get_matches_from(vec!["", "--opt", "some", "other"]); @@ -165,7 +165,7 @@ fn default_if_arg_present_no_default_user_override() { #[test] fn default_if_arg_present_no_arg_with_default() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -181,7 +181,7 @@ fn default_if_arg_present_no_arg_with_default() { #[test] fn default_if_arg_present_with_default() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -197,7 +197,7 @@ fn default_if_arg_present_with_default() { #[test] fn default_if_arg_present_with_default_user_override() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -213,7 +213,7 @@ 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") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -231,7 +231,7 @@ 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") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg(arg!([arg] "some arg").default_value_if("opt", Some("value"), Some("default"))) .try_get_matches_from(vec!["", "--opt", "value"]); @@ -243,7 +243,7 @@ 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") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg(arg!([arg] "some arg").default_value_if("opt", Some("value"), Some("default"))) .try_get_matches_from(vec!["", "--opt", "other"]); @@ -255,7 +255,7 @@ 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") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg(arg!([arg] "some arg").default_value_if("opt", Some("some"), Some("default"))) .try_get_matches_from(vec!["", "--opt", "some", "other"]); @@ -267,7 +267,7 @@ 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") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -283,7 +283,7 @@ 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") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -299,7 +299,7 @@ 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") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -315,7 +315,7 @@ 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") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -331,7 +331,7 @@ 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") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -347,7 +347,7 @@ 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") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -365,7 +365,7 @@ fn default_if_arg_present_no_arg_with_value_with_default_user_override_fail() { #[test] fn no_default_if_arg_present_with_value_no_default() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg(arg!([arg] "some arg").default_value_if("opt", Some("value"), None)) .try_get_matches_from(vec!["", "--opt", "value"]); @@ -376,7 +376,7 @@ fn no_default_if_arg_present_with_value_no_default() { #[test] fn no_default_if_arg_present_with_value_with_default() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -392,7 +392,7 @@ fn no_default_if_arg_present_with_value_with_default() { #[test] fn no_default_if_arg_present_with_value_with_default_user_override() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -408,7 +408,7 @@ fn no_default_if_arg_present_with_value_with_default_user_override() { #[test] fn no_default_if_arg_present_no_arg_with_value_with_default() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg( arg!([arg] "some arg") @@ -426,7 +426,7 @@ fn no_default_if_arg_present_no_arg_with_value_with_default() { #[test] fn default_ifs_arg_present() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg(arg!(--flag "some arg")) .arg( @@ -446,7 +446,7 @@ fn default_ifs_arg_present() { #[test] fn no_default_ifs_arg_present() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg(arg!(--flag "some arg")) .arg( @@ -463,7 +463,7 @@ fn no_default_ifs_arg_present() { #[test] fn default_ifs_arg_present_user_override() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg(arg!(--flag "some arg")) .arg( @@ -483,7 +483,7 @@ fn default_ifs_arg_present_user_override() { #[test] fn default_ifs_arg_present_order() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(--opt "some arg").required(false)) .arg(arg!(--flag "some arg")) .arg( @@ -505,7 +505,7 @@ fn default_ifs_arg_present_order() { #[test] fn conditional_reqs_pass() { - let m = App::new("Test app") + let m = Command::new("Test cmd") .arg( Arg::new("target") .takes_value(true) @@ -534,7 +534,7 @@ fn conditional_reqs_pass() { #[test] fn multiple_defaults() { - let r = App::new("diff") + let r = Command::new("diff") .arg( Arg::new("files") .long("files") @@ -551,7 +551,7 @@ fn multiple_defaults() { #[test] fn multiple_defaults_override() { - let r = App::new("diff") + let r = Command::new("diff") .arg( Arg::new("files") .long("files") @@ -568,7 +568,7 @@ fn multiple_defaults_override() { #[test] fn default_vals_donnot_show_in_smart_usage() { - let app = App::new("bug") + let cmd = Command::new("bug") .arg( Arg::new("foo") .long("config") @@ -578,7 +578,7 @@ fn default_vals_donnot_show_in_smart_usage() { .arg(Arg::new("input").required(true)); assert!(utils::compare_output( - app, + cmd, "bug", "error: The following required arguments were not provided: @@ -594,7 +594,7 @@ For more information try --help #[test] fn issue_1050_num_vals_and_defaults() { - let res = App::new("hello") + let res = Command::new("hello") .arg( Arg::new("exit-code") .long("exit-code") @@ -612,9 +612,9 @@ fn issue_1050_num_vals_and_defaults() { #[test] #[should_panic = "Argument group 'group' is required but all of it's arguments have a default value."] fn required_groups_with_default_values() { - use clap::{App, Arg, ArgGroup}; + use clap::{Arg, ArgGroup, Command}; - let _ = App::new("test") + let _ = Command::new("test") .arg(Arg::new("arg").default_value("value")) .group(ArgGroup::new("group").args(&["arg"]).required(true)) .try_get_matches(); @@ -624,9 +624,9 @@ fn required_groups_with_default_values() { #[test] #[should_panic = "Argument 'arg' is required and can't have a default value"] fn required_args_with_default_values() { - use clap::{App, Arg}; + use clap::{Arg, Command}; - let _ = App::new("test") + let _ = Command::new("test") .arg(Arg::new("arg").required(true).default_value("value")) .try_get_matches(); } @@ -635,9 +635,9 @@ fn required_args_with_default_values() { #[test] #[should_panic = "Argument `arg`'s default_value=value doesn't match possible values"] fn default_values_are_possible_values() { - use clap::{App, Arg}; + use clap::{Arg, Command}; - let _ = App::new("test") + let _ = Command::new("test") .arg( Arg::new("arg") .possible_values(["one", "two"]) @@ -650,9 +650,9 @@ fn default_values_are_possible_values() { #[test] #[should_panic = "Argument `arg`'s default_value=value failed validation: invalid digit found in string"] fn default_values_are_valid() { - use clap::{App, Arg}; + use clap::{Arg, Command}; - let _ = App::new("test") + let _ = Command::new("test") .arg( Arg::new("arg") .validator(|val| val.parse::().map_err(|e| e.to_string())) @@ -663,7 +663,7 @@ fn default_values_are_valid() { #[test] fn with_value_delimiter() { - let app = App::new("multiple_values").arg( + let cmd = Command::new("multiple_values").arg( Arg::new("option") .long("option") .help("multiple options") @@ -671,7 +671,7 @@ fn with_value_delimiter() { .default_value("first;second"), ); - let matches = app.try_get_matches_from(vec![""]).unwrap(); + let matches = cmd.try_get_matches_from(vec![""]).unwrap(); assert_eq!( matches.values_of("option").unwrap().collect::>(), @@ -681,14 +681,14 @@ fn with_value_delimiter() { #[test] fn missing_with_value_delimiter() { - let app = App::new("program").arg( + let cmd = Command::new("program").arg( Arg::new("option") .long("option") .value_delimiter(';') .default_missing_values(&["value1;value2;value3", "value4;value5"]), ); - let matches = app + let matches = cmd .try_get_matches_from(vec!["program", "--option"]) .unwrap(); diff --git a/tests/builder/delimiters.rs b/tests/builder/delimiters.rs index 9b3ec80870a..2ead7a3d333 100644 --- a/tests/builder/delimiters.rs +++ b/tests/builder/delimiters.rs @@ -1,8 +1,8 @@ -use clap::{App, Arg}; +use clap::{Arg, Command}; #[test] fn opt_default_no_delim() { - let m = App::new("no_delim") + let m = Command::new("no_delim") .arg(Arg::new("option").long("option").takes_value(true)) .try_get_matches_from(vec!["", "--option", "val1,val2,val3"]); @@ -16,7 +16,7 @@ fn opt_default_no_delim() { #[test] fn opt_eq_no_delim() { - let m = App::new("no_delim") + let m = Command::new("no_delim") .arg(Arg::new("option").long("option").takes_value(true)) .try_get_matches_from(vec!["", "--option=val1,val2,val3"]); @@ -30,7 +30,7 @@ fn opt_eq_no_delim() { #[test] fn opt_s_eq_no_delim() { - let m = App::new("no_delim") + let m = Command::new("no_delim") .arg(Arg::new("option").short('o').takes_value(true)) .try_get_matches_from(vec!["", "-o=val1,val2,val3"]); @@ -44,7 +44,7 @@ fn opt_s_eq_no_delim() { #[test] fn opt_s_default_no_delim() { - let m = App::new("no_delim") + let m = Command::new("no_delim") .arg(Arg::new("option").short('o').takes_value(true)) .try_get_matches_from(vec!["", "-o", "val1,val2,val3"]); @@ -58,7 +58,7 @@ fn opt_s_default_no_delim() { #[test] fn opt_s_no_space_no_delim() { - let m = App::new("no_delim") + let m = Command::new("no_delim") .arg(Arg::new("option").short('o').takes_value(true)) .try_get_matches_from(vec!["", "-o", "val1,val2,val3"]); @@ -72,7 +72,7 @@ fn opt_s_no_space_no_delim() { #[test] fn opt_s_no_space_mult_no_delim() { - let m = App::new("no_delim") + let m = Command::new("no_delim") .arg( Arg::new("option") .short('o') @@ -91,7 +91,7 @@ fn opt_s_no_space_mult_no_delim() { #[test] fn opt_eq_mult_def_delim() { - let m = App::new("no_delim") + let m = Command::new("no_delim") .arg( Arg::new("option") .long("opt") diff --git a/tests/builder/derive_order.rs b/tests/builder/derive_order.rs index f61bbc2cb90..9e5608e8a8f 100644 --- a/tests/builder/derive_order.rs +++ b/tests/builder/derive_order.rs @@ -2,7 +2,7 @@ use crate::utils; use std::str; -use clap::{App, AppSettings, Arg}; +use clap::{AppSettings, Arg, Command}; static NO_DERIVE_ORDER: &str = "test 1.2 @@ -86,7 +86,7 @@ OPTIONS: #[test] fn no_derive_order() { - let app = App::new("test").version("1.2").args(&[ + let cmd = Command::new("test").version("1.2").args(&[ Arg::new("flag_b").long("flag_b").help("first flag"), Arg::new("option_b") .long("option_b") @@ -100,7 +100,7 @@ fn no_derive_order() { ]); assert!(utils::compare_output( - app, + cmd, "test --help", NO_DERIVE_ORDER, false @@ -109,7 +109,7 @@ fn no_derive_order() { #[test] fn derive_order() { - let app = App::new("test") + let cmd = Command::new("test") .setting(AppSettings::DeriveDisplayOrder) .version("1.2") .args(&[ @@ -126,7 +126,7 @@ fn derive_order() { ]); assert!(utils::compare_output( - app, + cmd, "test --help", UNIFIED_HELP_AND_DERIVE, false @@ -149,7 +149,7 @@ OPTIONS: --option_a second option "; - let app = App::new("test") + let cmd = Command::new("test") .setting(AppSettings::DeriveDisplayOrder) .version("1.2") .next_display_order(10000) @@ -169,7 +169,7 @@ OPTIONS: .help("first option"), ); - assert!(utils::compare_output(app, "test --help", HELP, false)); + assert!(utils::compare_output(cmd, "test --help", HELP, false)); } #[test] @@ -188,7 +188,7 @@ OPTIONS: -V, --version Print version information "; - let app = App::new("test") + let cmd = Command::new("test") .setting(AppSettings::DeriveDisplayOrder) .version("1.2") .next_display_order(None) @@ -207,15 +207,15 @@ OPTIONS: .help("second option"), ); - assert!(utils::compare_output(app, "test --help", HELP, false)); + assert!(utils::compare_output(cmd, "test --help", HELP, false)); } #[test] fn derive_order_subcommand_propagate() { - let app = App::new("test") + let cmd = Command::new("test") .global_setting(AppSettings::DeriveDisplayOrder) .subcommand( - App::new("sub").version("1.2").args(&[ + Command::new("sub").version("1.2").args(&[ Arg::new("flag_b").long("flag_b").help("first flag"), Arg::new("option_b") .long("option_b") @@ -230,7 +230,7 @@ fn derive_order_subcommand_propagate() { ); assert!(utils::compare_output( - app, + cmd, "test sub --help", UNIFIED_DERIVE_SC_PROP, false @@ -239,10 +239,10 @@ fn derive_order_subcommand_propagate() { #[test] fn derive_order_subcommand_propagate_with_explicit_display_order() { - let app = App::new("test") + let cmd = Command::new("test") .global_setting(AppSettings::DeriveDisplayOrder) .subcommand( - App::new("sub").version("1.2").args(&[ + Command::new("sub").version("1.2").args(&[ Arg::new("flag_b").long("flag_b").help("first flag"), Arg::new("option_b") .long("option_b") @@ -260,7 +260,7 @@ fn derive_order_subcommand_propagate_with_explicit_display_order() { ); assert!(utils::compare_output( - app, + cmd, "test sub --help", UNIFIED_DERIVE_SC_PROP_EXPLICIT_ORDER, false @@ -269,7 +269,7 @@ fn derive_order_subcommand_propagate_with_explicit_display_order() { #[test] fn prefer_user_help_with_derive_order() { - let app = App::new("test") + let cmd = Command::new("test") .setting(AppSettings::DeriveDisplayOrder) .version("1.2") .args(&[ @@ -282,7 +282,7 @@ fn prefer_user_help_with_derive_order() { ]); assert!(utils::compare_output( - app, + cmd, "test --help", PREFER_USER_HELP_DERIVE_ORDER, false @@ -291,10 +291,10 @@ fn prefer_user_help_with_derive_order() { #[test] fn prefer_user_help_in_subcommand_with_derive_order() { - let app = App::new("test") + let cmd = Command::new("test") .global_setting(AppSettings::DeriveDisplayOrder) .subcommand( - App::new("sub").version("1.2").args(&[ + Command::new("sub").version("1.2").args(&[ Arg::new("help") .long("help") .short('h') @@ -305,7 +305,7 @@ fn prefer_user_help_in_subcommand_with_derive_order() { ); assert!(utils::compare_output( - app, + cmd, "test sub --help", PREFER_USER_HELP_SUBCMD_DERIVE_ORDER, false diff --git a/tests/builder/display_order.rs b/tests/builder/display_order.rs index cf83fadfca0..1c97ba2eb0d 100644 --- a/tests/builder/display_order.rs +++ b/tests/builder/display_order.rs @@ -1,13 +1,13 @@ use crate::utils; -use clap::App; +use clap::Command; #[test] fn very_large_display_order() { - let app = App::new("test").subcommand(App::new("sub").display_order(usize::MAX)); + let cmd = Command::new("test").subcommand(Command::new("sub").display_order(usize::MAX)); assert!(utils::compare_output( - app, + cmd, "test --help", "test diff --git a/tests/builder/double_require.rs b/tests/builder/double_require.rs index cf29983ccf7..30495c5872f 100644 --- a/tests/builder/double_require.rs +++ b/tests/builder/double_require.rs @@ -1,4 +1,4 @@ -use clap::{error::ErrorKind, App, Arg}; +use clap::{error::ErrorKind, Arg, Command}; static HELP: &str = "prog @@ -30,8 +30,8 @@ USAGE: For more information try --help "; -fn app() -> App<'static> { - App::new("prog") +fn cmd() -> Command<'static> { + Command::new("prog") .arg( Arg::new("a") .short('a') @@ -54,17 +54,17 @@ fn app() -> App<'static> { #[test] fn valid_cases() { - let res = app().try_get_matches_from(vec!["", "-a"]); + let res = cmd().try_get_matches_from(vec!["", "-a"]); assert!(res.is_ok(), "{}", res.unwrap_err()); - let res = app().clone().try_get_matches_from(vec!["", "-b", "-c"]); + let res = cmd().clone().try_get_matches_from(vec!["", "-b", "-c"]); assert!(res.is_ok(), "{}", res.unwrap_err()); - let res = app().try_get_matches_from(vec!["", "-c", "-b"]); + let res = cmd().try_get_matches_from(vec!["", "-c", "-b"]); assert!(res.is_ok(), "{}", res.unwrap_err()); } #[test] fn help_text() { - let res = app().try_get_matches_from(vec!["prog", "--help"]); + let res = cmd().try_get_matches_from(vec!["prog", "--help"]); assert!(res.is_err()); let err = res.unwrap_err(); assert_eq!(err.kind(), ErrorKind::DisplayHelp); @@ -74,13 +74,13 @@ fn help_text() { #[test] fn no_duplicate_error() { - let res = app().try_get_matches_from(vec!["", "-b"]); + let res = cmd().try_get_matches_from(vec!["", "-b"]); assert!(res.is_err()); let err = res.unwrap_err(); assert_eq!(err.kind(), ErrorKind::MissingRequiredArgument); assert_eq!(err.to_string(), ONLY_B_ERROR); - let res = app().try_get_matches_from(vec!["", "-c"]); + let res = cmd().try_get_matches_from(vec!["", "-c"]); assert!(res.is_err()); let err = res.unwrap_err(); assert_eq!(err.kind(), ErrorKind::MissingRequiredArgument); diff --git a/tests/builder/empty_values.rs b/tests/builder/empty_values.rs index ca22f539f64..5d57f160be4 100644 --- a/tests/builder/empty_values.rs +++ b/tests/builder/empty_values.rs @@ -1,10 +1,10 @@ use crate::utils; -use clap::{error::ErrorKind, App, Arg}; +use clap::{error::ErrorKind, Arg, Command}; #[test] fn empty_values() { - let m = App::new("config") + let m = Command::new("config") .arg(Arg::new("config").long("config").takes_value(true)) .try_get_matches_from(&["config", "--config", ""]) .unwrap(); @@ -13,13 +13,13 @@ fn empty_values() { #[test] fn empty_values_with_equals() { - let m = App::new("config") + let m = Command::new("config") .arg(Arg::new("config").long("config").takes_value(true)) .try_get_matches_from(&["config", "--config="]) .unwrap(); assert_eq!(m.value_of("config"), Some("")); - let m = App::new("config") + let m = Command::new("config") .arg(Arg::new("config").short('c').takes_value(true)) .try_get_matches_from(&["config", "-c="]) .unwrap(); @@ -28,7 +28,7 @@ fn empty_values_with_equals() { #[test] fn no_empty_values() { - let m = App::new("config") + let m = Command::new("config") .arg( Arg::new("config") .long("config") @@ -39,7 +39,7 @@ fn no_empty_values() { assert!(m.is_err()); assert_eq!(m.unwrap_err().kind(), ErrorKind::EmptyValue); - let m = App::new("config") + let m = Command::new("config") .arg( Arg::new("config") .short('c') @@ -53,7 +53,7 @@ fn no_empty_values() { #[test] fn no_empty_values_with_equals() { - let m = App::new("config") + let m = Command::new("config") .arg( Arg::new("config") .long("config") @@ -64,7 +64,7 @@ fn no_empty_values_with_equals() { assert!(m.is_err()); assert_eq!(m.unwrap_err().kind(), ErrorKind::EmptyValue); - let m = App::new("config") + let m = Command::new("config") .arg( Arg::new("config") .short('c') @@ -78,7 +78,7 @@ fn no_empty_values_with_equals() { #[test] fn no_empty_values_without_equals() { - let m = App::new("config") + let m = Command::new("config") .arg( Arg::new("config") .long("config") @@ -89,7 +89,7 @@ fn no_empty_values_without_equals() { assert!(m.is_err()); assert_eq!(m.unwrap_err().kind(), ErrorKind::EmptyValue); - let m = App::new("config") + let m = Command::new("config") .arg( Arg::new("config") .short('c') @@ -103,14 +103,14 @@ fn no_empty_values_without_equals() { #[test] fn no_empty_values_without_equals_but_requires_equals() { - let app = App::new("config").arg( + let cmd = Command::new("config").arg( Arg::new("config") .long("config") .takes_value(true) .forbid_empty_values(true) .require_equals(true), ); - let m = app.clone().try_get_matches_from(&["config", "--config"]); + let m = cmd.clone().try_get_matches_from(&["config", "--config"]); // Should error on no equals rather than empty value. assert!(m.is_err()); assert_eq!(m.unwrap_err().kind(), ErrorKind::NoEquals); @@ -125,7 +125,7 @@ For more information try --help "; assert!(utils::compare_output( - app, + cmd, "config --config", NO_EUQALS_ERROR, true diff --git a/tests/builder/env.rs b/tests/builder/env.rs index 115c9cb7da1..e5416eef470 100644 --- a/tests/builder/env.rs +++ b/tests/builder/env.rs @@ -3,13 +3,13 @@ use std::env; use std::ffi::OsStr; -use clap::{arg, App, Arg}; +use clap::{arg, Arg, Command}; #[test] fn env() { env::set_var("CLP_TEST_ENV", "env"); - let r = App::new("df") + let r = Command::new("df") .arg(arg!([arg] "some opt").env("CLP_TEST_ENV").takes_value(true)) .try_get_matches_from(vec![""]); @@ -25,7 +25,7 @@ fn env_bool_literal() { env::set_var("CLP_TEST_FLAG_TRUE", "On"); env::set_var("CLP_TEST_FLAG_FALSE", "nO"); - let r = App::new("df") + let r = Command::new("df") .arg(Arg::new("present").short('p').env("CLP_TEST_FLAG_TRUE")) .arg(Arg::new("negated").short('n').env("CLP_TEST_FLAG_FALSE")) .arg(Arg::new("absent").short('a').env("CLP_TEST_FLAG_ABSENT")) @@ -44,7 +44,7 @@ fn env_bool_literal() { fn env_os() { env::set_var("CLP_TEST_ENV_OS", "env"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env_os(OsStr::new("CLP_TEST_ENV_OS")) @@ -65,7 +65,7 @@ fn no_env() { // we need another variable just in case one of the others is running at the same time... env::remove_var("CLP_TEST_ENV_NONE"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_NONE") @@ -86,7 +86,7 @@ fn no_env_no_takes_value() { // we need another variable just in case one of the others is running at the same time... env::remove_var("CLP_TEST_ENV_NONE"); - let r = App::new("df") + let r = Command::new("df") .arg(arg!([arg] "some opt").env("CLP_TEST_ENV_NONE")) .try_get_matches_from(vec![""]); @@ -101,7 +101,7 @@ fn no_env_no_takes_value() { fn with_default() { env::set_var("CLP_TEST_ENV_WD", "env"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_WD") @@ -121,7 +121,7 @@ fn with_default() { fn opt_user_override() { env::set_var("CLP_TEST_ENV_OR", "env"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!(--arg [FILE] "some arg") .env("CLP_TEST_ENV_OR") @@ -144,7 +144,7 @@ fn opt_user_override() { fn positionals() { env::set_var("CLP_TEST_ENV_P", "env"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_P") @@ -163,7 +163,7 @@ fn positionals() { fn positionals_user_override() { env::set_var("CLP_TEST_ENV_POR", "env"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_POR") @@ -186,7 +186,7 @@ fn positionals_user_override() { fn multiple_one() { env::set_var("CLP_TEST_ENV_MO", "env"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_MO") @@ -207,7 +207,7 @@ fn multiple_one() { fn multiple_three() { env::set_var("CLP_TEST_ENV_MULTI1", "env1,env2,env3"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_MULTI1") @@ -231,7 +231,7 @@ fn multiple_three() { fn multiple_no_delimiter() { env::set_var("CLP_TEST_ENV_MULTI2", "env1 env2 env3"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_MULTI2") @@ -254,7 +254,7 @@ fn multiple_no_delimiter() { fn possible_value() { env::set_var("CLP_TEST_ENV_PV", "env"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_PV") @@ -274,7 +274,7 @@ fn possible_value() { fn not_possible_value() { env::set_var("CLP_TEST_ENV_NPV", "env"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_NPV") @@ -290,7 +290,7 @@ fn not_possible_value() { fn validator() { env::set_var("CLP_TEST_ENV_VDOR", "env"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_VDOR") @@ -316,7 +316,7 @@ fn validator() { fn validator_output() { env::set_var("CLP_TEST_ENV_VO", "42"); - let m = App::new("df") + let m = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_VO") @@ -333,7 +333,7 @@ fn validator_output() { fn validator_invalid() { env::set_var("CLP_TEST_ENV_IV", "env"); - let r = App::new("df") + let r = Command::new("df") .arg( arg!([arg] "some opt") .env("CLP_TEST_ENV_IV") diff --git a/tests/builder/error.rs b/tests/builder/error.rs index f031b51156b..3e4f923fec4 100644 --- a/tests/builder/error.rs +++ b/tests/builder/error.rs @@ -1,6 +1,6 @@ use crate::utils; -use clap::{arg, error::ErrorKind, App, Arg, Error}; +use clap::{arg, error::ErrorKind, Arg, Command, Error}; fn compare_error( err: Error, @@ -29,7 +29,7 @@ USAGE: For more information try --help "; - let app = App::new("test") + let cmd = Command::new("test") .arg( Arg::new("all") .short('a') @@ -52,15 +52,15 @@ For more information try --help .long("no-git-push") .help("Do not push generated commit and tags to git remote"), ); - let mut app = app; + let mut cmd = cmd; let expected_kind = ErrorKind::InvalidValue; - let err = app.error(expected_kind, "Failed for mysterious reasons"); + let err = cmd.error(expected_kind, "Failed for mysterious reasons"); assert!(compare_error(err, expected_kind, MESSAGE, true)); } #[test] fn value_validation_has_newline() { - let m = App::new("test") + let m = Command::new("test") .arg(arg!().help("Network port to use")) .try_get_matches_from(["test", "foo"]) .unwrap(); @@ -78,7 +78,7 @@ fn value_validation_has_newline() { #[test] fn argument_not_found_auto_has_newline() { - let m = App::new("test") + let m = Command::new("test") .arg(arg!([PORT]).help("Network port to use")) .try_get_matches_from(["test"]) .unwrap(); diff --git a/tests/builder/flag_subcommands.rs b/tests/builder/flag_subcommands.rs index fc1b1c2bc95..c5c24983dea 100644 --- a/tests/builder/flag_subcommands.rs +++ b/tests/builder/flag_subcommands.rs @@ -1,12 +1,12 @@ use crate::utils; -use clap::{arg, error::ErrorKind, App, Arg}; +use clap::{arg, error::ErrorKind, Arg, Command}; #[test] fn flag_subcommand_normal() { - let matches = App::new("test") + let matches = Command::new("test") .subcommand( - App::new("some").short_flag('S').long_flag("some").arg( + Command::new("some").short_flag('S').long_flag("some").arg( Arg::new("test") .short('t') .long("test") @@ -22,9 +22,9 @@ fn flag_subcommand_normal() { #[test] fn flag_subcommand_normal_with_alias() { - let matches = App::new("test") + let matches = Command::new("test") .subcommand( - App::new("some") + Command::new("some") .short_flag('S') .long_flag("S") .arg( @@ -44,9 +44,9 @@ fn flag_subcommand_normal_with_alias() { #[test] fn flag_subcommand_short() { - let matches = App::new("test") + let matches = Command::new("test") .subcommand( - App::new("some").short_flag('S').arg( + Command::new("some").short_flag('S').arg( Arg::new("test") .short('t') .long("test") @@ -62,9 +62,9 @@ fn flag_subcommand_short() { #[test] fn flag_subcommand_short_with_args() { - let matches = App::new("test") + let matches = Command::new("test") .subcommand( - App::new("some").short_flag('S').arg( + Command::new("some").short_flag('S').arg( Arg::new("test") .short('t') .long("test") @@ -80,9 +80,9 @@ fn flag_subcommand_short_with_args() { #[test] fn flag_subcommand_short_with_alias() { - let matches = App::new("test") + let matches = Command::new("test") .subcommand( - App::new("some") + Command::new("some") .short_flag('S') .arg( Arg::new("test") @@ -102,8 +102,8 @@ fn flag_subcommand_short_with_alias() { #[test] fn flag_subcommand_short_with_alias_same_as_short_flag() { - let matches = App::new("test") - .subcommand(App::new("some").short_flag('S').short_flag_alias('S')) + let matches = Command::new("test") + .subcommand(Command::new("some").short_flag('S').short_flag_alias('S')) .try_get_matches_from(vec!["myprog", "-S"]) .unwrap(); assert_eq!(matches.subcommand_name().unwrap(), "some"); @@ -111,8 +111,12 @@ fn flag_subcommand_short_with_alias_same_as_short_flag() { #[test] fn flag_subcommand_long_with_alias_same_as_long_flag() { - let matches = App::new("test") - .subcommand(App::new("some").long_flag("sync").long_flag_alias("sync")) + let matches = Command::new("test") + .subcommand( + Command::new("some") + .long_flag("sync") + .long_flag_alias("sync"), + ) .try_get_matches_from(vec!["myprog", "--sync"]) .unwrap(); assert_eq!(matches.subcommand_name().unwrap(), "some"); @@ -120,8 +124,8 @@ fn flag_subcommand_long_with_alias_same_as_long_flag() { #[test] fn flag_subcommand_short_with_aliases_vis_and_hidden() { - let app = App::new("test").subcommand( - App::new("some") + let cmd = Command::new("test").subcommand( + Command::new("some") .short_flag('S') .arg( Arg::new("test") @@ -132,24 +136,24 @@ fn flag_subcommand_short_with_aliases_vis_and_hidden() { .visible_short_flag_aliases(&['M', 'B']) .short_flag_alias('C'), ); - let app1 = app.clone(); + let app1 = cmd.clone(); let matches1 = app1.try_get_matches_from(vec!["test", "-M"]).unwrap(); assert_eq!(matches1.subcommand_name().unwrap(), "some"); - let app2 = app.clone(); + let app2 = cmd.clone(); let matches2 = app2.try_get_matches_from(vec!["test", "-C"]).unwrap(); assert_eq!(matches2.subcommand_name().unwrap(), "some"); - let app3 = app.clone(); + let app3 = cmd.clone(); let matches3 = app3.try_get_matches_from(vec!["test", "-B"]).unwrap(); assert_eq!(matches3.subcommand_name().unwrap(), "some"); } #[test] fn flag_subcommand_short_with_aliases() { - let matches = App::new("test") + let matches = Command::new("test") .subcommand( - App::new("some") + Command::new("some") .short_flag('S') .arg( Arg::new("test") @@ -169,9 +173,9 @@ fn flag_subcommand_short_with_aliases() { #[test] #[should_panic] fn flag_subcommand_short_with_alias_hyphen() { - let _ = App::new("test") + let _ = Command::new("test") .subcommand( - App::new("some") + Command::new("some") .short_flag('S') .arg( Arg::new("test") @@ -188,9 +192,9 @@ fn flag_subcommand_short_with_alias_hyphen() { #[test] #[should_panic] fn flag_subcommand_short_with_aliases_hyphen() { - let _ = App::new("test") + let _ = Command::new("test") .subcommand( - App::new("some") + Command::new("some") .short_flag('S') .arg( Arg::new("test") @@ -206,9 +210,9 @@ fn flag_subcommand_short_with_aliases_hyphen() { #[test] fn flag_subcommand_short_after_long_arg() { - let m = App::new("pacman") + let m = Command::new("pacman") .subcommand( - App::new("sync") + Command::new("sync") .short_flag('S') .arg(Arg::new("clean").short('c')), ) @@ -223,9 +227,9 @@ fn flag_subcommand_short_after_long_arg() { #[test] fn flag_subcommand_long() { - let matches = App::new("test") + let matches = Command::new("test") .subcommand( - App::new("some").long_flag("some").arg( + Command::new("some").long_flag("some").arg( Arg::new("test") .short('t') .long("test") @@ -241,9 +245,9 @@ fn flag_subcommand_long() { #[test] fn flag_subcommand_long_with_alias() { - let matches = App::new("test") + let matches = Command::new("test") .subcommand( - App::new("some") + Command::new("some") .long_flag("some") .arg( Arg::new("test") @@ -262,9 +266,9 @@ fn flag_subcommand_long_with_alias() { #[test] fn flag_subcommand_long_with_aliases() { - let matches = App::new("test") + let matches = Command::new("test") .subcommand( - App::new("some") + Command::new("some") .long_flag("some") .arg( Arg::new("test") @@ -283,15 +287,15 @@ fn flag_subcommand_long_with_aliases() { #[test] fn flag_subcommand_multiple() { - let matches = App::new("test") + let matches = Command::new("test") .subcommand( - App::new("some") + Command::new("some") .short_flag('S') .long_flag("some") .arg(arg!(-f --flag "some flag")) .arg(arg!(-p --print "print something")) .subcommand( - App::new("result") + Command::new("result") .short_flag('R') .long_flag("result") .arg(arg!(-f --flag "some flag")) @@ -314,8 +318,8 @@ fn flag_subcommand_multiple() { #[test] #[should_panic = "the \'-f\' short flag for the \'test\' argument conflicts with the short flag for \'some\' subcommand"] fn flag_subcommand_short_conflict_with_arg() { - let _ = App::new("test") - .subcommand(App::new("some").short_flag('f').long_flag("some")) + let _ = Command::new("test") + .subcommand(Command::new("some").short_flag('f').long_flag("some")) .arg(Arg::new("test").short('f')) .try_get_matches_from(vec!["myprog", "-f"]) .unwrap(); @@ -325,9 +329,9 @@ fn flag_subcommand_short_conflict_with_arg() { #[test] #[should_panic = "the \'-f\' short flag is specified for both \'some\' and \'result\' subcommands"] fn flag_subcommand_short_conflict_with_alias() { - let _ = App::new("test") - .subcommand(App::new("some").short_flag('f').long_flag("some")) - .subcommand(App::new("result").short_flag('t').short_flag_alias('f')) + let _ = Command::new("test") + .subcommand(Command::new("some").short_flag('f').long_flag("some")) + .subcommand(Command::new("result").short_flag('t').short_flag_alias('f')) .try_get_matches_from(vec!["myprog", "-f"]) .unwrap(); } @@ -336,9 +340,13 @@ fn flag_subcommand_short_conflict_with_alias() { #[test] #[should_panic = "the \'--flag\' long flag is specified for both \'some\' and \'result\' subcommands"] fn flag_subcommand_long_conflict_with_alias() { - let _ = App::new("test") - .subcommand(App::new("some").long_flag("flag")) - .subcommand(App::new("result").long_flag("test").long_flag_alias("flag")) + let _ = Command::new("test") + .subcommand(Command::new("some").long_flag("flag")) + .subcommand( + Command::new("result") + .long_flag("test") + .long_flag_alias("flag"), + ) .try_get_matches_from(vec!["myprog", "--flag"]) .unwrap(); } @@ -347,8 +355,8 @@ fn flag_subcommand_long_conflict_with_alias() { #[test] #[should_panic = "the \'-f\' short flag for the \'test\' argument conflicts with the short flag for \'some\' subcommand"] fn flag_subcommand_short_conflict_with_arg_alias() { - let _ = App::new("test") - .subcommand(App::new("some").short_flag('f').long_flag("some")) + let _ = Command::new("test") + .subcommand(Command::new("some").short_flag('f').long_flag("some")) .arg(Arg::new("test").short('t').short_alias('f')) .try_get_matches_from(vec!["myprog", "-f"]) .unwrap(); @@ -358,8 +366,8 @@ fn flag_subcommand_short_conflict_with_arg_alias() { #[test] #[should_panic = "the \'--some\' long flag for the \'test\' argument conflicts with the short flag for \'some\' subcommand"] fn flag_subcommand_long_conflict_with_arg_alias() { - let _ = App::new("test") - .subcommand(App::new("some").short_flag('f').long_flag("some")) + let _ = Command::new("test") + .subcommand(Command::new("some").short_flag('f').long_flag("some")) .arg(Arg::new("test").long("test").alias("some")) .try_get_matches_from(vec!["myprog", "--some"]) .unwrap(); @@ -369,8 +377,8 @@ fn flag_subcommand_long_conflict_with_arg_alias() { #[test] #[should_panic = "the \'--flag\' long flag for the \'flag\' argument conflicts with the short flag for \'some\' subcommand"] fn flag_subcommand_long_conflict_with_arg() { - let _ = App::new("test") - .subcommand(App::new("some").short_flag('a').long_flag("flag")) + let _ = Command::new("test") + .subcommand(Command::new("some").short_flag('a').long_flag("flag")) .arg(Arg::new("flag").long("flag")) .try_get_matches_from(vec!["myprog", "--flag"]) .unwrap(); @@ -378,25 +386,25 @@ fn flag_subcommand_long_conflict_with_arg() { #[test] fn flag_subcommand_conflict_with_help() { - let _ = App::new("test") - .subcommand(App::new("help").short_flag('h').long_flag("help")) + let _ = Command::new("test") + .subcommand(Command::new("help").short_flag('h').long_flag("help")) .try_get_matches_from(vec!["myprog", "--help"]) .unwrap(); } #[test] fn flag_subcommand_conflict_with_version() { - let _ = App::new("test") - .subcommand(App::new("ver").short_flag('V').long_flag("version")) + let _ = Command::new("test") + .subcommand(Command::new("ver").short_flag('V').long_flag("version")) .try_get_matches_from(vec!["myprog", "--version"]) .unwrap(); } #[test] fn flag_subcommand_long_infer_pass() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test").long_flag("test")) + .subcommand(Command::new("test").long_flag("test")) .try_get_matches_from(vec!["prog", "--te"]) .unwrap(); assert_eq!(m.subcommand_name(), Some("test")); @@ -405,10 +413,10 @@ fn flag_subcommand_long_infer_pass() { #[cfg(not(feature = "suggestions"))] #[test] fn flag_subcommand_long_infer_fail() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test").long_flag("test")) - .subcommand(App::new("temp").long_flag("temp")) + .subcommand(Command::new("test").long_flag("test")) + .subcommand(Command::new("temp").long_flag("temp")) .try_get_matches_from(vec!["prog", "--te"]); assert!(m.is_err(), "{:#?}", m.unwrap()); assert_eq!(m.unwrap_err().kind(), ErrorKind::UnknownArgument); @@ -417,10 +425,10 @@ fn flag_subcommand_long_infer_fail() { #[cfg(feature = "suggestions")] #[test] fn flag_subcommand_long_infer_fail() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test").long_flag("test")) - .subcommand(App::new("temp").long_flag("temp")) + .subcommand(Command::new("test").long_flag("test")) + .subcommand(Command::new("temp").long_flag("temp")) .try_get_matches_from(vec!["prog", "--te"]); assert!(m.is_err(), "{:#?}", m.unwrap()); assert_eq!(m.unwrap_err().kind(), ErrorKind::UnknownArgument); @@ -428,10 +436,10 @@ fn flag_subcommand_long_infer_fail() { #[test] fn flag_subcommand_long_infer_pass_close() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test").long_flag("test")) - .subcommand(App::new("temp").long_flag("temp")) + .subcommand(Command::new("test").long_flag("test")) + .subcommand(Command::new("temp").long_flag("temp")) .try_get_matches_from(vec!["prog", "--tes"]) .unwrap(); assert_eq!(m.subcommand_name(), Some("test")); @@ -439,11 +447,11 @@ fn flag_subcommand_long_infer_pass_close() { #[test] fn flag_subcommand_long_infer_exact_match() { - let m = App::new("prog") + let m = Command::new("prog") .infer_subcommands(true) - .subcommand(App::new("test").long_flag("test")) - .subcommand(App::new("testa").long_flag("testa")) - .subcommand(App::new("testb").long_flag("testb")) + .subcommand(Command::new("test").long_flag("test")) + .subcommand(Command::new("testa").long_flag("testa")) + .subcommand(Command::new("testb").long_flag("testb")) .try_get_matches_from(vec!["prog", "--test"]) .unwrap(); assert_eq!(m.subcommand_name(), Some("test")); @@ -463,7 +471,7 @@ OPTIONS: #[test] fn flag_subcommand_long_short_normal_usage_string() { - let app = App::new("pacman") + let cmd = Command::new("pacman") .about("package manager utility") .version("5.2.1") .subcommand_required(true) @@ -472,7 +480,7 @@ fn flag_subcommand_long_short_normal_usage_string() { // // Only a few of its arguments are implemented below. .subcommand( - App::new("query") + Command::new("query") .short_flag('Q') .long_flag("query") .about("Query the package database.") @@ -496,7 +504,7 @@ fn flag_subcommand_long_short_normal_usage_string() { ), ); assert!(utils::compare_output( - app, + cmd, "pacman -Qh", FLAG_SUBCOMMAND_HELP, false @@ -517,7 +525,7 @@ OPTIONS: #[test] fn flag_subcommand_long_normal_usage_string() { - let app = App::new("pacman") + let cmd = Command::new("pacman") .about("package manager utility") .version("5.2.1") .subcommand_required(true) @@ -526,7 +534,7 @@ fn flag_subcommand_long_normal_usage_string() { // // Only a few of its arguments are implemented below. .subcommand( - App::new("query") + Command::new("query") .long_flag("query") .about("Query the package database.") .arg( @@ -549,7 +557,7 @@ fn flag_subcommand_long_normal_usage_string() { ), ); assert!(utils::compare_output( - app, + cmd, "pacman query --help", FLAG_SUBCOMMAND_NO_SHORT_HELP, false @@ -570,7 +578,7 @@ OPTIONS: #[test] fn flag_subcommand_short_normal_usage_string() { - let app = App::new("pacman") + let cmd = Command::new("pacman") .about("package manager utility") .version("5.2.1") .subcommand_required(true) @@ -579,7 +587,7 @@ fn flag_subcommand_short_normal_usage_string() { // // Only a few of its arguments are implemented below. .subcommand( - App::new("query") + Command::new("query") .short_flag('Q') .about("Query the package database.") .arg( @@ -602,7 +610,7 @@ fn flag_subcommand_short_normal_usage_string() { ), ); assert!(utils::compare_output( - app, + cmd, "pacman query --help", FLAG_SUBCOMMAND_NO_LONG_HELP, false diff --git a/tests/builder/flags.rs b/tests/builder/flags.rs index 112849374ea..3d782ff37d0 100644 --- a/tests/builder/flags.rs +++ b/tests/builder/flags.rs @@ -1,5 +1,5 @@ use crate::utils; -use clap::{arg, App, Arg}; +use clap::{arg, Arg, Command}; const USE_FLAG_AS_ARGUMENT: &str = "error: Found argument '--another-flag' which wasn't expected, or isn't valid in this context @@ -14,7 +14,7 @@ For more information try --help #[test] fn flag_using_short() { - let m = App::new("flag") + let m = Command::new("flag") .args(&[ arg!(-f --flag "some flag"), arg!(-c --color "some other flag"), @@ -27,7 +27,7 @@ fn flag_using_short() { #[test] fn lots_o_flags_sep() { - let r = App::new("opts") + let r = Command::new("opts") .arg(arg!(o: -o ... "some flag")) .try_get_matches_from(vec![ "", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", "-o", @@ -61,7 +61,7 @@ fn lots_o_flags_sep() { #[test] fn lots_o_flags_combined() { - let r = App::new("opts") + let r = Command::new("opts") .arg(arg!(o: -o ... "some flag")) .try_get_matches_from(vec![ "", @@ -79,7 +79,7 @@ fn lots_o_flags_combined() { #[test] fn flag_using_long() { - let m = App::new("flag") + let m = Command::new("flag") .args(&[arg!(--flag "some flag"), arg!(--color "some other flag")]) .try_get_matches_from(vec!["", "--flag", "--color"]) .unwrap(); @@ -91,7 +91,7 @@ fn flag_using_long() { fn flag_using_long_with_literals() { use clap::error::ErrorKind; - let m = App::new("flag") + let m = Command::new("flag") .arg(Arg::new("rainbow").long("rainbow")) .try_get_matches_from(vec!["", "--rainbow=false"]); assert!(m.is_err(), "{:#?}", m.unwrap()); @@ -100,7 +100,7 @@ fn flag_using_long_with_literals() { #[test] fn flag_using_mixed() { - let m = App::new("flag") + let m = Command::new("flag") .args(&[ arg!(-f --flag "some flag"), arg!(-c --color "some other flag"), @@ -110,7 +110,7 @@ fn flag_using_mixed() { assert!(m.is_present("flag")); assert!(m.is_present("color")); - let m = App::new("flag") + let m = Command::new("flag") .args(&[ arg!(-f --flag "some flag"), arg!(-c --color "some other flag"), @@ -123,7 +123,7 @@ fn flag_using_mixed() { #[test] fn multiple_flags_in_single() { - let m = App::new("multe_flags") + let m = Command::new("multe_flags") .args(&[ arg!(-f --flag "some flag"), arg!(-c --color "some other flag"), @@ -138,30 +138,30 @@ fn multiple_flags_in_single() { #[test] fn issue_1284_argument_in_flag_style() { - let app = App::new("mycat") + let cmd = Command::new("mycat") .arg(Arg::new("filename")) .arg(Arg::new("a-flag").long("a-flag")); - let m = app + let m = cmd .clone() .try_get_matches_from(vec!["", "--", "--another-flag"]) .unwrap(); assert_eq!(m.value_of("filename"), Some("--another-flag")); - let m = app + let m = cmd .clone() .try_get_matches_from(vec!["", "--a-flag"]) .unwrap(); assert!(m.is_present("a-flag")); - let m = app + let m = cmd .clone() .try_get_matches_from(vec!["", "--", "--a-flag"]) .unwrap(); assert_eq!(m.value_of("filename"), Some("--a-flag")); assert!(utils::compare_output( - app, + cmd, "mycat --another-flag", USE_FLAG_AS_ARGUMENT, true @@ -180,10 +180,10 @@ USAGE: For more information try --help "; - let app = App::new("test").arg(Arg::new("arg").takes_value(true).required(true)); + let cmd = Command::new("test").arg(Arg::new("arg").takes_value(true).required(true)); assert!(utils::compare_output( - app, + cmd, "test -----", MULTIPLE_DASHES, true diff --git a/tests/builder/global_args.rs b/tests/builder/global_args.rs index c04468d5b80..d8024089664 100644 --- a/tests/builder/global_args.rs +++ b/tests/builder/global_args.rs @@ -1,8 +1,8 @@ -use clap::{arg, App, Arg}; +use clap::{arg, Arg, Command}; #[test] fn issue_1076() { - let mut app = App::new("myprog") + let mut cmd = Command::new("myprog") .arg( Arg::new("GLOBAL_ARG") .long("global-arg") @@ -18,19 +18,19 @@ fn issue_1076() { .global(true) .takes_value(true), ) - .subcommand(App::new("outer").subcommand(App::new("inner"))); - let _ = app.try_get_matches_from_mut(vec!["myprog"]); - let _ = app.try_get_matches_from_mut(vec!["myprog"]); - let _ = app.try_get_matches_from_mut(vec!["myprog"]); + .subcommand(Command::new("outer").subcommand(Command::new("inner"))); + let _ = cmd.try_get_matches_from_mut(vec!["myprog"]); + let _ = cmd.try_get_matches_from_mut(vec!["myprog"]); + let _ = cmd.try_get_matches_from_mut(vec!["myprog"]); } #[test] fn propagate_global_arg_in_subcommand_to_subsubcommand_1385() { - let m1 = App::new("foo") + let m1 = Command::new("foo") .subcommand( - App::new("sub1") + Command::new("sub1") .arg(Arg::new("arg1").long("arg1").takes_value(true).global(true)) - .subcommand(App::new("sub1a")), + .subcommand(Command::new("sub1a")), ) .try_get_matches_from(&["foo", "sub1", "--arg1", "v1", "sub1a"]) .unwrap(); @@ -47,17 +47,17 @@ fn propagate_global_arg_in_subcommand_to_subsubcommand_1385() { #[test] fn propagate_global_arg_to_subcommand_in_subsubcommand_2053() { - let m = App::new("opts") + let m = Command::new("opts") .arg(arg!(--"global-flag").global(true)) .arg(arg!(--"global-str" ).required(false).global(true)) .subcommand( - App::new("test") + Command::new("test") .arg(arg!(--"sub-flag").global(true)) .arg(arg!(--"sub-str" ).required(false).global(true)) - .subcommand(App::new("test")), + .subcommand(Command::new("test")), ) .try_get_matches_from(&[ - "app", + "cmd", "test", "test", "--global-flag", @@ -76,12 +76,12 @@ fn propagate_global_arg_to_subcommand_in_subsubcommand_2053() { #[test] fn global_arg_available_in_subcommand() { - let m = App::new("opt") + let m = Command::new("opt") .args(&[ Arg::new("global").global(true).long("global"), Arg::new("not").global(false).long("not"), ]) - .subcommand(App::new("ping")) + .subcommand(Command::new("ping")) .try_get_matches_from(&["opt", "ping", "--global"]) .unwrap(); @@ -91,15 +91,19 @@ fn global_arg_available_in_subcommand() { #[test] fn deeply_nested_discovery() { - let app = App::new("a").arg(arg!(--"long-a").global(true)).subcommand( - App::new("b").arg(arg!(--"long-b").global(true)).subcommand( - App::new("c") - .arg(arg!(--"long-c").global(true)) - .subcommand(App::new("d")), - ), - ); + let cmd = Command::new("a") + .arg(arg!(--"long-a").global(true)) + .subcommand( + Command::new("b") + .arg(arg!(--"long-b").global(true)) + .subcommand( + Command::new("c") + .arg(arg!(--"long-c").global(true)) + .subcommand(Command::new("d")), + ), + ); - let m = app + let m = cmd .try_get_matches_from(["a", "b", "c", "d", "--long-a", "--long-b", "--long-c"]) .unwrap(); assert!(m.is_present("long-a")); diff --git a/tests/builder/grouped_values.rs b/tests/builder/grouped_values.rs index fb88ac37c65..622e9c93e87 100644 --- a/tests/builder/grouped_values.rs +++ b/tests/builder/grouped_values.rs @@ -1,10 +1,10 @@ #![cfg(feature = "unstable-grouped")] -use clap::{App, Arg}; +use clap::{Arg, Command}; #[test] fn grouped_value_works() { - let m = App::new("cli") + let m = Command::new("cli") .arg( Arg::new("option") .long("option") @@ -34,7 +34,7 @@ fn grouped_value_works() { #[test] fn issue_1026() { - let m = App::new("cli") + let m = Command::new("cli") .arg(Arg::new("server").short('s').takes_value(true)) .arg(Arg::new("user").short('u').takes_value(true)) .arg( @@ -63,7 +63,7 @@ fn issue_1026() { #[test] fn grouped_value_long_flag_delimiter() { - let m = App::new("myapp") + let m = Command::new("myapp") .arg( Arg::new("option") .long("option") @@ -93,7 +93,7 @@ fn grouped_value_long_flag_delimiter() { #[test] fn grouped_value_short_flag_delimiter() { - let m = App::new("myapp") + let m = Command::new("myapp") .arg( Arg::new("option") .short('o') @@ -113,7 +113,7 @@ fn grouped_value_short_flag_delimiter() { #[test] fn grouped_value_positional_arg() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("pos") .help("multiple positionals") @@ -133,7 +133,7 @@ fn grouped_value_positional_arg() { #[test] fn grouped_value_multiple_positional_arg() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg(Arg::new("pos1").help("multiple positionals")) .arg( Arg::new("pos2") @@ -154,7 +154,7 @@ fn grouped_value_multiple_positional_arg() { #[test] fn grouped_value_multiple_positional_arg_last_multiple() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg(Arg::new("pos1").help("multiple positionals")) .arg( Arg::new("pos2") @@ -176,7 +176,7 @@ fn grouped_value_multiple_positional_arg_last_multiple() { #[test] fn issue_1374() { - let app = App::new("MyApp").arg( + let cmd = Command::new("MyApp").arg( Arg::new("input") .takes_value(true) .long("input") @@ -184,13 +184,13 @@ fn issue_1374() { .min_values(0) .multiple_occurrences(true), ); - let matches = app + let matches = cmd .clone() .try_get_matches_from(&["MyApp", "--input", "a", "b", "c", "--input", "d"]) .unwrap(); let vs = matches.values_of("input").unwrap(); assert_eq!(vs.collect::>(), vec!["a", "b", "c", "d"]); - let matches = app + let matches = cmd .clone() .try_get_matches_from(&["MyApp", "--input", "a", "b", "--input", "c", "d"]) .unwrap(); @@ -200,7 +200,7 @@ fn issue_1374() { #[test] fn issue_2171() { - let schema = App::new("ripgrep#1701 reproducer") + let schema = Command::new("ripgrep#1701 reproducer") .args_override_self(true) .arg(Arg::new("pretty").short('p').long("pretty")) .arg(Arg::new("search_zip").short('z').long("search-zip")); diff --git a/tests/builder/groups.rs b/tests/builder/groups.rs index a52549f87de..a4faef422a7 100644 --- a/tests/builder/groups.rs +++ b/tests/builder/groups.rs @@ -1,6 +1,6 @@ use crate::utils; -use clap::{arg, error::ErrorKind, App, Arg, ArgGroup}; +use clap::{arg, error::ErrorKind, Arg, ArgGroup, Command}; static REQ_GROUP_USAGE: &str = "error: The following required arguments were not provided: @@ -31,7 +31,7 @@ For more information try --help #[test] fn required_group_missing_arg() { - let result = App::new("group") + let result = Command::new("group") .arg(arg!(-f --flag "some flag")) .arg(arg!( -c --color "some other flag")) .group(ArgGroup::new("req").args(&["flag", "color"]).required(true)) @@ -45,7 +45,7 @@ fn required_group_missing_arg() { #[test] #[should_panic = "Argument group 'req' contains non-existent argument"] fn non_existing_arg() { - let _ = App::new("group") + let _ = Command::new("group") .arg(arg!(-f --flag "some flag")) .arg(arg!(-c --color "some other flag")) .group(ArgGroup::new("req").args(&["flg", "color"]).required(true)) @@ -56,7 +56,7 @@ fn non_existing_arg() { #[test] #[should_panic = "Argument group name must be unique\n\n\t'req' is already in use"] fn unique_group_name() { - let _ = App::new("group") + let _ = Command::new("group") .arg(arg!(-f --flag "some flag")) .arg(arg!(-c --color "some other flag")) .group(ArgGroup::new("req").args(&["flag"]).required(true)) @@ -68,7 +68,7 @@ fn unique_group_name() { #[test] #[should_panic = "Argument group name '' must not conflict with argument name"] fn groups_new_of_arg_name() { - let _ = App::new("group") + let _ = Command::new("group") .arg(Arg::new("a").long("a").group("a")) .try_get_matches_from(vec!["", "--a"]); } @@ -77,7 +77,7 @@ fn groups_new_of_arg_name() { #[test] #[should_panic = "Argument group name 'a' must not conflict with argument name"] fn arg_group_new_of_arg_name() { - let _ = App::new("group") + let _ = Command::new("group") .arg(Arg::new("a").long("a").group("a")) .group(ArgGroup::new("a")) .try_get_matches_from(vec!["", "--a"]); @@ -85,7 +85,7 @@ fn arg_group_new_of_arg_name() { #[test] fn group_single_value() { - let res = App::new("group") + let res = Command::new("group") .arg(arg!(-f --flag "some flag")) .arg(arg!(-c --color [color] "some option")) .group(ArgGroup::new("grp").args(&["flag", "color"])) @@ -99,7 +99,7 @@ fn group_single_value() { #[test] fn group_single_flag() { - let res = App::new("group") + let res = Command::new("group") .arg(arg!(-f --flag "some flag")) .arg(arg!(-c --color [color] "some option")) .group(ArgGroup::new("grp").args(&["flag", "color"])) @@ -113,7 +113,7 @@ fn group_single_flag() { #[test] fn group_empty() { - let res = App::new("group") + let res = Command::new("group") .arg(arg!(-f --flag "some flag")) .arg(arg!(-c --color [color] "some option")) .group(ArgGroup::new("grp").args(&["flag", "color"])) @@ -127,7 +127,7 @@ fn group_empty() { #[test] fn group_reqired_flags_empty() { - let result = App::new("group") + let result = Command::new("group") .arg(arg!(-f --flag "some flag")) .arg(arg!(-c --color "some option")) .group(ArgGroup::new("grp").required(true).args(&["flag", "color"])) @@ -139,7 +139,7 @@ fn group_reqired_flags_empty() { #[test] fn group_multi_value_single_arg() { - let res = App::new("group") + let res = Command::new("group") .arg(arg!(-f --flag "some flag")) .arg(arg!(-c --color "some option").multiple_values(true)) .group(ArgGroup::new("grp").args(&["flag", "color"])) @@ -156,7 +156,7 @@ fn group_multi_value_single_arg() { #[test] fn empty_group() { - let r = App::new("empty_group") + let r = Command::new("empty_group") .arg(arg!(-f --flag "some flag")) .group(ArgGroup::new("vers").required(true)) .try_get_matches_from(vec!["empty_prog"]); @@ -167,7 +167,7 @@ fn empty_group() { #[test] fn req_group_usage_string() { - let app = App::new("req_group") + let cmd = Command::new("req_group") .arg(arg!([base] "Base commit")) .arg(arg!( -d --delete "Remove the base commit information" @@ -179,7 +179,7 @@ fn req_group_usage_string() { ); assert!(utils::compare_output( - app, + cmd, "clap-test", REQ_GROUP_USAGE, true @@ -188,7 +188,7 @@ fn req_group_usage_string() { #[test] fn req_group_with_conflict_usage_string() { - let app = App::new("req_group") + let cmd = Command::new("req_group") .arg(arg!([base] "Base commit").conflicts_with("delete")) .arg(arg!( -d --delete "Remove the base commit information" @@ -200,7 +200,7 @@ fn req_group_with_conflict_usage_string() { ); assert!(utils::compare_output( - app, + cmd, "clap-test --delete base", REQ_GROUP_CONFLICT_USAGE, true @@ -209,7 +209,7 @@ fn req_group_with_conflict_usage_string() { #[test] fn req_group_with_conflict_usage_string_only_options() { - let app = App::new("req_group") + let cmd = Command::new("req_group") .arg(arg!(-a --all "All").conflicts_with("delete")) .arg(arg!( -d --delete "Remove the base commit information" @@ -220,7 +220,7 @@ fn req_group_with_conflict_usage_string_only_options() { .required(true), ); assert!(utils::compare_output( - app, + cmd, "clap-test --delete --all", REQ_GROUP_CONFLICT_ONLY_OPTIONS, true @@ -229,7 +229,7 @@ fn req_group_with_conflict_usage_string_only_options() { #[test] fn required_group_multiple_args() { - let result = App::new("group") + let result = Command::new("group") .arg(arg!(-f --flag "some flag")) .arg(arg!(-c --color "some other flag")) .group( @@ -247,7 +247,7 @@ fn required_group_multiple_args() { #[test] fn group_multiple_args_error() { - let result = App::new("group") + let result = Command::new("group") .arg(arg!(-f --flag "some flag")) .arg(arg!(-c --color "some other flag")) .group(ArgGroup::new("req").args(&["flag", "color"])) @@ -270,11 +270,11 @@ ARGS: OPTIONS: -h, --help Print help information "; - let app = App::new("prog") + let cmd = Command::new("prog") .arg(Arg::new("a").value_name("A")) .group(ArgGroup::new("group").arg("a").required(true)); assert!(utils::compare_output( - app, + cmd, "prog --help", GROUP_USAGE_USE_VAL_NAME, false, @@ -283,7 +283,7 @@ OPTIONS: #[test] fn group_acts_like_arg() { - let result = App::new("prog") + let result = Command::new("prog") .arg(Arg::new("debug").long("debug").group("mode")) .arg(Arg::new("verbose").long("verbose").group("mode")) .try_get_matches_from(vec!["prog", "--debug"]); @@ -296,7 +296,7 @@ fn group_acts_like_arg() { /* This is used to be fixed in a hack, we need to find a better way to fix it. #[test] fn issue_1794() { - let app = clap::App::new("hello") + let cmd = clap::Command::new("hello") .bin_name("deno") .arg(Arg::new("option1").long("option1").takes_value(false)) .arg(Arg::new("pos1").takes_value(true)) @@ -307,14 +307,14 @@ fn issue_1794() { .required(true), ); - let m = app.clone().try_get_matches_from(&["app", "pos1", "pos2"]).unwrap(); + let m = cmd.clone().try_get_matches_from(&["cmd", "pos1", "pos2"]).unwrap(); assert_eq!(m.value_of("pos1"), Some("pos1")); assert_eq!(m.value_of("pos2"), Some("pos2")); assert!(!m.is_present("option1")); - let m = app + let m = cmd .clone() - .try_get_matches_from(&["app", "--option1", "positional"]).unwrap(); + .try_get_matches_from(&["cmd", "--option1", "positional"]).unwrap(); assert_eq!(m.value_of("pos1"), None); assert_eq!(m.value_of("pos2"), Some("positional")); assert!(m.is_present("option1")); diff --git a/tests/builder/help.rs b/tests/builder/help.rs index 4c41af6ce89..d07829a26eb 100644 --- a/tests/builder/help.rs +++ b/tests/builder/help.rs @@ -1,6 +1,6 @@ use crate::utils; -use clap::{arg, error::ErrorKind, App, Arg, ArgGroup, PossibleValue}; +use clap::{arg, error::ErrorKind, Arg, ArgGroup, Command, PossibleValue}; static REQUIRE_DELIM_HELP: &str = "test 1.3 Kevin K. @@ -334,7 +334,7 @@ OPTIONS: -V, --version Print version information "; -static ISSUE_777: &str = "A app with a crazy very long long +static ISSUE_777: &str = "A cmd with a crazy very long long long name hahaha 1.0 Some Very Long Name and crazy long email @@ -606,8 +606,8 @@ SUBCOMMANDS: sub short about sub "; -fn setup() -> App<'static> { - App::new("test") +fn setup() -> Command<'static> { + Command::new("test") .author("Kevin K.") .about("tests stuff") .version("1.3") @@ -645,7 +645,7 @@ fn help_no_subcommand() { fn help_subcommand() { let m = setup() .subcommand( - App::new("test") + Command::new("test") .about("tests things") .arg(arg!(-v --verbose "with verbosity")), ) @@ -657,7 +657,7 @@ fn help_subcommand() { #[test] fn req_last_arg_usage() { - let app = App::new("example") + let cmd = Command::new("example") .version("1.0") .arg( Arg::new("FIRST") @@ -673,7 +673,7 @@ fn req_last_arg_usage() { .last(true), ); assert!(utils::compare_output( - app, + cmd, "example --help", LAST_ARG_REQ_MULT, false @@ -682,7 +682,7 @@ fn req_last_arg_usage() { #[test] fn args_with_last_usage() { - let app = App::new("flamegraph") + let cmd = Command::new("flamegraph") .version("0.1") .trailing_var_arg(true) .arg( @@ -720,7 +720,7 @@ fn args_with_last_usage() { .value_name("ARGS"), ); assert!(utils::compare_output( - app, + cmd, "flamegraph --help", LAST_ARG_USAGE, false @@ -763,19 +763,19 @@ fn complex_help_output() { #[test] fn after_and_before_help_output() { - let app = App::new("clap-test") + let cmd = Command::new("clap-test") .version("v1.4.8") .about("tests clap library") .before_help("some text that comes before the help") .after_help("some text that comes after the help"); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "clap-test -h", AFTER_HELP, false )); assert!(utils::compare_output( - app, + cmd, "clap-test --help", AFTER_HELP, false @@ -784,7 +784,7 @@ fn after_and_before_help_output() { #[test] fn after_and_before_long_help_output() { - let app = App::new("clap-test") + let cmd = Command::new("clap-test") .version("v1.4.8") .about("tests clap library") .before_help("some text that comes before the help") @@ -792,13 +792,13 @@ fn after_and_before_long_help_output() { .before_long_help("some longer text that comes before the help") .after_long_help("some longer text that comes after the help"); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "clap-test --help", AFTER_LONG_HELP, false )); assert!(utils::compare_output( - app, + cmd, "clap-test -h", AFTER_HELP, false @@ -807,9 +807,9 @@ fn after_and_before_long_help_output() { #[test] fn multi_level_sc_help() { - let app = App::new("ctest").subcommand( - App::new("subcmd").subcommand( - App::new("multi") + let cmd = Command::new("ctest").subcommand( + Command::new("subcmd").subcommand( + Command::new("multi") .about("tests subcommands") .author("Kevin K. ") .version("0.1") @@ -827,7 +827,7 @@ fn multi_level_sc_help() { ), ); assert!(utils::compare_output( - app, + cmd, "ctest help subcmd multi", MULTI_SC_HELP, false @@ -836,9 +836,11 @@ fn multi_level_sc_help() { #[test] fn no_wrap_help() { - let app = App::new("ctest").term_width(0).override_help(MULTI_SC_HELP); + let cmd = Command::new("ctest") + .term_width(0) + .override_help(MULTI_SC_HELP); assert!(utils::compare_output( - app, + cmd, "ctest --help", &format!("{}\n", MULTI_SC_HELP), false @@ -847,9 +849,9 @@ fn no_wrap_help() { #[test] fn no_wrap_default_help() { - let app = App::new("ctest").version("1.0").term_width(0); + let cmd = Command::new("ctest").version("1.0").term_width(0); assert!(utils::compare_output( - app, + cmd, "ctest --help", DEFAULT_HELP, false @@ -882,7 +884,7 @@ OPTIONS: --no-git-push Do not push generated commit and tags to git remote "; - let app = App::new("test") + let cmd = Command::new("test") .term_width(67) .arg( Arg::new("all") @@ -906,7 +908,7 @@ OPTIONS: .help("Do not push generated commit and tags to git remote"), ); assert!(utils::compare_output( - app, + cmd, "test --help", WRAPPED_HELP, false @@ -931,7 +933,7 @@ OPTIONS: --no-git-push Do not push generated commit and tags to git remote "; - let app = App::new("test") + let cmd = Command::new("test") .term_width(68) .arg( Arg::new("all") @@ -955,7 +957,7 @@ OPTIONS: .help("Do not push generated commit and tags to git remote"), ); assert!(utils::compare_output( - app, + cmd, "test --help", UNWRAPPED_HELP, false @@ -975,7 +977,7 @@ fn complex_subcommand_help_output() { #[test] fn issue_626_unicode_cutoff() { - let app = App::new("ctest").version("0.1").term_width(70).arg( + let cmd = Command::new("ctest").version("0.1").term_width(70).arg( Arg::new("cafe") .short('c') .long("cafe") @@ -991,7 +993,7 @@ fn issue_626_unicode_cutoff() { .takes_value(true), ); assert!(utils::compare_output( - app, + cmd, "ctest --help", ISSUE_626_CUTOFF, false @@ -1000,7 +1002,7 @@ fn issue_626_unicode_cutoff() { #[test] fn hide_possible_vals() { - let app = App::new("ctest") + let cmd = Command::new("ctest") .version("0.1") .arg( Arg::new("pos") @@ -1022,7 +1024,7 @@ fn hide_possible_vals() { .takes_value(true), ); assert!(utils::compare_output( - app, + cmd, "ctest --help", HIDE_POS_VALS, false @@ -1031,7 +1033,7 @@ fn hide_possible_vals() { #[test] fn hide_single_possible_val() { - let app = App::new("ctest") + let cmd = Command::new("ctest") .version("0.1") .arg( Arg::new("pos") @@ -1052,7 +1054,7 @@ fn hide_single_possible_val() { .takes_value(true), ); assert!(utils::compare_output( - app, + cmd, "ctest --help", HIDE_POS_VALS, false @@ -1061,7 +1063,7 @@ fn hide_single_possible_val() { #[test] fn issue_626_panic() { - let app = App::new("ctest") + let cmd = Command::new("ctest") .version("0.1") .term_width(52) .arg(Arg::new("cafe") @@ -1073,7 +1075,7 @@ fn issue_626_panic() { Le café est souvent une contribution majeure aux exportations des régions productrices.") .takes_value(true)); assert!(utils::compare_output( - app, + cmd, "ctest --help", ISSUE_626_PANIC, false @@ -1083,7 +1085,7 @@ fn issue_626_panic() { #[test] fn issue_626_variable_panic() { for i in 10..320 { - let _ = App::new("ctest") + let _ = Command::new("ctest") .version("0.1") .term_width(i) .arg(Arg::new("cafe") @@ -1100,9 +1102,9 @@ fn issue_626_variable_panic() { #[test] fn final_word_wrapping() { - let app = App::new("ctest").version("0.1").term_width(24); + let cmd = Command::new("ctest").version("0.1").term_width(24); assert!(utils::compare_output( - app, + cmd, "ctest --help", FINAL_WORD_WRAPPING, false @@ -1111,7 +1113,7 @@ fn final_word_wrapping() { #[test] fn wrapping_newline_chars() { - let app = App::new("ctest") + let cmd = Command::new("ctest") .version("0.1") .term_width(60) .arg(Arg::new("mode").help( @@ -1120,7 +1122,7 @@ fn wrapping_newline_chars() { m, med, medium Copy-friendly, 8 characters, contains symbols.\n", )); assert!(utils::compare_output( - app, + cmd, "ctest --help", WRAPPING_NEWLINE_CHARS, false @@ -1129,7 +1131,7 @@ fn wrapping_newline_chars() { #[test] fn wrapping_newline_variables() { - let app = App::new("ctest") + let cmd = Command::new("ctest") .version("0.1") .term_width(60) .arg(Arg::new("mode").help( @@ -1138,7 +1140,7 @@ fn wrapping_newline_variables() { m, med, medium Copy-friendly, 8 characters, contains symbols.{n}", )); assert!(utils::compare_output( - app, + cmd, "ctest --help", WRAPPING_NEWLINE_CHARS, false @@ -1147,13 +1149,13 @@ fn wrapping_newline_variables() { #[test] fn old_newline_chars() { - let app = App::new("ctest").version("0.1").arg( + let cmd = Command::new("ctest").version("0.1").arg( Arg::new("mode") .short('m') .help("Some help with some wrapping\n(Defaults to something)"), ); assert!(utils::compare_output( - app, + cmd, "ctest --help", OLD_NEWLINE_CHARS, false @@ -1162,13 +1164,13 @@ fn old_newline_chars() { #[test] fn old_newline_variables() { - let app = App::new("ctest").version("0.1").arg( + let cmd = Command::new("ctest").version("0.1").arg( Arg::new("mode") .short('m') .help("Some help with some wrapping{n}(Defaults to something)"), ); assert!(utils::compare_output( - app, + cmd, "ctest --help", OLD_NEWLINE_CHARS, false @@ -1179,7 +1181,7 @@ fn old_newline_variables() { fn issue_688_hide_pos_vals() { let filter_values = ["Nearest", "Linear", "Cubic", "Gaussian", "Lanczos3"]; - let app1 = App::new("ctest") + let app1 = Command::new("ctest") .version("0.1") .term_width(120) .hide_possible_values(true) @@ -1196,7 +1198,7 @@ fn issue_688_hide_pos_vals() { false )); - let app2 = App::new("ctest") + let app2 = Command::new("ctest") .version("0.1") .term_width(120) .arg(Arg::new("filter") @@ -1212,7 +1214,7 @@ fn issue_688_hide_pos_vals() { false )); - let app3 = App::new("ctest") + let app3 = Command::new("ctest") .version("0.1") .term_width(120) .arg(Arg::new("filter") @@ -1230,7 +1232,7 @@ fn issue_688_hide_pos_vals() { #[test] fn issue_702_multiple_values() { - let app = App::new("myapp") + let cmd = Command::new("myapp") .version("1.0") .author("foo") .about("bar") @@ -1263,12 +1265,12 @@ fn issue_702_multiple_values() { .multiple_values(true) .takes_value(true), ); - assert!(utils::compare_output(app, "myapp --help", ISSUE_702, false)); + assert!(utils::compare_output(cmd, "myapp --help", ISSUE_702, false)); } #[test] fn long_about() { - let app = App::new("myapp") + let cmd = Command::new("myapp") .version("1.0") .author("foo") .about("bar") @@ -1277,7 +1279,7 @@ fn long_about() { ) .arg(Arg::new("arg1").help("some option")); assert!(utils::compare_output( - app, + cmd, "myapp --help", LONG_ABOUT, false @@ -1286,7 +1288,7 @@ fn long_about() { #[test] fn issue_760() { - let app = App::new("ctest") + let cmd = Command::new("ctest") .version("0.1") .arg( Arg::new("option") @@ -1304,12 +1306,12 @@ fn issue_760() { .long("opt") .takes_value(true), ); - assert!(utils::compare_output(app, "ctest --help", ISSUE_760, false)); + assert!(utils::compare_output(cmd, "ctest --help", ISSUE_760, false)); } #[test] fn issue_1571() { - let app = App::new("hello").arg( + let cmd = Command::new("hello").arg( Arg::new("name") .long("package") .short('p') @@ -1318,7 +1320,7 @@ fn issue_1571() { .multiple_values(true), ); assert!(utils::compare_output( - app, + cmd, "hello --help", "hello @@ -1335,7 +1337,7 @@ OPTIONS: #[test] fn ripgrep_usage() { - let app = App::new("ripgrep").version("0.5").override_usage( + let cmd = Command::new("ripgrep").version("0.5").override_usage( "rg [OPTIONS] [ ...] rg [OPTIONS] [-e PATTERN | -f FILE ]... [ ...] rg [OPTIONS] --files [ ...] @@ -1343,7 +1345,7 @@ fn ripgrep_usage() { ); assert!(utils::compare_output( - app, + cmd, "rg --help", RIPGREP_USAGE, false @@ -1352,7 +1354,7 @@ fn ripgrep_usage() { #[test] fn ripgrep_usage_using_templates() { - let app = App::new("ripgrep") + let cmd = Command::new("ripgrep") .version("0.5") .override_usage( " @@ -1372,7 +1374,7 @@ OPTIONS: ); assert!(utils::compare_output( - app, + cmd, "rg --help", RIPGREP_USAGE, false @@ -1381,14 +1383,14 @@ OPTIONS: #[test] fn sc_negates_reqs() { - let app = App::new("prog") + let cmd = Command::new("prog") .version("1.0") .subcommand_negates_reqs(true) .arg(arg!(-o --opt "tests options")) .arg(Arg::new("PATH").help("help")) - .subcommand(App::new("test")); + .subcommand(Command::new("test")); assert!(utils::compare_output( - app, + cmd, "prog --help", SC_NEGATES_REQS, false @@ -1397,13 +1399,13 @@ fn sc_negates_reqs() { #[test] fn hide_args() { - let app = App::new("prog") + let cmd = Command::new("prog") .version("1.0") .arg(arg!(-f --flag "testing flags")) .arg(arg!(-o --opt "tests options").required(false)) .arg(Arg::new("pos").hide(true)); assert!(utils::compare_output( - app, + cmd, "prog --help", HIDDEN_ARGS, false @@ -1412,15 +1414,15 @@ fn hide_args() { #[test] fn args_negate_sc() { - let app = App::new("prog") + let cmd = Command::new("prog") .version("1.0") .args_conflicts_with_subcommands(true) .arg(arg!(-f --flag "testing flags")) .arg(arg!(-o --opt "tests options").required(false)) .arg(Arg::new("PATH").help("help")) - .subcommand(App::new("test")); + .subcommand(Command::new("test")); assert!(utils::compare_output( - app, + cmd, "prog --help", ARGS_NEGATE_SC, false @@ -1429,14 +1431,14 @@ fn args_negate_sc() { #[test] fn issue_1046_hide_scs() { - let app = App::new("prog") + let cmd = Command::new("prog") .version("1.0") .arg(arg!(-f --flag "testing flags")) .arg(arg!(-o --opt "tests options").required(false)) .arg(Arg::new("PATH").help("some")) - .subcommand(App::new("test").hide(true)); + .subcommand(Command::new("test").hide(true)); assert!(utils::compare_output( - app, + cmd, "prog --help", ISSUE_1046_HIDDEN_SCS, false @@ -1445,12 +1447,12 @@ fn issue_1046_hide_scs() { #[test] fn issue_777_wrap_all_things() { - let app = App::new("A app with a crazy very long long long name hahaha") + let cmd = Command::new("A cmd with a crazy very long long long name hahaha") .version("1.0") .author("Some Very Long Name and crazy long email ") .about("Show how the about text is not wrapped") .term_width(35); - assert!(utils::compare_output(app, "ctest --help", ISSUE_777, false)); + assert!(utils::compare_output(cmd, "ctest --help", ISSUE_777, false)); } static OVERRIDE_HELP_SHORT: &str = "test 0.1 @@ -1465,18 +1467,18 @@ OPTIONS: #[test] fn override_help_short() { - let app = App::new("test") + let cmd = Command::new("test") .version("0.1") .mut_arg("help", |h| h.short('H')); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "test --help", OVERRIDE_HELP_SHORT, false )); assert!(utils::compare_output( - app, + cmd, "test -H", OVERRIDE_HELP_SHORT, false @@ -1495,18 +1497,18 @@ OPTIONS: #[test] fn override_help_long() { - let app = App::new("test") + let cmd = Command::new("test") .version("0.1") .mut_arg("help", |h| h.long("hell")); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "test --hell", OVERRIDE_HELP_LONG, false )); assert!(utils::compare_output( - app, + cmd, "test -h", OVERRIDE_HELP_LONG, false @@ -1525,18 +1527,18 @@ OPTIONS: #[test] fn override_help_about() { - let app = App::new("test") + let cmd = Command::new("test") .version("0.1") .mut_arg("help", |h| h.help("Print help information")); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "test --help", OVERRIDE_HELP_ABOUT, false )); assert!(utils::compare_output( - app, + cmd, "test -h", OVERRIDE_HELP_ABOUT, false @@ -1545,10 +1547,10 @@ fn override_help_about() { #[test] fn arg_short_conflict_with_help() { - let app = App::new("conflict").arg(Arg::new("home").short('h')); + let cmd = Command::new("conflict").arg(Arg::new("home").short('h')); assert!(utils::compare_output( - app, + cmd, "conflict --help", HELP_CONFLICT, false @@ -1559,7 +1561,7 @@ fn arg_short_conflict_with_help() { #[test] #[should_panic = "`help`s `-h` conflicts with `home`."] fn arg_short_conflict_with_help_mut_arg() { - let _ = App::new("conflict") + let _ = Command::new("conflict") .arg(Arg::new("home").short('h')) .mut_arg("help", |h| h.short('h')) .try_get_matches_from(vec![""]); @@ -1567,7 +1569,7 @@ fn arg_short_conflict_with_help_mut_arg() { #[test] fn last_arg_mult_usage() { - let app = App::new("last") + let cmd = Command::new("last") .version("0.1") .arg(Arg::new("TARGET").required(true).help("some")) .arg(Arg::new("CORPUS").help("some")) @@ -1578,12 +1580,12 @@ fn last_arg_mult_usage() { .last(true) .help("some"), ); - assert!(utils::compare_output(app, "last --help", LAST_ARG, false)); + assert!(utils::compare_output(cmd, "last --help", LAST_ARG, false)); } #[test] fn last_arg_mult_usage_req() { - let app = App::new("last") + let cmd = Command::new("last") .version("0.1") .arg(Arg::new("TARGET").required(true).help("some")) .arg(Arg::new("CORPUS").help("some")) @@ -1596,7 +1598,7 @@ fn last_arg_mult_usage_req() { .help("some"), ); assert!(utils::compare_output( - app, + cmd, "last --help", LAST_ARG_REQ, false @@ -1605,7 +1607,7 @@ fn last_arg_mult_usage_req() { #[test] fn last_arg_mult_usage_req_with_sc() { - let app = App::new("last") + let cmd = Command::new("last") .version("0.1") .subcommand_negates_reqs(true) .arg(Arg::new("TARGET").required(true).help("some")) @@ -1618,9 +1620,9 @@ fn last_arg_mult_usage_req_with_sc() { .required(true) .help("some"), ) - .subcommand(App::new("test").about("some")); + .subcommand(Command::new("test").about("some")); assert!(utils::compare_output( - app, + cmd, "last --help", LAST_ARG_REQ_SC, false @@ -1629,7 +1631,7 @@ fn last_arg_mult_usage_req_with_sc() { #[test] fn last_arg_mult_usage_with_sc() { - let app = App::new("last") + let cmd = Command::new("last") .version("0.1") .args_conflicts_with_subcommands(true) .arg(Arg::new("TARGET").required(true).help("some")) @@ -1641,9 +1643,9 @@ fn last_arg_mult_usage_with_sc() { .last(true) .help("some"), ) - .subcommand(App::new("test").about("some")); + .subcommand(Command::new("test").about("some")); assert!(utils::compare_output( - app, + cmd, "last --help", LAST_ARG_SC, false @@ -1652,7 +1654,7 @@ fn last_arg_mult_usage_with_sc() { #[test] fn hide_default_val() { - let app1 = App::new("default").version("0.1").term_width(120).arg( + let app1 = Command::new("default").version("0.1").term_width(120).arg( Arg::new("argument") .help("Pass an argument to the program. [default: default-argument]") .long("arg") @@ -1666,7 +1668,7 @@ fn hide_default_val() { false )); - let app2 = App::new("default").version("0.1").term_width(120).arg( + let app2 = Command::new("default").version("0.1").term_width(120).arg( Arg::new("argument") .help("Pass an argument to the program.") .long("arg") @@ -1682,7 +1684,7 @@ fn hide_default_val() { #[test] fn escaped_whitespace_values() { - let app1 = App::new("default").version("0.1").term_width(120).arg( + let app1 = Command::new("default").version("0.1").term_width(120).arg( Arg::new("argument") .help("Pass an argument to the program.") .long("arg") @@ -1697,12 +1699,12 @@ fn escaped_whitespace_values() { )); } -fn issue_1112_setup() -> App<'static> { - App::new("test") +fn issue_1112_setup() -> Command<'static> { + Command::new("test") .version("1.3") .arg(Arg::new("help1").long("help").short('h').help("some help")) .subcommand( - App::new("foo").arg(Arg::new("help1").long("help").short('h').help("some help")), + Command::new("foo").arg(Arg::new("help1").long("help").short('h').help("some help")), ) } @@ -1748,7 +1750,7 @@ fn prefer_user_subcmd_help_short_1112() { #[test] fn issue_1052_require_delim_help() { - let app = App::new("test") + let cmd = Command::new("test") .author("Kevin K.") .about("tests stuff") .version("1.3") @@ -1763,7 +1765,7 @@ fn issue_1052_require_delim_help() { ); assert!(utils::compare_output( - app, + cmd, "test --help", REQUIRE_DELIM_HELP, false @@ -1772,7 +1774,7 @@ fn issue_1052_require_delim_help() { #[test] fn custom_headers_headers() { - let app = App::new("blorp") + let cmd = Command::new("blorp") .author("Will M.") .about("does stuff") .version("1.4") @@ -1795,7 +1797,7 @@ fn custom_headers_headers() { .args(&[Arg::new("port").long("port")]); assert!(utils::compare_output( - app, + cmd, "test --help", CUSTOM_HELP_SECTION, false @@ -1829,7 +1831,7 @@ SPECIAL: #[test] fn multiple_custom_help_headers() { - let app = App::new("blorp") + let cmd = Command::new("blorp") .author("Will M.") .about("does stuff") .version("1.4") @@ -1881,7 +1883,7 @@ fn multiple_custom_help_headers() { ); assert!(utils::compare_output( - app, + cmd, "test --help", MULTIPLE_CUSTOM_HELP_SECTIONS, false @@ -1908,7 +1910,7 @@ SPECIAL: #[test] fn custom_help_headers_hide_args() { - let app = App::new("blorp") + let cmd = Command::new("blorp") .author("Will M.") .about("does stuff") .version("1.4") @@ -1939,7 +1941,7 @@ fn custom_help_headers_hide_args() { ); assert!(utils::compare_output( - app, + cmd, "test -h", CUSTOM_HELP_SECTION_HIDDEN_ARGS, false @@ -1962,14 +1964,14 @@ OPTIONS: #[test] fn show_long_about_issue_897() { - let app = App::new("ctest").version("0.1").subcommand( - App::new("foo") + let cmd = Command::new("ctest").version("0.1").subcommand( + Command::new("foo") .version("0.1") .about("About foo") .long_about("Long about foo"), ); assert!(utils::compare_output( - app, + cmd, "ctest foo --help", ISSUE_897, false @@ -1989,14 +1991,14 @@ OPTIONS: #[test] fn show_short_about_issue_897() { - let app = App::new("ctest").version("0.1").subcommand( - App::new("foo") + let cmd = Command::new("ctest").version("0.1").subcommand( + Command::new("foo") .version("0.1") .about("About foo") .long_about("Long about foo"), ); assert!(utils::compare_output( - app, + cmd, "ctest foo -h", ISSUE_897_SHORT, false @@ -2005,7 +2007,7 @@ fn show_short_about_issue_897() { #[test] fn issue_1364_no_short_options() { - let app = App::new("demo") + let cmd = Command::new("demo") .arg(Arg::new("foo").short('f')) .arg( Arg::new("baz") @@ -2020,13 +2022,13 @@ fn issue_1364_no_short_options() { .multiple_values(true), ); - assert!(utils::compare_output(app, "demo -h", ISSUE_1364, false)); + assert!(utils::compare_output(cmd, "demo -h", ISSUE_1364, false)); } #[rustfmt::skip] #[test] fn issue_1487() { - let app = App::new("test") + let cmd = Command::new("test") .arg(Arg::new("arg1") .group("group1")) .arg(Arg::new("arg2") @@ -2034,14 +2036,14 @@ fn issue_1487() { .group(ArgGroup::new("group1") .args(&["arg1", "arg2"]) .required(true)); - assert!(utils::compare_output(app, "ctest -h", ISSUE_1487, false)); + assert!(utils::compare_output(cmd, "ctest -h", ISSUE_1487, false)); } #[cfg(debug_assertions)] #[test] -#[should_panic = "AppSettings::HelpExpected is enabled for the App"] +#[should_panic = "AppSettings::HelpExpected is enabled for the Command"] fn help_required_but_not_given() { - App::new("myapp") + Command::new("myapp") .help_expected(true) .arg(Arg::new("foo")) .try_get_matches_from(empty_args()) @@ -2050,9 +2052,9 @@ fn help_required_but_not_given() { #[cfg(debug_assertions)] #[test] -#[should_panic = "AppSettings::HelpExpected is enabled for the App"] +#[should_panic = "AppSettings::HelpExpected is enabled for the Command"] fn help_required_but_not_given_settings_after_args() { - App::new("myapp") + Command::new("myapp") .arg(Arg::new("foo")) .help_expected(true) .try_get_matches_from(empty_args()) @@ -2061,9 +2063,9 @@ fn help_required_but_not_given_settings_after_args() { #[cfg(debug_assertions)] #[test] -#[should_panic = "AppSettings::HelpExpected is enabled for the App"] +#[should_panic = "AppSettings::HelpExpected is enabled for the Command"] fn help_required_but_not_given_for_one_of_two_arguments() { - App::new("myapp") + Command::new("myapp") .help_expected(true) .arg(Arg::new("foo")) .arg(Arg::new("bar").help("It does bar stuff")) @@ -2074,11 +2076,11 @@ fn help_required_but_not_given_for_one_of_two_arguments() { #[test] #[should_panic = "List of such arguments: delete"] fn help_required_globally() { - App::new("myapp") + Command::new("myapp") .help_expected(true) .arg(Arg::new("foo").help("It does foo stuff")) .subcommand( - App::new("bar") + Command::new("bar") .arg(Arg::new("create").help("creates bar")) .arg(Arg::new("delete")), ) @@ -2088,13 +2090,13 @@ fn help_required_globally() { #[cfg(debug_assertions)] #[test] -#[should_panic = "AppSettings::HelpExpected is enabled for the App"] +#[should_panic = "AppSettings::HelpExpected is enabled for the Command"] fn help_required_globally_but_not_given_for_subcommand() { - App::new("myapp") + Command::new("myapp") .help_expected(true) .arg(Arg::new("foo").help("It does foo stuff")) .subcommand( - App::new("bar") + Command::new("bar") .arg(Arg::new("create").help("creates bar")) .arg(Arg::new("delete")), ) @@ -2104,11 +2106,11 @@ fn help_required_globally_but_not_given_for_subcommand() { #[test] fn help_required_and_given_for_subcommand() { - App::new("myapp") + Command::new("myapp") .help_expected(true) .arg(Arg::new("foo").help("It does foo stuff")) .subcommand( - App::new("bar") + Command::new("bar") .arg(Arg::new("create").help("creates bar")) .arg(Arg::new("delete").help("deletes bar")), ) @@ -2118,7 +2120,7 @@ fn help_required_and_given_for_subcommand() { #[test] fn help_required_and_given() { - App::new("myapp") + Command::new("myapp") .help_expected(true) .arg(Arg::new("foo").help("It does foo stuff")) .try_get_matches_from(empty_args()) @@ -2127,7 +2129,7 @@ fn help_required_and_given() { #[test] fn help_required_and_no_args() { - App::new("myapp") + Command::new("myapp") .help_expected(true) .try_get_matches_from(empty_args()) .unwrap(); @@ -2135,13 +2137,13 @@ fn help_required_and_no_args() { #[test] fn issue_1642_long_help_spacing() { - let app = App::new("prog").arg(Arg::new("cfg").long("config").long_help( + let cmd = Command::new("prog").arg(Arg::new("cfg").long("config").long_help( "The config file used by the myprog must be in JSON format with only valid keys and may not contain other nonsense that cannot be read by this program. Obviously I'm going on and on, so I'll stop now.", )); - assert!(utils::compare_output(app, "prog --help", ISSUE_1642, false)); + assert!(utils::compare_output(cmd, "prog --help", ISSUE_1642, false)); } const AFTER_HELP_NO_ARGS: &str = "myapp 1.0 @@ -2154,7 +2156,7 @@ This is after help. #[test] fn after_help_no_args() { - let mut app = App::new("myapp") + let mut cmd = Command::new("myapp") .version("1.0") .disable_help_flag(true) .disable_version_flag(true) @@ -2162,7 +2164,7 @@ fn after_help_no_args() { let help = { let mut output = Vec::new(); - app.write_help(&mut output).unwrap(); + cmd.write_help(&mut output).unwrap(); String::from_utf8(output).unwrap() }; @@ -2184,12 +2186,12 @@ OPTIONS: #[test] fn help_subcmd_help() { - let app = App::new("myapp") + let cmd = Command::new("myapp") .mut_arg("help", |h| h.help("Print custom help text")) - .subcommand(App::new("subcmd").subcommand(App::new("multi").version("1.0"))); + .subcommand(Command::new("subcmd").subcommand(Command::new("multi").version("1.0"))); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "myapp help help", HELP_SUBCMD_HELP, false @@ -2211,12 +2213,12 @@ OPTIONS: #[test] fn subcmd_help_subcmd_help() { - let app = App::new("myapp") + let cmd = Command::new("myapp") .mut_arg("help", |h| h.help("Print custom help text")) - .subcommand(App::new("subcmd").subcommand(App::new("multi").version("1.0"))); + .subcommand(Command::new("subcmd").subcommand(Command::new("multi").version("1.0"))); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "myapp subcmd help help", SUBCMD_HELP_SUBCMD_HELP, false @@ -2245,24 +2247,24 @@ OPTIONS: #[test] fn help_about_multi_subcmd() { - let app = App::new("myapp") + let cmd = Command::new("myapp") .mut_arg("help", |h| h.help("Print custom help text")) - .subcommand(App::new("subcmd").subcommand(App::new("multi").version("1.0"))); + .subcommand(Command::new("subcmd").subcommand(Command::new("multi").version("1.0"))); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "myapp help subcmd multi", HELP_ABOUT_MULTI_SC, false )); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "myapp subcmd multi -h", HELP_ABOUT_MULTI_SC, false )); assert!(utils::compare_output( - app, + cmd, "myapp subcmd multi --help", HELP_ABOUT_MULTI_SC, false @@ -2271,30 +2273,30 @@ fn help_about_multi_subcmd() { #[test] fn help_about_multi_subcmd_override() { - let app = App::new("myapp") + let cmd = Command::new("myapp") .mut_arg("help", |h| h.help("Print custom help text")) .subcommand( - App::new("subcmd").subcommand( - App::new("multi") + Command::new("subcmd").subcommand( + Command::new("multi") .version("1.0") .mut_arg("help", |h| h.help("Print custom help text from multi")), ), ); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "myapp help subcmd multi", HELP_ABOUT_MULTI_SC_OVERRIDE, false )); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "myapp subcmd multi -h", HELP_ABOUT_MULTI_SC_OVERRIDE, false )); assert!(utils::compare_output( - app, + cmd, "myapp subcmd multi --help", HELP_ABOUT_MULTI_SC_OVERRIDE, false @@ -2303,7 +2305,7 @@ fn help_about_multi_subcmd_override() { #[test] fn option_usage_order() { - let app = App::new("order").args(&[ + let cmd = Command::new("order").args(&[ Arg::new("a").short('a'), Arg::new("B").short('B'), Arg::new("b").short('b'), @@ -2314,7 +2316,7 @@ fn option_usage_order() { ]); assert!(utils::compare_output( - app, + cmd, "order --help", OPTION_USAGE_ORDER, false @@ -2323,14 +2325,14 @@ fn option_usage_order() { #[test] fn prefer_about_over_long_about_in_subcommands_list() { - let app = App::new("about-in-subcommands-list").subcommand( - App::new("sub") + let cmd = Command::new("about-in-subcommands-list").subcommand( + Command::new("sub") .long_about("long about sub") .about("short about sub"), ); assert!(utils::compare_output( - app, + cmd, "about-in-subcommands-list --help", ABOUT_IN_SUBCOMMANDS_LIST, false @@ -2353,7 +2355,7 @@ OPTIONS: --option1 "; - let app = clap::App::new("hello") + let cmd = clap::Command::new("hello") .bin_name("deno") .arg(Arg::new("option1").long("option1").takes_value(false)) .arg(Arg::new("pos1").takes_value(true)) @@ -2365,7 +2367,7 @@ OPTIONS: .arg(Arg::new("pos2").takes_value(true)); assert!(utils::compare_output( - app, + cmd, "deno --help", USAGE_WITH_GROUP, false @@ -2390,14 +2392,14 @@ NETWORKING: #[test] fn custom_heading_pos() { - let app = App::new("test") + let cmd = Command::new("test") .version("1.4") .arg(Arg::new("gear").help("Which gear")) .next_help_heading(Some("NETWORKING")) .arg(Arg::new("speed").help("How fast")); assert!(utils::compare_output( - app, + cmd, "test --help", CUSTOM_HEADING_POS, false @@ -2415,7 +2417,7 @@ NETWORKING: #[test] fn only_custom_heading_opts_no_args() { - let app = App::new("test") + let cmd = Command::new("test") .version("1.4") .disable_version_flag(true) .mut_arg("help", |a| a.hide(true)) @@ -2423,7 +2425,7 @@ fn only_custom_heading_opts_no_args() { .arg(arg!(-s --speed "How fast").required(false)); assert!(utils::compare_output( - app, + cmd, "test --help", ONLY_CUSTOM_HEADING_OPTS_NO_ARGS, false @@ -2441,7 +2443,7 @@ NETWORKING: #[test] fn only_custom_heading_pos_no_args() { - let app = App::new("test") + let cmd = Command::new("test") .version("1.4") .disable_version_flag(true) .mut_arg("help", |a| a.hide(true)) @@ -2449,7 +2451,7 @@ fn only_custom_heading_pos_no_args() { .arg(Arg::new("speed").help("How fast")); assert!(utils::compare_output( - app, + cmd, "test --help", ONLY_CUSTOM_HEADING_POS_NO_ARGS, false @@ -2458,7 +2460,7 @@ fn only_custom_heading_pos_no_args() { #[test] fn issue_2508_number_of_values_with_single_value_name() { - let app = App::new("my_app") + let cmd = Command::new("my_app") .arg(Arg::new("some_arg").long("some_arg").number_of_values(2)) .arg( Arg::new("some_arg_issue") @@ -2467,7 +2469,7 @@ fn issue_2508_number_of_values_with_single_value_name() { .value_name("ARG"), ); assert!(utils::compare_output( - app, + cmd, "my_app --help", "my_app @@ -2485,12 +2487,12 @@ OPTIONS: #[test] fn missing_positional_final_required() { - let app = App::new("test") + let cmd = Command::new("test") .allow_missing_positional(true) .arg(Arg::new("arg1")) .arg(Arg::new("arg2").required(true)); assert!(utils::compare_output( - app, + cmd, "test --help", "test @@ -2510,13 +2512,13 @@ OPTIONS: #[test] fn missing_positional_final_multiple() { - let app = App::new("test") + let cmd = Command::new("test") .allow_missing_positional(true) .arg(Arg::new("foo")) .arg(Arg::new("bar")) .arg(Arg::new("baz").takes_value(true).multiple_values(true)); assert!(utils::compare_output( - app, + cmd, "test --help", "test @@ -2537,14 +2539,14 @@ OPTIONS: #[test] fn positional_multiple_values_is_dotted() { - let app = App::new("test").arg( + let cmd = Command::new("test").arg( Arg::new("foo") .required(true) .takes_value(true) .multiple_values(true), ); assert!(utils::compare_output( - app, + cmd, "test --help", "test @@ -2560,7 +2562,7 @@ OPTIONS: false )); - let app = App::new("test").arg( + let cmd = Command::new("test").arg( Arg::new("foo") .required(true) .takes_value(true) @@ -2568,7 +2570,7 @@ OPTIONS: .multiple_values(true), ); assert!(utils::compare_output( - app, + cmd, "test --help", "test @@ -2587,14 +2589,14 @@ OPTIONS: #[test] fn positional_multiple_occurrences_is_dotted() { - let app = App::new("test").arg( + let cmd = Command::new("test").arg( Arg::new("foo") .required(true) .takes_value(true) .multiple_occurrences(true), ); assert!(utils::compare_output( - app, + cmd, "test --help", "test @@ -2610,7 +2612,7 @@ OPTIONS: false )); - let app = App::new("test").arg( + let cmd = Command::new("test").arg( Arg::new("foo") .required(true) .takes_value(true) @@ -2618,7 +2620,7 @@ OPTIONS: .multiple_occurrences(true), ); assert!(utils::compare_output( - app, + cmd, "test --help", "test @@ -2637,8 +2639,8 @@ OPTIONS: #[test] fn disabled_help_flag() { - let res = App::new("foo") - .subcommand(App::new("sub")) + let res = Command::new("foo") + .subcommand(Command::new("sub")) .disable_help_flag(true) .try_get_matches_from("foo a".split(' ')); assert!(res.is_err()); @@ -2648,8 +2650,8 @@ fn disabled_help_flag() { #[test] fn disabled_help_flag_and_subcommand() { - let res = App::new("foo") - .subcommand(App::new("sub")) + let res = Command::new("foo") + .subcommand(Command::new("sub")) .disable_help_flag(true) .disable_help_subcommand(true) .try_get_matches_from("foo help".split(' ')); @@ -2665,11 +2667,11 @@ fn disabled_help_flag_and_subcommand() { #[test] fn override_help_subcommand() { - let app = App::new("bar") - .subcommand(App::new("help").arg(Arg::new("arg").takes_value(true))) - .subcommand(App::new("not_help").arg(Arg::new("arg").takes_value(true))) + let cmd = Command::new("bar") + .subcommand(Command::new("help").arg(Arg::new("arg").takes_value(true))) + .subcommand(Command::new("not_help").arg(Arg::new("arg").takes_value(true))) .disable_help_subcommand(true); - let matches = app.try_get_matches_from(&["bar", "help", "foo"]).unwrap(); + let matches = cmd.try_get_matches_from(&["bar", "help", "foo"]).unwrap(); assert_eq!( matches.subcommand_matches("help").unwrap().value_of("arg"), Some("foo") @@ -2678,19 +2680,19 @@ fn override_help_subcommand() { #[test] fn override_help_flag_using_long() { - let app = App::new("foo") - .subcommand(App::new("help").long_flag("help")) + let cmd = Command::new("foo") + .subcommand(Command::new("help").long_flag("help")) .disable_help_flag(true); - let matches = app.try_get_matches_from(&["foo", "--help"]).unwrap(); + let matches = cmd.try_get_matches_from(&["foo", "--help"]).unwrap(); assert!(matches.subcommand_matches("help").is_some()); } #[test] fn override_help_flag_using_short() { - let app = App::new("foo") + let cmd = Command::new("foo") .disable_help_flag(true) - .subcommand(App::new("help").short_flag('h')); - let matches = app.try_get_matches_from(&["foo", "-h"]).unwrap(); + .subcommand(Command::new("help").short_flag('h')); + let matches = cmd.try_get_matches_from(&["foo", "-h"]).unwrap(); assert!(matches.subcommand_matches("help").is_some()); } @@ -2698,10 +2700,10 @@ fn override_help_flag_using_short() { fn subcommand_help_doesnt_have_useless_help_flag() { // The main care-about is that the docs and behavior match. Since the `help` subcommand // currently ignores the `--help` flag, the output shouldn't have it. - let app = App::new("test_app").subcommand(App::new("test").about("Subcommand")); + let cmd = Command::new("test_app").subcommand(Command::new("test").about("Subcommand")); assert!(utils::compare_output( - app, + cmd, "example help help", "example-help Print this message or the help of the given subcommand(s) @@ -2718,12 +2720,12 @@ ARGS: #[test] fn disable_help_flag_affects_help_subcommand() { - let mut app = App::new("test_app") + let mut cmd = Command::new("test_app") .disable_help_flag(true) - .subcommand(App::new("test").about("Subcommand")); - app._build_all(); + .subcommand(Command::new("test").about("Subcommand")); + cmd._build_all(); - let args = app + let args = cmd .find_subcommand("help") .unwrap() .get_arguments() @@ -2738,13 +2740,13 @@ fn disable_help_flag_affects_help_subcommand() { #[test] fn dont_propagate_version_to_help_subcommand() { - let app = clap::App::new("test") + let cmd = clap::Command::new("test") .version("1.0") .propagate_version(true) - .subcommand(clap::App::new("subcommand")); + .subcommand(clap::Command::new("subcommand")); assert!(utils::compare_output( - app.clone(), + cmd.clone(), "example help help", "example-help Print this message or the help of the given subcommand(s) @@ -2758,19 +2760,19 @@ ARGS: false )); - app.debug_assert(); + cmd.debug_assert(); } #[test] fn help_without_short() { - let mut app = clap::App::new("test") + let mut cmd = clap::Command::new("test") .arg(arg!(-h --hex )) .arg(arg!(--help)); - app._build_all(); - let help = app.get_arguments().find(|a| a.get_id() == "help").unwrap(); + cmd._build_all(); + let help = cmd.get_arguments().find(|a| a.get_id() == "help").unwrap(); assert_eq!(help.get_short(), None); - let m = app.try_get_matches_from(["test", "-h", "0x100"]).unwrap(); + let m = cmd.try_get_matches_from(["test", "-h", "0x100"]).unwrap(); assert_eq!(m.value_of("hex"), Some("0x100")); } diff --git a/tests/builder/help_env.rs b/tests/builder/help_env.rs index d203ed1518a..c18e3994392 100644 --- a/tests/builder/help_env.rs +++ b/tests/builder/help_env.rs @@ -2,7 +2,7 @@ use std::env; -use clap::{App, Arg}; +use clap::{Arg, Command}; use crate::utils; @@ -98,7 +98,7 @@ OPTIONS: fn hide_env() { env::set_var("ENVVAR", "MYVAL"); - let app = App::new("ctest").version("0.1").arg( + let cmd = Command::new("ctest").version("0.1").arg( Arg::new("cafe") .short('c') .long("cafe") @@ -109,14 +109,14 @@ fn hide_env() { .takes_value(true), ); - assert!(utils::compare_output(app, "ctest --help", HIDE_ENV, false)); + assert!(utils::compare_output(cmd, "ctest --help", HIDE_ENV, false)); } #[test] fn show_env() { env::set_var("ENVVAR", "MYVAL"); - let app = App::new("ctest").version("0.1").arg( + let cmd = Command::new("ctest").version("0.1").arg( Arg::new("cafe") .short('c') .long("cafe") @@ -126,14 +126,14 @@ fn show_env() { .takes_value(true), ); - assert!(utils::compare_output(app, "ctest --help", SHOW_ENV, false)); + assert!(utils::compare_output(cmd, "ctest --help", SHOW_ENV, false)); } #[test] fn hide_env_vals() { env::set_var("ENVVAR", "MYVAL"); - let app = App::new("ctest").version("0.1").arg( + let cmd = Command::new("ctest").version("0.1").arg( Arg::new("cafe") .short('c') .long("cafe") @@ -145,7 +145,7 @@ fn hide_env_vals() { ); assert!(utils::compare_output( - app, + cmd, "ctest --help", HIDE_ENV_VALS, false @@ -156,7 +156,7 @@ fn hide_env_vals() { fn show_env_vals() { env::set_var("ENVVAR", "MYVAL"); - let app = App::new("ctest").version("0.1").arg( + let cmd = Command::new("ctest").version("0.1").arg( Arg::new("cafe") .short('c') .long("cafe") @@ -167,7 +167,7 @@ fn show_env_vals() { ); assert!(utils::compare_output( - app, + cmd, "ctest --help", SHOW_ENV_VALS, false @@ -178,7 +178,7 @@ fn show_env_vals() { fn hide_env_flag() { env::set_var("ENVVAR", "MYVAL"); - let app = App::new("ctest").version("0.1").arg( + let cmd = Command::new("ctest").version("0.1").arg( Arg::new("cafe") .short('c') .long("cafe") @@ -188,7 +188,7 @@ fn hide_env_flag() { ); assert!(utils::compare_output( - app, + cmd, "ctest --help", HIDE_ENV_FLAG, false @@ -199,7 +199,7 @@ fn hide_env_flag() { fn show_env_flag() { env::set_var("ENVVAR", "MYVAL"); - let app = App::new("ctest").version("0.1").arg( + let cmd = Command::new("ctest").version("0.1").arg( Arg::new("cafe") .short('c') .long("cafe") @@ -208,7 +208,7 @@ fn show_env_flag() { ); assert!(utils::compare_output( - app, + cmd, "ctest --help", SHOW_ENV_FLAG, false @@ -219,7 +219,7 @@ fn show_env_flag() { fn hide_env_vals_flag() { env::set_var("ENVVAR", "MYVAL"); - let app = App::new("ctest").version("0.1").arg( + let cmd = Command::new("ctest").version("0.1").arg( Arg::new("cafe") .short('c') .long("cafe") @@ -229,7 +229,7 @@ fn hide_env_vals_flag() { ); assert!(utils::compare_output( - app, + cmd, "ctest --help", HIDE_ENV_VALS_FLAG, false @@ -240,7 +240,7 @@ fn hide_env_vals_flag() { fn show_env_vals_flag() { env::set_var("ENVVAR", "MYVAL"); - let app = App::new("ctest").version("0.1").arg( + let cmd = Command::new("ctest").version("0.1").arg( Arg::new("cafe") .short('c') .long("cafe") @@ -249,7 +249,7 @@ fn show_env_vals_flag() { ); assert!(utils::compare_output( - app, + cmd, "ctest --help", SHOW_ENV_VALS_FLAG, false diff --git a/tests/builder/hidden_args.rs b/tests/builder/hidden_args.rs index 7ae82e2a4d1..3827fe80d07 100644 --- a/tests/builder/hidden_args.rs +++ b/tests/builder/hidden_args.rs @@ -1,6 +1,6 @@ use crate::utils; -use clap::{arg, App, Arg}; +use clap::{arg, Arg, Command}; static HIDDEN_ARGS: &str = "test 1.4 Kevin K. @@ -18,7 +18,7 @@ OPTIONS: #[test] fn hide_args() { - let app = App::new("test") + let cmd = Command::new("test") .author("Kevin K.") .about("tests stuff") .version("1.4") @@ -29,7 +29,7 @@ fn hide_args() { Arg::new("DUMMY").hide(true), ]); assert!(utils::compare_output( - app, + cmd, "test --help", HIDDEN_ARGS, false @@ -73,7 +73,7 @@ OPTIONS: /// Ensure hide with short option #[test] fn hide_short_args() { - let app = App::new("test") + let cmd = Command::new("test") .about("hides short args") .author("Steve P.") .version("2.31.2") @@ -90,7 +90,7 @@ fn hide_short_args() { ]); assert!(utils::compare_output( - app, + cmd, "test -h", HIDDEN_SHORT_ARGS, false @@ -100,7 +100,7 @@ fn hide_short_args() { /// Ensure visible with opposite option #[test] fn hide_short_args_long_help() { - let app = App::new("test") + let cmd = Command::new("test") .about("hides short args") .author("Steve P.") .version("2.31.2") @@ -117,7 +117,7 @@ fn hide_short_args_long_help() { ]); assert!(utils::compare_output( - app, + cmd, "test --help", HIDDEN_SHORT_ARGS_LONG_HELP, false @@ -144,7 +144,7 @@ OPTIONS: #[test] fn hide_long_args() { - let app = App::new("test") + let cmd = Command::new("test") .about("hides long args") .author("Steve P.") .version("2.31.2") @@ -161,7 +161,7 @@ fn hide_long_args() { ]); assert!(utils::compare_output( - app, + cmd, "test --help", HIDDEN_LONG_ARGS, false @@ -184,7 +184,7 @@ OPTIONS: #[test] fn hide_long_args_short_help() { - let app = App::new("test") + let cmd = Command::new("test") .about("hides long args") .author("Steve P.") .version("2.31.2") @@ -201,7 +201,7 @@ fn hide_long_args_short_help() { ]); assert!(utils::compare_output( - app, + cmd, "test -h", HIDDEN_LONG_ARGS_SHORT_HELP, false @@ -223,13 +223,13 @@ OPTIONS: #[test] fn hide_pos_args() { - let app = App::new("test").version("1.4").args(&[ + let cmd = Command::new("test").version("1.4").args(&[ Arg::new("pos").help("some pos").hide(true), Arg::new("another").help("another pos"), ]); assert!(utils::compare_output( - app, + cmd, "test --help", HIDDEN_POS_ARGS, false @@ -248,12 +248,12 @@ OPTIONS: #[test] fn hide_subcmds() { - let app = App::new("test") + let cmd = Command::new("test") .version("1.4") - .subcommand(App::new("sub").hide(true)); + .subcommand(Command::new("sub").hide(true)); assert!(utils::compare_output( - app, + cmd, "test --help", HIDDEN_SUBCMDS, false @@ -270,7 +270,7 @@ After help #[test] fn hide_opt_args_only() { - let app = App::new("test") + let cmd = Command::new("test") .version("1.4") .after_help("After help") .mut_arg("help", |a| a.hide(true)) @@ -282,7 +282,7 @@ fn hide_opt_args_only() { ); assert!(utils::compare_output( - app, + cmd, "test --help", HIDDEN_OPT_ARGS_ONLY, false @@ -299,7 +299,7 @@ After help #[test] fn hide_pos_args_only() { - let app = App::new("test") + let cmd = Command::new("test") .version("1.4") .after_help("After help") .mut_arg("help", |a| a.hide(true)) @@ -307,7 +307,7 @@ fn hide_pos_args_only() { .args(&[Arg::new("pos").help("some pos").hide(true)]); assert!(utils::compare_output( - app, + cmd, "test --help", HIDDEN_POS_ARGS_ONLY, false @@ -324,15 +324,15 @@ After help #[test] fn hide_subcmds_only() { - let app = App::new("test") + let cmd = Command::new("test") .version("1.4") .after_help("After help") .mut_arg("help", |a| a.hide(true)) .mut_arg("version", |a| a.hide(true)) - .subcommand(App::new("sub").hide(true)); + .subcommand(Command::new("sub").hide(true)); assert!(utils::compare_output( - app, + cmd, "test --help", HIDDEN_SUBCMDS_ONLY, false diff --git a/tests/builder/ignore_errors.rs b/tests/builder/ignore_errors.rs index f3da817712b..894b7d6c876 100644 --- a/tests/builder/ignore_errors.rs +++ b/tests/builder/ignore_errors.rs @@ -1,12 +1,12 @@ -use clap::{arg, App, Arg}; +use clap::{arg, Arg, Command}; #[test] fn single_short_arg_without_value() { - let app = App::new("app").ignore_errors(true).arg(arg!( + let cmd = Command::new("cmd").ignore_errors(true).arg(arg!( -c --config [FILE] "Sets a custom config file" )); - let r = app.try_get_matches_from(vec!["app", "-c" /* missing: , "config file" */]); + let r = cmd.try_get_matches_from(vec!["cmd", "-c" /* missing: , "config file" */]); assert!(r.is_ok(), "unexpected error: {:?}", r); let m = r.unwrap(); @@ -15,11 +15,11 @@ fn single_short_arg_without_value() { #[test] fn single_long_arg_without_value() { - let app = App::new("app").ignore_errors(true).arg(arg!( + let cmd = Command::new("cmd").ignore_errors(true).arg(arg!( -c --config [FILE] "Sets a custom config file" )); - let r = app.try_get_matches_from(vec!["app", "--config" /* missing: , "config file" */]); + let r = cmd.try_get_matches_from(vec!["cmd", "--config" /* missing: , "config file" */]); assert!(r.is_ok(), "unexpected error: {:?}", r); let m = r.unwrap(); @@ -28,7 +28,7 @@ fn single_long_arg_without_value() { #[test] fn multiple_args_and_final_arg_without_value() { - let app = App::new("app") + let cmd = Command::new("cmd") .ignore_errors(true) .arg(arg!( -c --config [FILE] "Sets a custom config file" @@ -38,8 +38,8 @@ fn multiple_args_and_final_arg_without_value() { )) .arg(arg!(f: -f "Flag")); - let r = app.try_get_matches_from(vec![ - "app", "-c", "file", "-f", "-x", /* missing: , "some stuff" */ + let r = cmd.try_get_matches_from(vec![ + "cmd", "-c", "file", "-f", "-x", /* missing: , "some stuff" */ ]); assert!(r.is_ok(), "unexpected error: {:?}", r); @@ -51,7 +51,7 @@ fn multiple_args_and_final_arg_without_value() { #[test] fn multiple_args_and_intermittent_arg_without_value() { - let app = App::new("app") + let cmd = Command::new("cmd") .ignore_errors(true) .arg(arg!( -c --config[FILE] "Sets a custom config file" @@ -61,8 +61,8 @@ fn multiple_args_and_intermittent_arg_without_value() { )) .arg(arg!(f: -f "Flag")); - let r = app.try_get_matches_from(vec![ - "app", "-x", /* missing: ,"some stuff" */ + let r = cmd.try_get_matches_from(vec![ + "cmd", "-x", /* missing: ,"some stuff" */ "-c", "file", "-f", ]); @@ -75,10 +75,10 @@ fn multiple_args_and_intermittent_arg_without_value() { #[test] fn subcommand() { - let app = App::new("test") + let cmd = Command::new("test") .ignore_errors(true) .subcommand( - App::new("some") + Command::new("some") .arg( Arg::new("test") .short('t') @@ -96,7 +96,7 @@ fn subcommand() { ) .arg(Arg::new("other").long("other")); - let m = app + let m = cmd .try_get_matches_from(vec![ "myprog", "some", diff --git a/tests/builder/indices.rs b/tests/builder/indices.rs index 8be1b287b63..403cf86f579 100644 --- a/tests/builder/indices.rs +++ b/tests/builder/indices.rs @@ -1,8 +1,8 @@ -use clap::{App, Arg}; +use clap::{Arg, Command}; #[test] fn indices_mult_opts() { - let m = App::new("ind") + let m = Command::new("ind") .arg( Arg::new("exclude") .short('e') @@ -31,7 +31,7 @@ fn indices_mult_opts() { #[test] fn index_mult_opts() { - let m = App::new("ind") + let m = Command::new("ind") .arg( Arg::new("exclude") .short('e') @@ -54,7 +54,7 @@ fn index_mult_opts() { #[test] fn index_flag() { - let m = App::new("ind") + let m = Command::new("ind") .arg(Arg::new("exclude").short('e')) .arg(Arg::new("include").short('i')) .try_get_matches_from(vec!["ind", "-e", "-i"]) @@ -66,7 +66,7 @@ fn index_flag() { #[test] fn index_flags() { - let m = App::new("ind") + let m = Command::new("ind") .arg(Arg::new("exclude").short('e').multiple_occurrences(true)) .arg(Arg::new("include").short('i').multiple_occurrences(true)) .try_get_matches_from(vec!["ind", "-e", "-i", "-e", "-e", "-i"]) @@ -78,7 +78,7 @@ fn index_flags() { #[test] fn indices_mult_flags() { - let m = App::new("ind") + let m = Command::new("ind") .arg(Arg::new("exclude").short('e').multiple_occurrences(true)) .arg(Arg::new("include").short('i').multiple_occurrences(true)) .try_get_matches_from(vec!["ind", "-e", "-i", "-e", "-e", "-i"]) @@ -96,7 +96,7 @@ fn indices_mult_flags() { #[test] fn indices_mult_flags_combined() { - let m = App::new("ind") + let m = Command::new("ind") .arg(Arg::new("exclude").short('e').multiple_occurrences(true)) .arg(Arg::new("include").short('i').multiple_occurrences(true)) .try_get_matches_from(vec!["ind", "-eieei"]) @@ -114,7 +114,7 @@ fn indices_mult_flags_combined() { #[test] fn indices_mult_flags_opt_combined() { - let m = App::new("ind") + let m = Command::new("ind") .arg(Arg::new("exclude").short('e').multiple_occurrences(true)) .arg(Arg::new("include").short('i').multiple_occurrences(true)) .arg(Arg::new("option").short('o').takes_value(true)) @@ -134,7 +134,7 @@ fn indices_mult_flags_opt_combined() { #[test] fn indices_mult_flags_opt_combined_eq() { - let m = App::new("ind") + let m = Command::new("ind") .arg(Arg::new("exclude").short('e').multiple_occurrences(true)) .arg(Arg::new("include").short('i').multiple_occurrences(true)) .arg(Arg::new("option").short('o').takes_value(true)) @@ -154,7 +154,7 @@ fn indices_mult_flags_opt_combined_eq() { #[test] fn indices_mult_opt_value_delim_eq() { - let m = App::new("myapp") + let m = Command::new("myapp") .arg( Arg::new("option") .short('o') @@ -172,7 +172,7 @@ fn indices_mult_opt_value_delim_eq() { #[test] fn indices_mult_opt_value_no_delim_eq() { - let m = App::new("myapp") + let m = Command::new("myapp") .arg( Arg::new("option") .short('o') @@ -186,7 +186,7 @@ fn indices_mult_opt_value_no_delim_eq() { #[test] fn indices_mult_opt_mult_flag() { - let m = App::new("myapp") + let m = Command::new("myapp") .arg( Arg::new("option") .short('o') diff --git a/tests/builder/multiple_occurrences.rs b/tests/builder/multiple_occurrences.rs index 5c78ada2ccd..6e7c6339172 100644 --- a/tests/builder/multiple_occurrences.rs +++ b/tests/builder/multiple_occurrences.rs @@ -1,8 +1,8 @@ -use clap::{arg, error::ErrorKind, App, Arg}; +use clap::{arg, error::ErrorKind, Arg, Command}; #[test] fn multiple_occurrences_of_flags_long() { - let m = App::new("mo_flags_long") + let m = Command::new("mo_flags_long") .arg(arg!(--multflag "allowed multiple flag").multiple_occurrences(true)) .arg(arg!(--flag "disallowed multiple flag")) .try_get_matches_from(vec!["", "--multflag", "--flag", "--multflag"]) @@ -15,7 +15,7 @@ fn multiple_occurrences_of_flags_long() { #[test] fn multiple_occurrences_of_flags_short() { - let m = App::new("mo_flags_short") + let m = Command::new("mo_flags_short") .arg(arg!(-m --multflag "allowed multiple flag").multiple_occurrences(true)) .arg(arg!(-f --flag "disallowed multiple flag")) .try_get_matches_from(vec!["", "-m", "-f", "-m"]) @@ -28,7 +28,7 @@ fn multiple_occurrences_of_flags_short() { #[test] fn multiple_occurrences_of_flags_mixed() { - let m = App::new("mo_flags_mixed") + let m = Command::new("mo_flags_mixed") .arg(arg!(-m --multflag1 "allowed multiple flag").multiple_occurrences(true)) .arg(arg!(-n --multflag2 "another allowed multiple flag").multiple_occurrences(true)) .arg(arg!(-f --flag "disallowed multiple flag")) @@ -52,9 +52,9 @@ fn multiple_occurrences_of_flags_mixed() { #[test] fn multiple_occurrences_of_positional() { - let app = App::new("test").arg(Arg::new("multi").multiple_occurrences(true)); + let cmd = Command::new("test").arg(Arg::new("multi").multiple_occurrences(true)); - let m = app + let m = cmd .clone() .try_get_matches_from(&["test"]) .expect("zero occurrences work"); @@ -62,7 +62,7 @@ fn multiple_occurrences_of_positional() { assert_eq!(m.occurrences_of("multi"), 0); assert!(m.values_of("multi").is_none()); - let m = app + let m = cmd .clone() .try_get_matches_from(&["test", "one"]) .expect("single occurrence work"); @@ -70,7 +70,7 @@ fn multiple_occurrences_of_positional() { assert_eq!(m.occurrences_of("multi"), 1); assert_eq!(m.values_of("multi").unwrap().collect::>(), ["one"]); - let m = app + let m = cmd .clone() .try_get_matches_from(&["test", "one", "two", "three", "four"]) .expect("many occurrences work"); @@ -88,7 +88,7 @@ fn multiple_occurrences_of_flags_large_quantity() { .into_iter() .chain(vec!["-m"; 1024].into_iter()) .collect(); - let m = App::new("mo_flags_large_qty") + let m = Command::new("mo_flags_large_qty") .arg(arg!(-m --multflag "allowed multiple flag").multiple_occurrences(true)) .try_get_matches_from(args) .unwrap(); @@ -99,7 +99,7 @@ fn multiple_occurrences_of_flags_large_quantity() { #[cfg(feature = "env")] #[test] fn multiple_occurrences_of_before_env() { - let app = App::new("mo_before_env").arg( + let cmd = Command::new("mo_before_env").arg( Arg::new("verbose") .env("VERBOSE") .short('v') @@ -108,18 +108,18 @@ fn multiple_occurrences_of_before_env() { .multiple_occurrences(true), ); - let m = app.clone().try_get_matches_from(vec![""]); + let m = cmd.clone().try_get_matches_from(vec![""]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 0); - let m = app.clone().try_get_matches_from(vec!["", "-v"]); + let m = cmd.clone().try_get_matches_from(vec!["", "-v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 1); - let m = app.clone().try_get_matches_from(vec!["", "-vv"]); + let m = cmd.clone().try_get_matches_from(vec!["", "-vv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 2); - let m = app.clone().try_get_matches_from(vec!["", "-vvv"]); + let m = cmd.clone().try_get_matches_from(vec!["", "-vvv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 3); } @@ -127,7 +127,7 @@ fn multiple_occurrences_of_before_env() { #[cfg(feature = "env")] #[test] fn multiple_occurrences_of_after_env() { - let app = App::new("mo_after_env").arg( + let cmd = Command::new("mo_after_env").arg( Arg::new("verbose") .short('v') .long("verbose") @@ -136,44 +136,44 @@ fn multiple_occurrences_of_after_env() { .env("VERBOSE"), ); - let m = app.clone().try_get_matches_from(vec![""]); + let m = cmd.clone().try_get_matches_from(vec![""]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 0); - let m = app.clone().try_get_matches_from(vec!["", "-v"]); + let m = cmd.clone().try_get_matches_from(vec!["", "-v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 1); - let m = app.clone().try_get_matches_from(vec!["", "-vv"]); + let m = cmd.clone().try_get_matches_from(vec!["", "-vv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 2); - let m = app.clone().try_get_matches_from(vec!["", "-vvv"]); + let m = cmd.clone().try_get_matches_from(vec!["", "-vvv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 3); } #[test] fn max_occurrences_implies_multiple_occurrences() { - let app = App::new("prog").arg( + let cmd = Command::new("prog").arg( Arg::new("verbose") .short('v') .long("verbose") .max_occurrences(3), ); - let m = app.try_get_matches_from(vec!["prog", "-vvv"]); + let m = cmd.try_get_matches_from(vec!["prog", "-vvv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 3); // One max should not imply multiple occurrences - let app = App::new("prog").arg( + let cmd = Command::new("prog").arg( Arg::new("verbose") .short('v') .long("verbose") .max_occurrences(1), ); - let m = app.try_get_matches_from(vec!["prog", "-vvv"]); + let m = cmd.try_get_matches_from(vec!["prog", "-vvv"]); assert!(m.is_err()); assert_eq!(m.unwrap_err().kind(), ErrorKind::UnexpectedMultipleUsage); @@ -181,35 +181,35 @@ fn max_occurrences_implies_multiple_occurrences() { #[test] fn max_occurrences_try_inputs() { - let app = App::new("prog").arg( + let cmd = Command::new("prog").arg( Arg::new("verbose") .short('v') .long("verbose") .max_occurrences(3), ); - let m = app.clone().try_get_matches_from(vec!["prog", "-v"]); + let m = cmd.clone().try_get_matches_from(vec!["prog", "-v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 1); - let m = app.clone().try_get_matches_from(vec!["prog", "-vv"]); + let m = cmd.clone().try_get_matches_from(vec!["prog", "-vv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 2); - let m = app.clone().try_get_matches_from(vec!["prog", "-vvv"]); + let m = cmd.clone().try_get_matches_from(vec!["prog", "-vvv"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 3); - let m = app.clone().try_get_matches_from(vec!["prog", "-vvvv"]); + let m = cmd.clone().try_get_matches_from(vec!["prog", "-vvvv"]); assert!(m.is_err()); assert_eq!(m.unwrap_err().kind(), ErrorKind::TooManyOccurrences); - let m = app + let m = cmd .clone() .try_get_matches_from(vec!["prog", "-v", "-v", "-v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 3); - let m = app + let m = cmd .clone() .try_get_matches_from(vec!["prog", "-v", "-vv", "-v"]); assert!(m.is_err()); @@ -218,22 +218,22 @@ fn max_occurrences_try_inputs() { #[test] fn max_occurrences_positional() { - let app = App::new("prog").arg(Arg::new("verbose").max_occurrences(3)); - let m = app.clone().try_get_matches_from(vec!["prog", "v"]); + let cmd = Command::new("prog").arg(Arg::new("verbose").max_occurrences(3)); + let m = cmd.clone().try_get_matches_from(vec!["prog", "v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 1); - let m = app.clone().try_get_matches_from(vec!["prog", "v", "v"]); + let m = cmd.clone().try_get_matches_from(vec!["prog", "v", "v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 2); - let m = app + let m = cmd .clone() .try_get_matches_from(vec!["prog", "v", "v", "v"]); assert!(m.is_ok(), "{}", m.unwrap_err()); assert_eq!(m.unwrap().occurrences_of("verbose"), 3); - let m = app + let m = cmd .clone() .try_get_matches_from(vec!["prog", "v", "v", "v", "v"]); assert!(m.is_err()); diff --git a/tests/builder/multiple_values.rs b/tests/builder/multiple_values.rs index 74a5ee50f79..3f115e76ade 100644 --- a/tests/builder/multiple_values.rs +++ b/tests/builder/multiple_values.rs @@ -1,8 +1,8 @@ -use clap::{error::ErrorKind, App, Arg}; +use clap::{error::ErrorKind, Arg, Command}; #[test] fn option_long() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .long("option") @@ -28,7 +28,7 @@ fn option_long() { #[test] fn option_short() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -52,7 +52,7 @@ fn option_short() { #[test] fn option_mixed() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .long("option") @@ -79,7 +79,7 @@ fn option_mixed() { #[test] fn option_exact_exact() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -102,7 +102,7 @@ fn option_exact_exact() { #[test] fn option_exact_exact_not_mult() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -124,7 +124,7 @@ fn option_exact_exact_not_mult() { #[test] fn option_exact_exact_mult() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -149,7 +149,7 @@ fn option_exact_exact_mult() { #[test] fn option_exact_less() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -165,7 +165,7 @@ fn option_exact_less() { #[test] fn option_exact_more() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -183,7 +183,7 @@ fn option_exact_more() { #[test] fn option_min_exact() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -206,7 +206,7 @@ fn option_min_exact() { #[test] fn option_min_less() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -222,7 +222,7 @@ fn option_min_less() { #[test] fn option_short_min_more_mult_occurs() { - let res = App::new("multiple_values") + let res = Command::new("multiple_values") .arg(Arg::new("arg").required(true)) .arg( Arg::new("option") @@ -250,7 +250,7 @@ fn option_short_min_more_mult_occurs() { #[test] fn option_short_min_more_single_occur() { - let res = App::new("multiple_values") + let res = Command::new("multiple_values") .arg(Arg::new("arg").required(true)) .arg( Arg::new("option") @@ -275,7 +275,7 @@ fn option_short_min_more_single_occur() { #[test] fn option_max_exact() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -298,7 +298,7 @@ fn option_max_exact() { #[test] fn option_max_less() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -321,7 +321,7 @@ fn option_max_less() { #[test] fn option_max_more() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -339,7 +339,7 @@ fn option_max_more() { #[test] fn positional() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("pos") .help("multiple positionals") @@ -361,7 +361,7 @@ fn positional() { #[test] fn positional_exact_exact() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("pos") .help("multiple positionals") @@ -382,7 +382,7 @@ fn positional_exact_exact() { #[test] fn positional_exact_less() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("pos") .help("multiple positionals") @@ -396,7 +396,7 @@ fn positional_exact_less() { #[test] fn positional_exact_more() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("pos") .help("multiple positionals") @@ -410,7 +410,7 @@ fn positional_exact_more() { #[test] fn positional_min_exact() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg(Arg::new("pos").help("multiple positionals").min_values(3)) .try_get_matches_from(vec!["myprog", "val1", "val2", "val3"]); @@ -427,7 +427,7 @@ fn positional_min_exact() { #[test] fn positional_min_less() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg(Arg::new("pos").help("multiple positionals").min_values(3)) .try_get_matches_from(vec!["myprog", "val1", "val2"]); @@ -437,7 +437,7 @@ fn positional_min_less() { #[test] fn positional_min_more() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg(Arg::new("pos").help("multiple positionals").min_values(3)) .try_get_matches_from(vec!["myprog", "val1", "val2", "val3", "val4"]); @@ -454,7 +454,7 @@ fn positional_min_more() { #[test] fn positional_max_exact() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg(Arg::new("pos").help("multiple positionals").max_values(3)) .try_get_matches_from(vec!["myprog", "val1", "val2", "val3"]); @@ -471,7 +471,7 @@ fn positional_max_exact() { #[test] fn positional_max_less() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg(Arg::new("pos").help("multiple positionals").max_values(3)) .try_get_matches_from(vec!["myprog", "val1", "val2"]); @@ -488,7 +488,7 @@ fn positional_max_less() { #[test] fn positional_max_more() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg(Arg::new("pos").help("multiple positionals").max_values(3)) .try_get_matches_from(vec!["myprog", "val1", "val2", "val3", "val4"]); @@ -498,7 +498,7 @@ fn positional_max_more() { #[test] fn sep_long_equals() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .long("option") @@ -520,7 +520,7 @@ fn sep_long_equals() { #[test] fn sep_long_space() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .long("option") @@ -542,7 +542,7 @@ fn sep_long_space() { #[test] fn sep_short_equals() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -564,7 +564,7 @@ fn sep_short_equals() { #[test] fn sep_short_space() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -586,7 +586,7 @@ fn sep_short_space() { #[test] fn sep_short_no_space() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -608,7 +608,7 @@ fn sep_short_no_space() { #[test] fn sep_positional() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .help("multiple options") @@ -629,7 +629,7 @@ fn sep_positional() { #[test] fn different_sep() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .long("option") @@ -651,7 +651,7 @@ fn different_sep() { #[test] fn different_sep_positional() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .help("multiple options") @@ -672,7 +672,7 @@ fn different_sep_positional() { #[test] fn no_sep() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .long("option") @@ -692,7 +692,7 @@ fn no_sep() { #[test] fn no_sep_positional() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .help("multiple options") @@ -711,7 +711,7 @@ fn no_sep_positional() { #[test] fn req_delimiter_long() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .long("option") @@ -744,7 +744,7 @@ fn req_delimiter_long() { #[test] fn req_delimiter_long_with_equal() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .long("option") @@ -777,7 +777,7 @@ fn req_delimiter_long_with_equal() { #[test] fn req_delimiter_short_with_space() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -810,7 +810,7 @@ fn req_delimiter_short_with_space() { #[test] fn req_delimiter_short_with_no_space() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -843,7 +843,7 @@ fn req_delimiter_short_with_no_space() { #[test] fn req_delimiter_short_with_equal() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .short('o') @@ -876,7 +876,7 @@ fn req_delimiter_short_with_equal() { #[test] fn req_delimiter_complex() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("option") .long("option") @@ -950,7 +950,7 @@ fn req_delimiter_complex() { positional argument (i.e. the one with the highest index) *must* have \ .required(true) or .last(true) set."] fn low_index_positional_not_required() { - let _ = App::new("lip") + let _ = Command::new("lip") .arg( Arg::new("files") .index(1) @@ -968,7 +968,7 @@ fn low_index_positional_not_required() { #[should_panic = "Only one positional argument with .multiple_values(true) \ set is allowed per command, unless the second one also has .last(true) set"] fn low_index_positional_last_multiple_too() { - let _ = App::new("lip") + let _ = Command::new("lip") .arg( Arg::new("files") .index(1) @@ -992,7 +992,7 @@ fn low_index_positional_last_multiple_too() { #[should_panic = "Only the last positional argument, or second to \ last positional argument may be set to .multiple_values(true)"] fn low_index_positional_too_far_back() { - let _ = App::new("lip") + let _ = Command::new("lip") .arg( Arg::new("files") .index(1) @@ -1007,7 +1007,7 @@ fn low_index_positional_too_far_back() { #[test] fn low_index_positional() { - let m = App::new("lip") + let m = Command::new("lip") .arg( Arg::new("files") .index(1) @@ -1034,9 +1034,9 @@ fn low_index_positional() { #[test] fn low_index_positional_in_subcmd() { - let m = App::new("lip") + let m = Command::new("lip") .subcommand( - App::new("test") + Command::new("test") .arg( Arg::new("files") .index(1) @@ -1065,7 +1065,7 @@ fn low_index_positional_in_subcmd() { #[test] fn low_index_positional_with_option() { - let m = App::new("lip") + let m = Command::new("lip") .arg( Arg::new("files") .required(true) @@ -1096,7 +1096,7 @@ fn low_index_positional_with_option() { #[test] fn low_index_positional_with_flag() { - let m = App::new("lip") + let m = Command::new("lip") .arg( Arg::new("files") .index(1) @@ -1125,7 +1125,7 @@ fn low_index_positional_with_flag() { #[test] fn multiple_value_terminator_option() { - let m = App::new("lip") + let m = Command::new("lip") .arg( Arg::new("files") .short('f') @@ -1151,7 +1151,7 @@ fn multiple_value_terminator_option() { #[test] fn multiple_value_terminator_option_other_arg() { - let m = App::new("lip") + let m = Command::new("lip") .arg( Arg::new("files") .short('f') @@ -1178,7 +1178,7 @@ fn multiple_value_terminator_option_other_arg() { #[test] fn multiple_vals_with_hyphen() { - let res = App::new("do") + let res = Command::new("do") .arg( Arg::new("cmds") .takes_value(true) @@ -1207,7 +1207,7 @@ fn multiple_vals_with_hyphen() { #[test] fn issue_1480_max_values_consumes_extra_arg_1() { - let res = App::new("prog") + let res = Command::new("prog") .arg(Arg::new("field").max_values(1).long("field")) .arg(Arg::new("positional").required(true).index(1)) .try_get_matches_from(vec!["prog", "--field", "1", "file"]); @@ -1217,7 +1217,7 @@ fn issue_1480_max_values_consumes_extra_arg_1() { #[test] fn issue_1480_max_values_consumes_extra_arg_2() { - let res = App::new("prog") + let res = Command::new("prog") .arg(Arg::new("field").max_values(1).long("field")) .try_get_matches_from(vec!["prog", "--field", "1", "2"]); @@ -1227,7 +1227,7 @@ fn issue_1480_max_values_consumes_extra_arg_2() { #[test] fn issue_1480_max_values_consumes_extra_arg_3() { - let res = App::new("prog") + let res = Command::new("prog") .arg(Arg::new("field").max_values(1).long("field")) .try_get_matches_from(vec!["prog", "--field", "1", "2", "3"]); @@ -1237,7 +1237,7 @@ fn issue_1480_max_values_consumes_extra_arg_3() { #[test] fn issue_2229() { - let m = App::new("multiple_values") + let m = Command::new("multiple_values") .arg( Arg::new("pos") .help("multiple positionals") @@ -1253,7 +1253,7 @@ fn issue_2229() { #[test] fn value_names_building_num_vals() { - let m = App::new("test") + let m = Command::new("test") .arg( Arg::new("pos") .long("pos") @@ -1272,7 +1272,7 @@ fn value_names_building_num_vals() { #[test] fn value_names_building_num_vals_for_positional() { - let m = App::new("test") + let m = Command::new("test") .arg(Arg::new("pos").value_names(&["who", "what", "why"])) .try_get_matches_from(vec!["myprog", "val1", "val2", "val3"]); @@ -1287,7 +1287,7 @@ fn value_names_building_num_vals_for_positional() { #[test] fn number_of_values_preferred_over_value_names() { - let m = App::new("test") + let m = Command::new("test") .arg( Arg::new("pos") .long("pos") @@ -1307,7 +1307,7 @@ fn number_of_values_preferred_over_value_names() { #[test] fn values_per_occurrence_named() { - let mut a = App::new("test").arg( + let mut a = Command::new("test").arg( Arg::new("pos") .long("pos") .number_of_values(2) @@ -1339,7 +1339,7 @@ fn values_per_occurrence_named() { #[test] fn values_per_occurrence_positional() { - let mut a = App::new("test").arg( + let mut a = Command::new("test").arg( Arg::new("pos") .number_of_values(2) .multiple_occurrences(true), diff --git a/tests/builder/opts.rs b/tests/builder/opts.rs index 74f11af491f..5f8a63a2e11 100644 --- a/tests/builder/opts.rs +++ b/tests/builder/opts.rs @@ -1,6 +1,6 @@ use crate::utils; -use clap::{arg, error::ErrorKind, App, Arg, ArgMatches}; +use clap::{arg, error::ErrorKind, Arg, ArgMatches, Command}; #[cfg(feature = "suggestions")] static DYM: &str = @@ -32,7 +32,7 @@ For more information try --help #[test] fn require_equals_fail() { - let res = App::new("prog") + let res = Command::new("prog") .arg( Arg::new("cfg") .require_equals(true) @@ -55,14 +55,14 @@ USAGE: For more information try --help "; - let app = App::new("prog").arg( + let cmd = Command::new("prog").arg( Arg::new("cfg") .require_equals(true) .takes_value(true) .long("config"), ); assert!(utils::compare_output( - app, + cmd, "prog --config file.conf", NO_EQUALS, true @@ -71,7 +71,7 @@ For more information try --help #[test] fn require_equals_min_values_zero() { - let res = App::new("prog") + let res = Command::new("prog") .arg( Arg::new("cfg") .takes_value(true) @@ -89,7 +89,7 @@ fn require_equals_min_values_zero() { #[test] fn double_hyphen_as_value() { - let res = App::new("prog") + let res = Command::new("prog") .arg( Arg::new("cfg") .takes_value(true) @@ -103,7 +103,7 @@ fn double_hyphen_as_value() { #[test] fn require_equals_no_empty_values_fail() { - let res = App::new("prog") + let res = Command::new("prog") .arg( Arg::new("cfg") .takes_value(true) @@ -119,7 +119,7 @@ fn require_equals_no_empty_values_fail() { #[test] fn require_equals_empty_vals_pass() { - let res = App::new("prog") + let res = Command::new("prog") .arg( Arg::new("cfg") .takes_value(true) @@ -132,7 +132,7 @@ fn require_equals_empty_vals_pass() { #[test] fn require_equals_pass() { - let res = App::new("prog") + let res = Command::new("prog") .arg( Arg::new("cfg") .takes_value(true) @@ -145,7 +145,7 @@ fn require_equals_pass() { #[test] fn stdin_char() { - let r = App::new("opts") + let r = Command::new("opts") .arg(arg!(f: -f [flag] "some flag")) .try_get_matches_from(vec!["", "-f", "-"]); assert!(r.is_ok(), "{}", r.unwrap_err()); @@ -156,7 +156,7 @@ fn stdin_char() { #[test] fn opts_using_short() { - let r = App::new("opts") + let r = Command::new("opts") .args(&[ arg!(f: -f [flag] "some flag"), arg!(c: -c [color] "some other flag"), @@ -172,7 +172,7 @@ fn opts_using_short() { #[test] fn lots_o_vals() { - let r = App::new("opts") + let r = Command::new("opts") .arg(arg!(o: -o "some opt").multiple_values(true)) .try_get_matches_from(vec![ "", "-o", "some", "some", "some", "some", "some", "some", "some", "some", "some", @@ -212,7 +212,7 @@ fn lots_o_vals() { #[test] fn opts_using_long_space() { - let r = App::new("opts") + let r = Command::new("opts") .args(&[ arg!(--flag [flag] "some flag"), arg!(--color [color] "some other flag"), @@ -228,7 +228,7 @@ fn opts_using_long_space() { #[test] fn opts_using_long_equals() { - let r = App::new("opts") + let r = Command::new("opts") .args(&[ arg!(--flag [flag] "some flag"), arg!(--color [color] "some other flag"), @@ -244,7 +244,7 @@ fn opts_using_long_equals() { #[test] fn opts_using_mixed() { - let r = App::new("opts") + let r = Command::new("opts") .args(&[ arg!(-f --flag [flag] "some flag"), arg!(-c --color [color] "some other flag"), @@ -260,7 +260,7 @@ fn opts_using_mixed() { #[test] fn opts_using_mixed2() { - let r = App::new("opts") + let r = Command::new("opts") .args(&[ arg!(-f --flag [flag] "some flag"), arg!(-c --color [color] "some other flag"), @@ -276,7 +276,7 @@ fn opts_using_mixed2() { #[test] fn default_values_user_value() { - let r = App::new("df") + let r = Command::new("df") .arg(arg!(o: -o [opt] "some opt").default_value("default")) .try_get_matches_from(vec!["", "-o", "value"]); assert!(r.is_ok(), "{}", r.unwrap_err()); @@ -287,7 +287,7 @@ fn default_values_user_value() { #[test] fn multiple_vals_pos_arg_equals() { - let r = App::new("mvae") + let r = Command::new("mvae") .arg(arg!(o: -o [opt] ... "some opt")) .arg(arg!([file] "some file")) .try_get_matches_from(vec!["", "-o=1", "some"]); @@ -301,7 +301,7 @@ fn multiple_vals_pos_arg_equals() { #[test] fn multiple_vals_pos_arg_delim() { - let r = App::new("mvae") + let r = Command::new("mvae") .arg( arg!(o: -o "some opt") .multiple_values(true) @@ -319,7 +319,7 @@ fn multiple_vals_pos_arg_delim() { #[test] fn require_delims_no_delim() { - let r = App::new("mvae") + let r = Command::new("mvae") .arg( arg!(o: -o [opt] ... "some opt") .use_value_delimiter(true) @@ -334,7 +334,7 @@ fn require_delims_no_delim() { #[test] fn require_delims() { - let r = App::new("mvae") + let r = Command::new("mvae") .arg( arg!(o: -o "some opt") .multiple_values(true) @@ -353,7 +353,7 @@ fn require_delims() { #[test] fn leading_hyphen_pass() { - let r = App::new("mvae") + let r = Command::new("mvae") .arg( arg!(o: -o "some opt") .multiple_values(true) @@ -368,7 +368,7 @@ fn leading_hyphen_pass() { #[test] fn leading_hyphen_fail() { - let r = App::new("mvae") + let r = Command::new("mvae") .arg(arg!(o: -o "some opt")) .try_get_matches_from(vec!["", "-o", "-2"]); assert!(r.is_err()); @@ -378,7 +378,7 @@ fn leading_hyphen_fail() { #[test] fn leading_hyphen_with_flag_after() { - let r = App::new("mvae") + let r = Command::new("mvae") .arg( arg!(o: -o "some opt") .multiple_values(true) @@ -395,7 +395,7 @@ fn leading_hyphen_with_flag_after() { #[test] fn leading_hyphen_with_flag_before() { - let r = App::new("mvae") + let r = Command::new("mvae") .arg(arg!(o: -o [opt] ... "some opt").allow_hyphen_values(true)) .arg(arg!(f: -f "some flag")) .try_get_matches_from(vec!["", "-f", "-o", "-2"]); @@ -408,7 +408,7 @@ fn leading_hyphen_with_flag_before() { #[test] fn leading_hyphen_with_only_pos_follows() { - let r = App::new("mvae") + let r = Command::new("mvae") .arg( arg!(o: -o [opt] ... "some opt") .number_of_values(1) @@ -437,7 +437,7 @@ fn did_you_mean() { #[test] fn issue_1047_min_zero_vals_default_val() { - let m = App::new("foo") + let m = Command::new("foo") .arg( Arg::new("del") .short('d') @@ -454,7 +454,7 @@ fn issue_1047_min_zero_vals_default_val() { } fn issue_1105_setup(argv: Vec<&'static str>) -> Result { - App::new("opts") + Command::new("opts") .arg(arg!(-o --option "some option")) .arg(arg!(--flag "some flag")) .try_get_matches_from(argv) @@ -462,14 +462,14 @@ fn issue_1105_setup(argv: Vec<&'static str>) -> Result #[test] fn issue_1105_empty_value_long_fail() { - let r = issue_1105_setup(vec!["app", "--option", "--flag"]); + let r = issue_1105_setup(vec!["cmd", "--option", "--flag"]); assert!(r.is_err()); assert_eq!(r.unwrap_err().kind(), ErrorKind::EmptyValue); } #[test] fn issue_1105_empty_value_long_explicit() { - let r = issue_1105_setup(vec!["app", "--option", ""]); + let r = issue_1105_setup(vec!["cmd", "--option", ""]); assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert_eq!(m.value_of("option"), Some("")); @@ -477,7 +477,7 @@ fn issue_1105_empty_value_long_explicit() { #[test] fn issue_1105_empty_value_long_equals() { - let r = issue_1105_setup(vec!["app", "--option="]); + let r = issue_1105_setup(vec!["cmd", "--option="]); assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert_eq!(m.value_of("option"), Some("")); @@ -485,14 +485,14 @@ fn issue_1105_empty_value_long_equals() { #[test] fn issue_1105_empty_value_short_fail() { - let r = issue_1105_setup(vec!["app", "-o", "--flag"]); + let r = issue_1105_setup(vec!["cmd", "-o", "--flag"]); assert!(r.is_err()); assert_eq!(r.unwrap_err().kind(), ErrorKind::EmptyValue); } #[test] fn issue_1105_empty_value_short_explicit() { - let r = issue_1105_setup(vec!["app", "-o", ""]); + let r = issue_1105_setup(vec!["cmd", "-o", ""]); assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert_eq!(m.value_of("option"), Some("")); @@ -500,7 +500,7 @@ fn issue_1105_empty_value_short_explicit() { #[test] fn issue_1105_empty_value_short_equals() { - let r = issue_1105_setup(vec!["app", "-o="]); + let r = issue_1105_setup(vec!["cmd", "-o="]); assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert_eq!(m.value_of("option"), Some("")); @@ -508,7 +508,7 @@ fn issue_1105_empty_value_short_equals() { #[test] fn issue_1105_empty_value_short_explicit_no_space() { - let r = issue_1105_setup(vec!["app", "-o", ""]); + let r = issue_1105_setup(vec!["cmd", "-o", ""]); assert!(r.is_ok(), "{}", r.unwrap_err()); let m = r.unwrap(); assert_eq!(m.value_of("option"), Some("")); @@ -517,11 +517,11 @@ fn issue_1105_empty_value_short_explicit_no_space() { #[test] #[cfg(feature = "suggestions")] fn issue_1073_suboptimal_flag_suggestion() { - let app = App::new("ripgrep-616") + let cmd = Command::new("ripgrep-616") .arg(Arg::new("files-with-matches").long("files-with-matches")) .arg(Arg::new("files-without-match").long("files-without-match")); assert!(utils::compare_output( - app, + cmd, "ripgrep-616 --files-without-matches", DYM_ISSUE_1073, true @@ -530,7 +530,7 @@ fn issue_1073_suboptimal_flag_suggestion() { #[test] fn short_non_ascii_no_space() { - let matches = App::new("app") + let matches = Command::new("cmd") .arg(arg!(opt: -'磨' )) .try_get_matches_from(&["test", "-磨VALUE"]) .unwrap(); @@ -540,7 +540,7 @@ fn short_non_ascii_no_space() { #[test] fn short_eq_val_starts_with_eq() { - let matches = App::new("app") + let matches = Command::new("cmd") .arg(arg!(opt: -f )) .try_get_matches_from(&["test", "-f==value"]) .unwrap(); @@ -550,7 +550,7 @@ fn short_eq_val_starts_with_eq() { #[test] fn long_eq_val_starts_with_eq() { - let matches = App::new("app") + let matches = Command::new("cmd") .arg(arg!(opt: --foo )) .try_get_matches_from(&["test", "--foo==value"]) .unwrap(); @@ -560,16 +560,16 @@ fn long_eq_val_starts_with_eq() { #[test] fn issue_2022_get_flags_misuse() { - let app = App::new("test") + let cmd = Command::new("test") .next_help_heading(Some("test")) .arg(Arg::new("a").long("a").default_value("32")); - let matches = app.try_get_matches_from(&[""]).unwrap(); + let matches = cmd.try_get_matches_from(&[""]).unwrap(); assert!(matches.value_of("a").is_some()) } #[test] fn issue_2279() { - let before_help_heading = App::new("app") + let before_help_heading = Command::new("cmd") .arg(Arg::new("foo").short('f').default_value("bar")) .next_help_heading(Some("This causes default_value to be ignored")) .try_get_matches_from(&[""]) @@ -577,7 +577,7 @@ fn issue_2279() { assert_eq!(before_help_heading.value_of("foo"), Some("bar")); - let after_help_heading = App::new("app") + let after_help_heading = Command::new("cmd") .next_help_heading(Some("This causes default_value to be ignored")) .arg(Arg::new("foo").short('f').default_value("bar")) .try_get_matches_from(&[""]) @@ -588,39 +588,39 @@ fn issue_2279() { #[test] fn infer_long_arg() { - let app = App::new("test") + let cmd = Command::new("test") .infer_long_args(true) .arg(Arg::new("racetrack").long("racetrack").alias("autobahn")) .arg(Arg::new("racecar").long("racecar").takes_value(true)); - let matches = app + let matches = cmd .clone() .try_get_matches_from(&["test", "--racec=hello"]) .unwrap(); assert!(!matches.is_present("racetrack")); assert_eq!(matches.value_of("racecar"), Some("hello")); - let matches = app + let matches = cmd .clone() .try_get_matches_from(&["test", "--racet"]) .unwrap(); assert!(matches.is_present("racetrack")); assert_eq!(matches.value_of("racecar"), None); - let matches = app + let matches = cmd .clone() .try_get_matches_from(&["test", "--auto"]) .unwrap(); assert!(matches.is_present("racetrack")); assert_eq!(matches.value_of("racecar"), None); - let app = App::new("test") + let cmd = Command::new("test") .infer_long_args(true) .arg(Arg::new("arg").long("arg")); - let matches = app.clone().try_get_matches_from(&["test", "--"]).unwrap(); + let matches = cmd.clone().try_get_matches_from(&["test", "--"]).unwrap(); assert!(!matches.is_present("arg")); - let matches = app.clone().try_get_matches_from(&["test", "--a"]).unwrap(); + let matches = cmd.clone().try_get_matches_from(&["test", "--a"]).unwrap(); assert!(matches.is_present("arg")); } diff --git a/tests/builder/positionals.rs b/tests/builder/positionals.rs index 485f3e4f1c3..4ad3856e9d0 100644 --- a/tests/builder/positionals.rs +++ b/tests/builder/positionals.rs @@ -1,8 +1,8 @@ -use clap::{arg, error::ErrorKind, App, Arg}; +use clap::{arg, error::ErrorKind, Arg, Command}; #[test] fn only_pos_follow() { - let r = App::new("onlypos") + let r = Command::new("onlypos") .args(&[arg!(f: -f [flag] "some opt"), arg!([arg] "some arg")]) .try_get_matches_from(vec!["", "--", "-f"]); assert!(r.is_ok(), "{}", r.unwrap_err()); @@ -14,7 +14,7 @@ fn only_pos_follow() { #[test] fn issue_946() { - let r = App::new("compiletest") + let r = Command::new("compiletest") .allow_hyphen_values(true) .arg(arg!(--exact "filters match exactly")) .arg( @@ -33,7 +33,7 @@ fn issue_946() { #[test] fn positional() { - let r = App::new("positional") + let r = Command::new("positional") .args(&[arg!(-f --flag "some flag"), Arg::new("positional").index(1)]) .try_get_matches_from(vec!["", "-f", "test"]); assert!(r.is_ok(), "{:#?}", r); @@ -42,7 +42,7 @@ fn positional() { assert!(m.is_present("flag")); assert_eq!(m.value_of("positional").unwrap(), "test"); - let m = App::new("positional") + let m = Command::new("positional") .args(&[arg!(-f --flag "some flag"), Arg::new("positional").index(1)]) .try_get_matches_from(vec!["", "test", "--flag"]) .unwrap(); @@ -53,7 +53,7 @@ fn positional() { #[test] fn lots_o_vals() { - let r = App::new("opts") + let r = Command::new("opts") .arg(arg!(... "some pos")) .try_get_matches_from(vec![ "", "some", "some", "some", "some", "some", "some", "some", "some", "some", "some", @@ -93,7 +93,7 @@ fn lots_o_vals() { #[test] fn positional_multiple() { - let r = App::new("positional_multiple") + let r = Command::new("positional_multiple") .args(&[ arg!(-f --flag "some flag"), Arg::new("positional") @@ -114,7 +114,7 @@ fn positional_multiple() { #[test] fn positional_multiple_3() { - let r = App::new("positional_multiple") + let r = Command::new("positional_multiple") .args(&[ arg!(-f --flag "some flag"), Arg::new("positional") @@ -135,7 +135,7 @@ fn positional_multiple_3() { #[test] fn positional_multiple_2() { - let result = App::new("positional_multiple") + let result = Command::new("positional_multiple") .args(&[arg!(-f --flag "some flag"), Arg::new("positional").index(1)]) .try_get_matches_from(vec!["", "-f", "test1", "test2", "test3"]); assert!(result.is_err()); @@ -145,7 +145,7 @@ fn positional_multiple_2() { #[test] fn positional_possible_values() { - let r = App::new("positional_possible_values") + let r = Command::new("positional_possible_values") .args(&[ arg!(-f --flag "some flag"), Arg::new("positional").index(1).possible_value("test123"), @@ -163,7 +163,7 @@ fn positional_possible_values() { #[test] fn create_positional() { - let _ = App::new("test") + let _ = Command::new("test") .arg(Arg::new("test").index(1).help("testing testing")) .try_get_matches_from(vec![""]) .unwrap(); @@ -171,7 +171,7 @@ fn create_positional() { #[test] fn positional_hyphen_does_not_panic() { - let _ = App::new("test") + let _ = Command::new("test") .arg(Arg::new("dummy")) .try_get_matches_from(vec!["test", "-"]) .unwrap(); @@ -179,36 +179,36 @@ fn positional_hyphen_does_not_panic() { #[test] fn single_positional_usage_string() { - let mut app = App::new("test").arg(arg!([FILE] "some file")); - assert_eq!(app.render_usage(), "USAGE:\n test [FILE]"); + let mut cmd = Command::new("test").arg(arg!([FILE] "some file")); + assert_eq!(cmd.render_usage(), "USAGE:\n test [FILE]"); } #[test] fn single_positional_multiple_usage_string() { - let mut app = App::new("test").arg(arg!([FILE]... "some file")); - assert_eq!(app.render_usage(), "USAGE:\n test [FILE]..."); + let mut cmd = Command::new("test").arg(arg!([FILE]... "some file")); + assert_eq!(cmd.render_usage(), "USAGE:\n test [FILE]..."); } #[test] fn multiple_positional_usage_string() { - let mut app = App::new("test") + let mut cmd = Command::new("test") .arg(arg!([FILE] "some file")) .arg(arg!([FILES]... "some file")); - assert_eq!(app.render_usage(), "USAGE:\n test [ARGS]"); + assert_eq!(cmd.render_usage(), "USAGE:\n test [ARGS]"); } #[test] fn multiple_positional_one_required_usage_string() { - let mut app = App::new("test") + let mut cmd = Command::new("test") .arg(arg!( "some file")) .arg(arg!([FILES]... "some file")); - assert_eq!(app.render_usage(), "USAGE:\n test [FILES]..."); + assert_eq!(cmd.render_usage(), "USAGE:\n test [FILES]..."); } #[test] fn single_positional_required_usage_string() { - let mut app = App::new("test").arg(arg!( "some file")); - assert_eq!(app.render_usage(), "USAGE:\n test "); + let mut cmd = Command::new("test").arg(arg!( "some file")); + assert_eq!(cmd.render_usage(), "USAGE:\n test "); } // This tests a programmer error and will only succeed with debug_assertions @@ -217,7 +217,7 @@ fn single_positional_required_usage_string() { #[should_panic = "Found non-required positional argument \ with a lower index than a required positional argument"] fn missing_required() { - let _ = App::new("test") + let _ = Command::new("test") .arg(arg!([FILE1] "some file")) .arg(arg!( "some file")) .try_get_matches_from(vec![""]); @@ -225,7 +225,7 @@ fn missing_required() { #[test] fn missing_required_2() { - let r = App::new("test") + let r = Command::new("test") .arg(arg!( "some file")) .arg(arg!( "some file")) .try_get_matches_from(vec!["test", "file"]); @@ -235,7 +235,7 @@ fn missing_required_2() { #[test] fn last_positional() { - let r = App::new("test") + let r = Command::new("test") .arg(arg!( "some target")) .arg(arg!([CORPUS] "some corpus")) .arg(arg!([ARGS]... "some file").last(true)) @@ -247,7 +247,7 @@ fn last_positional() { #[test] fn last_positional_no_double_dash() { - let r = App::new("test") + let r = Command::new("test") .arg(arg!( "some target")) .arg(arg!([CORPUS] "some corpus")) .arg(arg!([ARGS]... "some file").last(true)) @@ -258,7 +258,7 @@ fn last_positional_no_double_dash() { #[test] fn last_positional_second_to_last_mult() { - let r = App::new("test") + let r = Command::new("test") .arg(arg!( "some target")) .arg(arg!([CORPUS]... "some corpus")) .arg(arg!([ARGS]... "some file").last(true)) @@ -270,9 +270,9 @@ fn last_positional_second_to_last_mult() { #[test] #[should_panic = "Argument 'arg' is a positional argument and can't have short or long name versions"] fn positional_arg_with_long() { - use clap::{App, Arg}; + use clap::{Arg, Command}; - let _ = App::new("test") + let _ = Command::new("test") .arg(Arg::new("arg").index(1).long("arg")) .try_get_matches(); } @@ -281,16 +281,16 @@ fn positional_arg_with_long() { #[test] #[should_panic = "Argument 'arg' is a positional argument and can't have short or long name versions"] fn positional_arg_with_short() { - use clap::{App, Arg}; + use clap::{Arg, Command}; - let _ = App::new("test") + let _ = Command::new("test") .arg(Arg::new("arg").index(1).short('a')) .try_get_matches(); } #[test] fn ignore_hyphen_values_on_last() { - let app = clap::App::new("foo") + let cmd = clap::Command::new("foo") .arg( clap::Arg::new("cmd") .multiple_values(true) @@ -305,6 +305,6 @@ fn ignore_hyphen_values_on_last() { .required(false), ); - let matches = app.try_get_matches_from(["test", "-n", "foo"]).unwrap(); + let matches = cmd.try_get_matches_from(["test", "-n", "foo"]).unwrap(); assert_eq!(matches.value_of("name"), Some("foo")); } diff --git a/tests/builder/posix_compatible.rs b/tests/builder/posix_compatible.rs index 30d67f0f08d..09a0120d81a 100644 --- a/tests/builder/posix_compatible.rs +++ b/tests/builder/posix_compatible.rs @@ -1,8 +1,8 @@ -use clap::{arg, error::ErrorKind, App, Arg}; +use clap::{arg, error::ErrorKind, Arg, Command}; #[test] fn flag_overrides_itself() { - let res = App::new("posix") + let res = Command::new("posix") .arg( arg!(--flag "some flag" ) @@ -17,7 +17,7 @@ fn flag_overrides_itself() { #[test] fn mult_flag_overrides_itself() { - let res = App::new("posix") + let res = Command::new("posix") .arg(arg!(--flag ... "some flag").overrides_with("flag")) .try_get_matches_from(vec!["", "--flag", "--flag", "--flag", "--flag"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -28,7 +28,7 @@ fn mult_flag_overrides_itself() { #[test] fn option_overrides_itself() { - let res = App::new("posix") + let res = Command::new("posix") .arg( arg!(--opt "some option") .required(false) @@ -44,7 +44,7 @@ fn option_overrides_itself() { #[test] fn mult_option_require_delim_overrides_itself() { - let res = App::new("posix") + let res = Command::new("posix") .arg( arg!(--opt ... "some option") .required(false) @@ -67,7 +67,7 @@ fn mult_option_require_delim_overrides_itself() { #[test] fn mult_option_overrides_itself() { - let res = App::new("posix") + let res = Command::new("posix") .arg( arg!(--opt ... "some option") .required(false) @@ -96,7 +96,7 @@ fn mult_option_overrides_itself() { #[test] fn option_use_delim_false_override_itself() { - let m = App::new("posix") + let m = Command::new("posix") .arg( arg!(--opt "some option") .required(false) @@ -115,7 +115,7 @@ fn option_use_delim_false_override_itself() { #[test] fn pos_mult_overrides_itself() { // opts with multiple - let res = App::new("posix") + let res = Command::new("posix") .arg(arg!([val] ... "some pos").overrides_with("val")) .try_get_matches_from(vec!["", "some", "other", "value"]); assert!(res.is_ok(), "{}", res.unwrap_err()); @@ -129,7 +129,7 @@ fn pos_mult_overrides_itself() { } #[test] fn posix_compatible_flags_long() { - let m = App::new("posix") + let m = Command::new("posix") .arg(arg!(--flag "some flag").overrides_with("color")) .arg(arg!(--color "some other flag")) .try_get_matches_from(vec!["", "--flag", "--color"]) @@ -140,7 +140,7 @@ fn posix_compatible_flags_long() { #[test] fn posix_compatible_flags_long_rev() { - let m = App::new("posix") + let m = Command::new("posix") .arg(arg!(--flag "some flag").overrides_with("color")) .arg(arg!(--color "some other flag")) .try_get_matches_from(vec!["", "--color", "--flag"]) @@ -151,7 +151,7 @@ fn posix_compatible_flags_long_rev() { #[test] fn posix_compatible_flags_short() { - let m = App::new("posix") + let m = Command::new("posix") .arg(arg!(-f --flag "some flag").overrides_with("color")) .arg(arg!(-c --color "some other flag")) .try_get_matches_from(vec!["", "-f", "-c"]) @@ -162,7 +162,7 @@ fn posix_compatible_flags_short() { #[test] fn posix_compatible_flags_short_rev() { - let m = App::new("posix") + let m = Command::new("posix") .arg(arg!(-f --flag "some flag").overrides_with("color")) .arg(arg!(-c --color "some other flag")) .try_get_matches_from(vec!["", "-c", "-f"]) @@ -173,7 +173,7 @@ fn posix_compatible_flags_short_rev() { #[test] fn posix_compatible_opts_long() { - let m = App::new("posix") + let m = Command::new("posix") .arg( arg!(--flag "some flag") .required(false) @@ -189,7 +189,7 @@ fn posix_compatible_opts_long() { #[test] fn posix_compatible_opts_long_rev() { - let m = App::new("posix") + let m = Command::new("posix") .arg( arg!(--flag "some flag") .required(false) @@ -205,7 +205,7 @@ fn posix_compatible_opts_long_rev() { #[test] fn posix_compatible_opts_long_equals() { - let m = App::new("posix") + let m = Command::new("posix") .arg( arg!(--flag "some flag") .required(false) @@ -221,7 +221,7 @@ fn posix_compatible_opts_long_equals() { #[test] fn posix_compatible_opts_long_equals_rev() { - let m = App::new("posix") + let m = Command::new("posix") .arg( arg!(--flag "some flag") .required(false) @@ -237,7 +237,7 @@ fn posix_compatible_opts_long_equals_rev() { #[test] fn posix_compatible_opts_short() { - let m = App::new("posix") + let m = Command::new("posix") .arg( arg!(f: -f "some flag") .required(false) @@ -253,7 +253,7 @@ fn posix_compatible_opts_short() { #[test] fn posix_compatible_opts_short_rev() { - let m = App::new("posix") + let m = Command::new("posix") .arg( arg!(f: -f "some flag") .required(false) @@ -269,7 +269,7 @@ fn posix_compatible_opts_short_rev() { #[test] fn conflict_overridden() { - let m = App::new("conflict_overridden") + let m = Command::new("conflict_overridden") .arg(arg!(-f --flag "some flag").conflicts_with("debug")) .arg(arg!(-d --debug "other flag")) .arg(arg!(-c --color "third flag").overrides_with("flag")) @@ -282,7 +282,7 @@ fn conflict_overridden() { #[test] fn conflict_overridden_2() { - let result = App::new("conflict_overridden") + let result = Command::new("conflict_overridden") .arg(arg!(-f --flag "some flag").conflicts_with("debug")) .arg(arg!(-d --debug "other flag")) .arg(arg!(-c --color "third flag").overrides_with("flag")) @@ -296,7 +296,7 @@ fn conflict_overridden_2() { #[test] fn conflict_overridden_3() { - let result = App::new("conflict_overridden") + let result = Command::new("conflict_overridden") .arg(arg!(-f --flag "some flag").conflicts_with("debug")) .arg(arg!(-d --debug "other flag")) .arg(arg!(-c --color "third flag").overrides_with("flag")) @@ -308,7 +308,7 @@ fn conflict_overridden_3() { #[test] fn conflict_overridden_4() { - let m = App::new("conflict_overridden") + let m = Command::new("conflict_overridden") .arg(arg!(-f --flag "some flag").conflicts_with("debug")) .arg(arg!(-d --debug "other flag")) .arg(arg!(-c --color "third flag").overrides_with("flag")) @@ -321,7 +321,7 @@ fn conflict_overridden_4() { #[test] fn pos_required_overridden_by_flag() { - let result = App::new("require_overridden") + let result = Command::new("require_overridden") .arg(Arg::new("pos").index(1).required(true)) .arg(arg!(-c --color "some flag").overrides_with("pos")) .try_get_matches_from(vec!["", "test", "-c"]); @@ -330,7 +330,7 @@ fn pos_required_overridden_by_flag() { #[test] fn require_overridden_2() { - let m = App::new("require_overridden") + let m = Command::new("require_overridden") .arg(Arg::new("req_pos").required(true)) .arg(arg!(-c --color "other flag").overrides_with("req_pos")) .try_get_matches_from(vec!["", "-c", "req_pos"]) @@ -341,7 +341,7 @@ fn require_overridden_2() { #[test] fn require_overridden_3() { - let m = App::new("require_overridden") + let m = Command::new("require_overridden") .arg(arg!(-f --flag "some flag").requires("debug")) .arg(arg!(-d --debug "other flag")) .arg(arg!(-c --color "third flag").overrides_with("flag")) @@ -354,7 +354,7 @@ fn require_overridden_3() { #[test] fn require_overridden_4() { - let result = App::new("require_overridden") + let result = Command::new("require_overridden") .arg(arg!(-f --flag "some flag").requires("debug")) .arg(arg!(-d --debug "other flag")) .arg(arg!(-c --color "third flag").overrides_with("flag")) @@ -366,19 +366,19 @@ fn require_overridden_4() { #[test] fn issue_1374_overrides_self_with_multiple_values() { - let app = App::new("test").arg( + let cmd = Command::new("test").arg( Arg::new("input") .long("input") .takes_value(true) .overrides_with("input") .min_values(0), ); - let m = app + let m = cmd .clone() .try_get_matches_from(&["test", "--input", "a", "b", "c", "--input", "d"]) .unwrap(); assert_eq!(m.values_of("input").unwrap().collect::>(), &["d"]); - let m = app + let m = cmd .clone() .try_get_matches_from(&["test", "--input", "a", "b", "--input", "c", "d"]) .unwrap(); @@ -390,10 +390,10 @@ fn issue_1374_overrides_self_with_multiple_values() { #[test] fn incremental_override() { - let mut app = App::new("test") + let mut cmd = Command::new("test") .arg(arg!(--name ).multiple_occurrences(true)) .arg(arg!(--"no-name").overrides_with("name")); - let m = app + let m = cmd .try_get_matches_from_mut(&["test", "--name=ahmed", "--no-name", "--name=ali"]) .unwrap(); assert_eq!(m.values_of("name").unwrap().collect::>(), &["ali"]); diff --git a/tests/builder/possible_values.rs b/tests/builder/possible_values.rs index 533e0ebf782..61f87ebd39d 100644 --- a/tests/builder/possible_values.rs +++ b/tests/builder/possible_values.rs @@ -1,6 +1,6 @@ use crate::utils; -use clap::{error::ErrorKind, App, Arg, PossibleValue}; +use clap::{error::ErrorKind, Arg, Command, PossibleValue}; #[cfg(feature = "suggestions")] static PV_ERROR: &str = "error: \"slo\" isn't a valid value for '-O