Skip to content

Commit 96bc015

Browse files
authored
Merge pull request #2239 from jplatte/delimited_option_args
cli: Allow specifying multiple component or target values in one argument
2 parents ddeda7c + 364c1ec commit 96bc015

File tree

4 files changed

+100
-6
lines changed

4 files changed

+100
-6
lines changed

src/cli/rustup_mode.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,17 @@ pub fn cli() -> App<'static, 'static> {
318318
.long("component")
319319
.short("c")
320320
.takes_value(true)
321-
.multiple(true),
321+
.multiple(true)
322+
.use_delimiter(true),
322323
)
323324
.arg(
324325
Arg::with_name("targets")
325326
.help("Add specific targets on installation")
326327
.long("target")
327328
.short("t")
328329
.takes_value(true)
329-
.multiple(true),
330+
.multiple(true)
331+
.use_delimiter(true),
330332
)
331333
.arg(
332334
Arg::with_name("force")

src/cli/setup_mode.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,17 @@ pub fn main() -> Result<()> {
6767
.long("component")
6868
.short("c")
6969
.takes_value(true)
70-
.multiple(true),
70+
.multiple(true)
71+
.use_delimiter(true),
7172
)
7273
.arg(
7374
Arg::with_name("targets")
7475
.help("Target name to also install")
7576
.long("target")
7677
.short("target")
7778
.takes_value(true)
78-
.multiple(true),
79+
.multiple(true)
80+
.use_delimiter(true),
7981
)
8082
.arg(
8183
Arg::with_name("no-modify-path")

tests/cli-inst-interactive.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
pub mod mock;
44

55
use crate::mock::clitools::{
6-
self, expect_stderr_ok, expect_stdout_ok, set_current_dist_date, Config, SanitizedOutput,
7-
Scenario,
6+
self, expect_ok, expect_stderr_ok, expect_stdout_ok, set_current_dist_date, this_host_triple,
7+
Config, SanitizedOutput, Scenario,
88
};
99
use crate::mock::{get_path, restore_path};
1010
use lazy_static::lazy_static;
@@ -248,6 +248,31 @@ fn user_says_nope_after_advanced_install() {
248248
});
249249
}
250250

251+
#[test]
252+
fn install_with_components() {
253+
fn go(comp_args: &[&str]) {
254+
let mut args = vec!["rustup-init", "-y"];
255+
args.extend_from_slice(comp_args);
256+
257+
setup(&|config| {
258+
expect_ok(config, &args);
259+
expect_stdout_ok(
260+
config,
261+
&["rustup", "component", "list"],
262+
"rust-src (installed)",
263+
);
264+
expect_stdout_ok(
265+
config,
266+
&["rustup", "component", "list"],
267+
&format!("rust-analysis-{} (installed)", this_host_triple()),
268+
);
269+
})
270+
}
271+
272+
go(&["-c", "rust-src", "-c", "rust-analysis"]);
273+
go(&["-c", "rust-src,rust-analysis"]);
274+
}
275+
251276
#[test]
252277
fn install_forces_and_skips_rls() {
253278
setup_(true, &|config| {

tests/cli-v2.rs

+65
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,71 @@ fn target_list_ignores_unavailable_targets() {
12351235
})
12361236
}
12371237

1238+
#[test]
1239+
fn install_with_components() {
1240+
fn go(comp_args: &[&str]) {
1241+
let mut args = vec![
1242+
"rustup",
1243+
"toolchain",
1244+
"install",
1245+
"nightly",
1246+
"--no-self-update",
1247+
];
1248+
args.extend_from_slice(comp_args);
1249+
1250+
setup(&|config| {
1251+
expect_ok(config, &args);
1252+
expect_stdout_ok(
1253+
config,
1254+
&["rustup", "component", "list"],
1255+
"rust-src (installed)",
1256+
);
1257+
expect_stdout_ok(
1258+
config,
1259+
&["rustup", "component", "list"],
1260+
&format!("rust-analysis-{} (installed)", this_host_triple()),
1261+
);
1262+
})
1263+
}
1264+
1265+
go(&["-c", "rust-src", "-c", "rust-analysis"]);
1266+
go(&["-c", "rust-src,rust-analysis"]);
1267+
}
1268+
1269+
#[test]
1270+
fn install_with_targets() {
1271+
fn go(comp_args: &[&str]) {
1272+
let mut args = vec![
1273+
"rustup",
1274+
"toolchain",
1275+
"install",
1276+
"nightly",
1277+
"--no-self-update",
1278+
];
1279+
args.extend_from_slice(comp_args);
1280+
1281+
setup(&|config| {
1282+
expect_ok(config, &args);
1283+
expect_stdout_ok(
1284+
config,
1285+
&["rustup", "target", "list"],
1286+
&format!("{} (installed)", clitools::CROSS_ARCH1),
1287+
);
1288+
expect_stdout_ok(
1289+
config,
1290+
&["rustup", "target", "list"],
1291+
&format!("{} (installed)", clitools::CROSS_ARCH2),
1292+
);
1293+
})
1294+
}
1295+
1296+
go(&["-t", clitools::CROSS_ARCH1, "-t", clitools::CROSS_ARCH2]);
1297+
go(&[
1298+
"-t",
1299+
&format!("{},{}", clitools::CROSS_ARCH1, clitools::CROSS_ARCH2),
1300+
]);
1301+
}
1302+
12381303
#[test]
12391304
fn install_with_component_and_target() {
12401305
setup(&|config| {

0 commit comments

Comments
 (0)