Skip to content

Commit

Permalink
refactor: remove code going to other crates and deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin K committed Oct 20, 2018
1 parent eaa0700 commit 0333380
Show file tree
Hide file tree
Showing 63 changed files with 790 additions and 3,359 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ fn main() {
.about("controls testing features")
.version("1.3")
.author("Someone E. <someone_else@other.com>")
.arg_from_usage("-d, --debug 'Print debug information'"))
.arg("-d, --debug 'Print debug information'"))
.get_matches();

// Same as previous example...
Expand Down
10 changes: 5 additions & 5 deletions benches/03_complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
extern crate clap;
extern crate test;

use clap::{App, AppSettings, Arg, ArgSettings, SubCommand};
use clap::{App, AppSettings, Arg, ArgSettings, };

use test::Bencher;

Expand Down Expand Up @@ -39,12 +39,12 @@ macro_rules! create_app {
Arg::from("--maxvals3 [maxvals]... 'Tests 3 max vals'").max_values(3),
])
.subcommand(
SubCommand::with_name("subcmd")
App::new("subcmd")
.about("tests subcommands")
.version("0.1")
.author("Kevin K. <kbknapp@gmail.com>")
.arg_from_usage("-o --option [scoption]... 'tests options'")
.arg_from_usage("[scpositional] 'tests positionals'"),
.arg("-o --option [scoption]... 'tests options'")
.arg("[scpositional] 'tests positionals'"),
)
}};
}
Expand Down Expand Up @@ -146,7 +146,7 @@ fn create_app_builder(b: &mut Bencher) {
.max_values(3),
)
.subcommand(
SubCommand::with_name("subcmd")
App::new("subcmd")
.about("tests subcommands")
.version("0.1")
.author("Kevin K. <kbknapp@gmail.com>")
Expand Down
8 changes: 4 additions & 4 deletions benches/04_new_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use test::Bencher;
use std::io::Cursor;

use clap::App;
use clap::{Arg, ArgSettings, SubCommand};
use clap::{Arg, ArgSettings, };

fn build_help(app: &mut App) -> String {
let mut buf = Cursor::new(Vec::with_capacity(50));
Expand All @@ -28,9 +28,9 @@ fn app_example1<'b, 'c>() -> App<'b, 'c> {
-d... 'Turn debugging information on'",
)
.subcommand(
SubCommand::with_name("test")
App::new("test")
.about("does testing things")
.arg_from_usage("-l, --list 'lists test values'"),
.arg("-l, --list 'lists test values'"),
)
}

Expand Down Expand Up @@ -59,7 +59,7 @@ fn app_example3<'b, 'c>() -> App<'b, 'c> {
.index(1)
.setting(ArgSettings::Required),
])
.arg_from_usage("--license 'display the license file'")
.arg("--license 'display the license file'")
.args_from_usage(
"[output] 'Supply an output file to use'
-i, --int=[IFACE] 'Set an interface to use'",
Expand Down
88 changes: 44 additions & 44 deletions benches/06_rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
extern crate clap;
extern crate test;

use clap::{App, AppSettings, Arg, ArgGroup, ArgSettings, Shell, SubCommand};
use clap::{App, AppSettings, Arg, ArgGroup, ArgSettings, Shell, };

use test::Bencher;

Expand All @@ -34,102 +34,102 @@ pub fn build_cli() -> App<'static, 'static> {
.help("Enable verbose output")
.short('v')
.long("verbose"))
.subcommand(SubCommand::with_name("show")
.subcommand(App::new("show")
.about("Show the active and installed toolchains")
.after_help(SHOW_HELP))
.subcommand(SubCommand::with_name("install")
.subcommand(App::new("install")
.about("Update Rust toolchains")
.after_help(TOOLCHAIN_INSTALL_HELP)
.setting(AppSettings::Hidden) // synonym for 'toolchain install'
.arg(Arg::with_name("toolchain")
.setting(ArgSettings::Required)))
.subcommand(SubCommand::with_name("update")
.subcommand(App::new("update")
.about("Update Rust toolchains")
.after_help(UPDATE_HELP)
.arg(Arg::with_name("toolchain").setting(ArgSettings::Required))
.arg(Arg::with_name("no-self-update")
.help("Don't perform self update when running the `rustup` command")
.long("no-self-update")
.setting(ArgSettings::Hidden)))
.subcommand(SubCommand::with_name("default")
.subcommand(App::new("default")
.about("Set the default toolchain")
.after_help(DEFAULT_HELP)
.arg(Arg::with_name("toolchain").setting(ArgSettings::Required)))
.subcommand(SubCommand::with_name("toolchain")
.subcommand(App::new("toolchain")
.about("Modify or query the installed toolchains")
.after_help(TOOLCHAIN_HELP)
.setting(AppSettings::DeriveDisplayOrder)
// .setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(SubCommand::with_name("list").about("List installed toolchains"))
.subcommand(SubCommand::with_name("install")
.subcommand(App::new("list").about("List installed toolchains"))
.subcommand(App::new("install")
.about("Install or update a given toolchain")
.arg(Arg::with_name("toolchain").setting(ArgSettings::Required)))
.subcommand(SubCommand::with_name("uninstall")
.subcommand(App::new("uninstall")
.about("Uninstall a toolchain")
.arg(Arg::with_name("toolchain").setting(ArgSettings::Required)))
.subcommand(SubCommand::with_name("link")
.subcommand(App::new("link")
.about("Create a custom toolchain by symlinking to a directory")
.arg(Arg::with_name("toolchain").setting(ArgSettings::Required))
.arg(Arg::with_name("path").setting(ArgSettings::Required)))
.subcommand(SubCommand::with_name("update")
.subcommand(App::new("update")
.setting(AppSettings::Hidden) // synonym for 'install'
.arg(Arg::with_name("toolchain")
.setting(ArgSettings::Required)))
.subcommand(SubCommand::with_name("add")
.subcommand(App::new("add")
.setting(AppSettings::Hidden) // synonym for 'install'
.arg(Arg::with_name("toolchain")
.setting(ArgSettings::Required)))
.subcommand(SubCommand::with_name("remove")
.subcommand(App::new("remove")
.setting(AppSettings::Hidden) // synonym for 'uninstall'
.arg(Arg::with_name("toolchain")
.setting(ArgSettings::Required))))
.subcommand(SubCommand::with_name("target")
.subcommand(App::new("target")
.about("Modify a toolchain's supported targets")
.setting(AppSettings::VersionlessSubcommands)
.setting(AppSettings::DeriveDisplayOrder)
// .setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(SubCommand::with_name("list")
.subcommand(App::new("list")
.about("List installed and available targets")
.arg(Arg::with_name("toolchain")
.long("toolchain")
.setting(ArgSettings::TakesValue)))
.subcommand(SubCommand::with_name("add")
.subcommand(App::new("add")
.about("Add a target to a Rust toolchain")
.arg(Arg::with_name("target").setting(ArgSettings::Required))
.arg(Arg::with_name("toolchain")
.long("toolchain")
.setting(ArgSettings::TakesValue)))
.subcommand(SubCommand::with_name("remove")
.subcommand(App::new("remove")
.about("Remove a target from a Rust toolchain")
.arg(Arg::with_name("target").setting(ArgSettings::Required))
.arg(Arg::with_name("toolchain")
.long("toolchain")
.setting(ArgSettings::TakesValue)))
.subcommand(SubCommand::with_name("install")
.subcommand(App::new("install")
.setting(AppSettings::Hidden) // synonym for 'add'
.arg(Arg::with_name("target")
.setting(ArgSettings::Required))
.arg(Arg::with_name("toolchain")
.long("toolchain")
.setting(ArgSettings::TakesValue)))
.subcommand(SubCommand::with_name("uninstall")
.subcommand(App::new("uninstall")
.setting(AppSettings::Hidden) // synonym for 'remove'
.arg(Arg::with_name("target")
.setting(ArgSettings::Required))
.arg(Arg::with_name("toolchain")
.long("toolchain")
.setting(ArgSettings::TakesValue))))
.subcommand(SubCommand::with_name("component")
.subcommand(App::new("component")
.about("Modify a toolchain's installed components")
.setting(AppSettings::VersionlessSubcommands)
.setting(AppSettings::DeriveDisplayOrder)
// .setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(SubCommand::with_name("list")
.subcommand(App::new("list")
.about("List installed and available components")
.arg(Arg::with_name("toolchain")
.long("toolchain")
.setting(ArgSettings::TakesValue)))
.subcommand(SubCommand::with_name("add")
.subcommand(App::new("add")
.about("Add a component to a Rust toolchain")
.arg(Arg::with_name("component").setting(ArgSettings::Required))
.arg(Arg::with_name("toolchain")
Expand All @@ -138,7 +138,7 @@ pub fn build_cli() -> App<'static, 'static> {
.arg(Arg::with_name("target")
.long("target")
.setting(ArgSettings::TakesValue)))
.subcommand(SubCommand::with_name("remove")
.subcommand(App::new("remove")
.about("Remove a component from a Rust toolchain")
.arg(Arg::with_name("component").setting(ArgSettings::Required))
.arg(Arg::with_name("toolchain")
Expand All @@ -147,17 +147,17 @@ pub fn build_cli() -> App<'static, 'static> {
.arg(Arg::with_name("target")
.long("target")
.setting(ArgSettings::TakesValue))))
.subcommand(SubCommand::with_name("override")
.subcommand(App::new("override")
.about("Modify directory toolchain overrides")
.after_help(OVERRIDE_HELP)
.setting(AppSettings::VersionlessSubcommands)
.setting(AppSettings::DeriveDisplayOrder)
// .setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(SubCommand::with_name("list").about("List directory toolchain overrides"))
.subcommand(SubCommand::with_name("set")
.subcommand(App::new("list").about("List directory toolchain overrides"))
.subcommand(App::new("set")
.about("Set the override toolchain for a directory")
.arg(Arg::with_name("toolchain").setting(ArgSettings::Required)))
.subcommand(SubCommand::with_name("unset")
.subcommand(App::new("unset")
.about("Remove the override toolchain for a directory")
.after_help(OVERRIDE_UNSET_HELP)
.arg(Arg::with_name("path")
Expand All @@ -167,11 +167,11 @@ pub fn build_cli() -> App<'static, 'static> {
.arg(Arg::with_name("nonexistent")
.long("nonexistent")
.help("Remove override toolchain for all nonexistent directories")))
.subcommand(SubCommand::with_name("add")
.subcommand(App::new("add")
.setting(AppSettings::Hidden) // synonym for 'set'
.arg(Arg::with_name("toolchain")
.setting(ArgSettings::Required)))
.subcommand(SubCommand::with_name("remove")
.subcommand(App::new("remove")
.setting(AppSettings::Hidden) // synonym for 'unset'
.about("Remove the override toolchain for a directory")
.arg(Arg::with_name("path")
Expand All @@ -180,17 +180,17 @@ pub fn build_cli() -> App<'static, 'static> {
.arg(Arg::with_name("nonexistent")
.long("nonexistent")
.help("Remove override toolchain for all nonexistent directories"))))
.subcommand(SubCommand::with_name("run")
.subcommand(App::new("run")
.about("Run a command with an environment configured for a given toolchain")
.after_help(RUN_HELP)
.setting(AppSettings::TrailingVarArg)
.arg(Arg::with_name("toolchain").setting(ArgSettings::Required))
.arg(Arg::with_name("command")
.settings(&[ArgSettings::Required, ArgSettings::MultipleValues, ArgSettings::MultipleOccurrences])))
.subcommand(SubCommand::with_name("which")
.subcommand(App::new("which")
.about("Display which binary will be run for a given command")
.arg(Arg::with_name("command").setting(ArgSettings::Required)))
.subcommand(SubCommand::with_name("doc")
.subcommand(App::new("doc")
.about("Open the documentation for the current toolchain")
.after_help(DOC_HELP)
.arg(Arg::with_name("book")
Expand All @@ -200,37 +200,37 @@ pub fn build_cli() -> App<'static, 'static> {
.long("std")
.help("Standard library API documentation"))
.group(ArgGroup::with_name("page").args(&["book", "std"])))
.subcommand(SubCommand::with_name("man")
.subcommand(App::new("man")
.about("View the man page for a given command")
.arg(Arg::with_name("command").setting(ArgSettings::Required))
.arg(Arg::with_name("toolchain")
.long("toolchain")
.setting(ArgSettings::TakesValue)))
.subcommand(SubCommand::with_name("self")
.subcommand(App::new("self")
.about("Modify the rustup installation")
.setting(AppSettings::VersionlessSubcommands)
.setting(AppSettings::DeriveDisplayOrder)
.subcommand(SubCommand::with_name("update")
.subcommand(App::new("update")
.about("Download and install updates to rustup"))
.subcommand(SubCommand::with_name("uninstall")
.subcommand(App::new("uninstall")
.about("Uninstall rustup.")
.arg(Arg::with_name("no-prompt").short('y')))
.subcommand(SubCommand::with_name("upgrade-data")
.subcommand(App::new("upgrade-data")
.about("Upgrade the internal data format.")))
.subcommand(SubCommand::with_name("telemetry")
.subcommand(App::new("telemetry")
.about("rustup telemetry commands")
.setting(AppSettings::Hidden)
.setting(AppSettings::VersionlessSubcommands)
.setting(AppSettings::DeriveDisplayOrder)
.subcommand(SubCommand::with_name("enable").about("Enable rustup telemetry"))
.subcommand(SubCommand::with_name("disable").about("Disable rustup telemetry"))
.subcommand(SubCommand::with_name("analyze").about("Analyze stored telemetry")))
.subcommand(SubCommand::with_name("set")
.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(App::new("set")
.about("Alter rustup settings")
.subcommand(SubCommand::with_name("default-host")
.subcommand(App::new("default-host")
.about("The triple used to identify toolchains when not specified")
.arg(Arg::with_name("host_triple").setting(ArgSettings::Required))))
.subcommand(SubCommand::with_name("completions")
.subcommand(App::new("completions")
.about("Generate completion scripts for your shell")
.after_help(COMPLETIONS_HELP)
.setting(AppSettings::ArgRequiredElseHelp)
Expand Down
19 changes: 9 additions & 10 deletions clap-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod test {

use regex::Regex;

use clap::{App, Arg, SubCommand, ArgGroup};
use clap::{App, Arg, ArgGroup};

fn compare<S, S2>(l: S, r: S2) -> bool
where S: AsRef<str>,
Expand All @@ -31,7 +31,7 @@ mod test {

pub fn compare_output(l: App, args: &str, right: &str, stderr: bool) -> bool {
let mut buf = Cursor::new(Vec::with_capacity(50));
let res = l.get_matches_from_safe(args.split(' ').collect::<Vec<_>>());
let res = l.try_get_matches_from(args.split(' ').collect::<Vec<_>>());
let err = res.unwrap_err();
err.write_to(&mut buf).unwrap();
let content = buf.into_inner();
Expand All @@ -43,7 +43,7 @@ mod test {

pub fn compare_output2(l: App, args: &str, right1: &str, right2: &str, stderr: bool) -> bool {
let mut buf = Cursor::new(Vec::with_capacity(50));
let res = l.get_matches_from_safe(args.split(' ').collect::<Vec<_>>());
let res = l.try_get_matches_from(args.split(' ').collect::<Vec<_>>());
let err = res.unwrap_err();
err.write_to(&mut buf).unwrap();
let content = buf.into_inner();
Expand All @@ -55,15 +55,14 @@ mod test {
// Legacy tests from the pyhton script days

pub fn complex_app() -> App<'static, 'static> {
let args = "-o --option=[opt]... 'tests options'
[positional] 'tests positionals'";
let opt3_vals = ["fast", "slow"];
let pos3_vals = ["vi", "emacs"];
App::new("clap-test")
.version("v1.4.8")
.about("tests clap library")
.author("Kevin K. <kbknapp@gmail.com>")
.args_from_usage(args)
.arg("-o --option=[opt]... 'tests options'")
.arg("[positional] 'tests positionals'")
.arg(Arg::from("-f --flag... 'tests flags'")
.global(true))
.args(&[
Expand All @@ -77,12 +76,12 @@ mod test {
Arg::from("--minvals2 [minvals]... 'Tests 2 min vals'").min_values(2),
Arg::from("--maxvals3 [maxvals]... 'Tests 3 max vals'").max_values(3)
])
.subcommand(SubCommand::with_name("subcmd")
.subcommand(App::new("subcmd")
.about("tests subcommands")
.version("0.1")
.author("Kevin K. <kbknapp@gmail.com>")
.arg_from_usage("-o --option [scoption]... 'tests options'")
.arg_from_usage("-s --subcmdarg [subcmdarg] 'tests other args'")
.arg_from_usage("[scpositional] 'tests positionals'"))
.arg("-o --option [scoption]... 'tests options'")
.arg("-s --subcmdarg [subcmdarg] 'tests other args'")
.arg("[scpositional] 'tests positionals'"))
}
}
Loading

0 comments on commit 0333380

Please sign in to comment.