Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add/remove multiple toolchains #986

Merged
merged 2 commits into from
Mar 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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