Skip to content

Commit 02d1b87

Browse files
committed
Auto merge of #986 - durka:add-rm-multiple, r=brson
add/remove multiple toolchains Teaches the `toolchain` subcommand to accept multiple arguments for toolchains to add or remove. Depends on #968. Fixes #976.
2 parents 7d1de03 + a807244 commit 02d1b87

File tree

2 files changed

+57
-23
lines changed

2 files changed

+57
-23
lines changed

src/rustup-cli/rustup_mode.rs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ pub fn cli() -> App<'static, 'static> {
158158
.subcommand(SubCommand::with_name("install")
159159
.about("Install or update a given toolchain")
160160
.arg(Arg::with_name("toolchain")
161-
.required(true)))
161+
.required(true)
162+
.multiple(true)))
162163
.subcommand(SubCommand::with_name("uninstall")
163164
.about("Uninstall a toolchain")
164165
.arg(Arg::with_name("toolchain")
165-
.required(true)))
166+
.required(true)
167+
.multiple(true)))
166168
.subcommand(SubCommand::with_name("link")
167169
.about("Create a custom toolchain by symlinking to a directory")
168170
.arg(Arg::with_name("toolchain")
@@ -172,15 +174,18 @@ pub fn cli() -> App<'static, 'static> {
172174
.subcommand(SubCommand::with_name("update")
173175
.setting(AppSettings::Hidden) // synonym for 'install'
174176
.arg(Arg::with_name("toolchain")
175-
.required(true)))
177+
.required(true)
178+
.multiple(true)))
176179
.subcommand(SubCommand::with_name("add")
177180
.setting(AppSettings::Hidden) // synonym for 'install'
178181
.arg(Arg::with_name("toolchain")
179-
.required(true)))
182+
.required(true)
183+
.multiple(true)))
180184
.subcommand(SubCommand::with_name("remove")
181185
.setting(AppSettings::Hidden) // synonym for 'uninstall'
182186
.arg(Arg::with_name("toolchain")
183-
.required(true))))
187+
.required(true)
188+
.multiple(true))))
184189
.subcommand(SubCommand::with_name("target")
185190
.about("Modify a toolchain's supported targets")
186191
.setting(AppSettings::VersionlessSubcommands)
@@ -458,21 +463,23 @@ fn default_(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
458463
}
459464

460465
fn update(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
461-
if let Some(name) = m.value_of("toolchain") {
462-
try!(update_bare_triple_check(cfg, name));
463-
let toolchain = try!(cfg.get_toolchain(name, false));
464-
465-
let status = if !toolchain.is_custom() {
466-
Some(try!(toolchain.install_from_dist()))
467-
} else if !toolchain.exists() {
468-
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
469-
} else {
470-
None
471-
};
466+
if let Some(names) = m.values_of("toolchain") {
467+
for name in names {
468+
try!(update_bare_triple_check(cfg, name));
469+
let toolchain = try!(cfg.get_toolchain(name, false));
470+
471+
let status = if !toolchain.is_custom() {
472+
Some(try!(toolchain.install_from_dist()))
473+
} else if !toolchain.exists() {
474+
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
475+
} else {
476+
None
477+
};
472478

473-
if let Some(status) = status {
474-
println!("");
475-
try!(common::show_channel_update(cfg, toolchain.name(), Ok(status)));
479+
if let Some(status) = status {
480+
println!("");
481+
try!(common::show_channel_update(cfg, toolchain.name(), Ok(status)));
482+
}
476483
}
477484
} else {
478485
try!(common::update_all_channels(cfg, !m.is_present("no-self-update") && !self_update::NEVER_SELF_UPDATE));
@@ -684,10 +691,11 @@ fn toolchain_link(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
684691
}
685692

686693
fn toolchain_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
687-
let ref toolchain = m.value_of("toolchain").expect("");
688-
let toolchain = try!(cfg.get_toolchain(toolchain, false));
689-
690-
Ok(try!(toolchain.remove()))
694+
for toolchain in m.values_of("toolchain").expect("") {
695+
let toolchain = try!(cfg.get_toolchain(toolchain, false));
696+
try!(toolchain.remove());
697+
}
698+
Ok(())
691699
}
692700

693701
fn override_add(cfg: &Cfg, m: &ArgMatches) -> Result<()> {

tests/cli-v2.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,32 @@ fn remove_toolchain() {
138138
});
139139
}
140140

141+
#[test]
142+
fn add_remove_multiple_toolchains() {
143+
fn go(add: &str, rm: &str) {
144+
setup(&|config| {
145+
let tch1 = "beta";
146+
let tch2 = "nightly";
147+
148+
expect_ok(config, &["rustup", "toolchain", add, tch1, tch2]);
149+
expect_ok(config, &["rustup", "toolchain", "list"]);
150+
expect_stdout_ok(config, &["rustup", "toolchain", "list"], tch1);
151+
expect_stdout_ok(config, &["rustup", "toolchain", "list"], tch2);
152+
153+
expect_ok(config, &["rustup", "toolchain", rm, tch1, tch2]);
154+
expect_ok(config, &["rustup", "toolchain", "list"]);
155+
expect_not_stdout_ok(config, &["rustup", "toolchain", "list"], tch1);
156+
expect_not_stdout_ok(config, &["rustup", "toolchain", "list"], tch2);
157+
});
158+
}
159+
160+
for add in &["add", "update", "install"] {
161+
for rm in &["remove", "uninstall"] {
162+
go(add, rm);
163+
}
164+
}
165+
}
166+
141167
#[test]
142168
fn remove_default_toolchain_err_handling() {
143169
setup(&|config| {

0 commit comments

Comments
 (0)