Skip to content

Commit

Permalink
Auto merge of #986 - durka:add-rm-multiple, r=brson
Browse files Browse the repository at this point in the history
add/remove multiple toolchains

Teaches the `toolchain` subcommand to accept multiple arguments for toolchains to add or remove.

Depends on #968.
Fixes #976.
  • Loading branch information
bors committed Mar 18, 2017
2 parents 7d1de03 a807244 commit 02d1b87
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 23 deletions.
54 changes: 31 additions & 23 deletions src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 158,13 @@ pub fn cli() -> App<'static, 'static> {
.subcommand(SubCommand::with_name("install")
.about("Install or update a given toolchain")
.arg(Arg::with_name("toolchain")
.required(true)))
.required(true)
.multiple(true)))
.subcommand(SubCommand::with_name("uninstall")
.about("Uninstall a toolchain")
.arg(Arg::with_name("toolchain")
.required(true)))
.required(true)
.multiple(true)))
.subcommand(SubCommand::with_name("link")
.about("Create a custom toolchain by symlinking to a directory")
.arg(Arg::with_name("toolchain")
Expand All @@ -172,15 174,18 @@ pub fn cli() -> App<'static, 'static> {
.subcommand(SubCommand::with_name("update")
.setting(AppSettings::Hidden) // synonym for 'install'
.arg(Arg::with_name("toolchain")
.required(true)))
.required(true)
.multiple(true)))
.subcommand(SubCommand::with_name("add")
.setting(AppSettings::Hidden) // synonym for 'install'
.arg(Arg::with_name("toolchain")
.required(true)))
.required(true)
.multiple(true)))
.subcommand(SubCommand::with_name("remove")
.setting(AppSettings::Hidden) // synonym for 'uninstall'
.arg(Arg::with_name("toolchain")
.required(true))))
.required(true)
.multiple(true))))
.subcommand(SubCommand::with_name("target")
.about("Modify a toolchain's supported targets")
.setting(AppSettings::VersionlessSubcommands)
Expand Down Expand Up @@ -458,21 463,23 @@ fn default_(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
}

fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
if let Some(name) = m.value_of("toolchain") {
try!(update_bare_triple_check(cfg, name));
let toolchain = try!(cfg.get_toolchain(name, false));

let status = if !toolchain.is_custom() {
Some(try!(toolchain.install_from_dist()))
} else if !toolchain.exists() {
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
} else {
None
};
if let Some(names) = m.values_of("toolchain") {
for name in names {
try!(update_bare_triple_check(cfg, name));
let toolchain = try!(cfg.get_toolchain(name, false));

let status = if !toolchain.is_custom() {
Some(try!(toolchain.install_from_dist()))
} else if !toolchain.exists() {
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
} else {
None
};

if let Some(status) = status {
println!("");
try!(common::show_channel_update(cfg, toolchain.name(), Ok(status)));
if let Some(status) = status {
println!("");
try!(common::show_channel_update(cfg, toolchain.name(), Ok(status)));
}
}
} else {
try!(common::update_all_channels(cfg, !m.is_present("no-self-update") && !self_update::NEVER_SELF_UPDATE));
Expand Down Expand Up @@ -684,10 691,11 @@ fn toolchain_link(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
}

fn toolchain_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
let ref toolchain = m.value_of("toolchain").expect("");
let toolchain = try!(cfg.get_toolchain(toolchain, false));

Ok(try!(toolchain.remove()))
for toolchain in m.values_of("toolchain").expect("") {
let toolchain = try!(cfg.get_toolchain(toolchain, false));
try!(toolchain.remove());
}
Ok(())
}

fn override_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
Expand Down
26 changes: 26 additions & 0 deletions tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 138,32 @@ fn remove_toolchain() {
});
}

#[test]
fn add_remove_multiple_toolchains() {
fn go(add: &str, rm: &str) {
setup(&|config| {
let tch1 = "beta";
let tch2 = "nightly";

expect_ok(config, &["rustup", "toolchain", add, tch1, tch2]);
expect_ok(config, &["rustup", "toolchain", "list"]);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], tch1);
expect_stdout_ok(config, &["rustup", "toolchain", "list"], tch2);

expect_ok(config, &["rustup", "toolchain", rm, tch1, tch2]);
expect_ok(config, &["rustup", "toolchain", "list"]);
expect_not_stdout_ok(config, &["rustup", "toolchain", "list"], tch1);
expect_not_stdout_ok(config, &["rustup", "toolchain", "list"], tch2);
});
}

for add in &["add", "update", "install"] {
for rm in &["remove", "uninstall"] {
go(add, rm);
}
}
}

#[test]
fn remove_default_toolchain_err_handling() {
setup(&|config| {
Expand Down

0 comments on commit 02d1b87

Please sign in to comment.