Skip to content

Commit 261b851

Browse files
committed
feat(rustup-mode): install the active toolchain by default on rustup toolchain install
1 parent 00ceced commit 261b851

File tree

4 files changed

+49
-25
lines changed

4 files changed

+49
-25
lines changed

src/cli/rustup_mode.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn plus_toolchain_value_parser(s: &str) -> clap::error::Result<ResolvableToolcha
100100
#[derive(Debug, Subcommand)]
101101
#[command(name = "rustup", bin_name = "rustup[EXE]")]
102102
enum RustupSubcmd {
103-
/// Update Rust toolchains
103+
/// Install or update the given toolchains, or by default the active toolchain
104104
#[command(hide = true, after_help = INSTALL_HELP)]
105105
Install {
106106
#[command(flatten)]
@@ -302,7 +302,7 @@ enum ToolchainSubcmd {
302302
quiet: bool,
303303
},
304304

305-
/// Install or update a given toolchain
305+
/// Install or update the given toolchains, or by default the active toolchain
306306
#[command(aliases = ["update", "add"] )]
307307
Install {
308308
#[command(flatten)]
@@ -330,7 +330,6 @@ enum ToolchainSubcmd {
330330
#[derive(Debug, Default, Args)]
331331
struct UpdateOpts {
332332
#[arg(
333-
required = true,
334333
help = OFFICIAL_TOOLCHAIN_ARG_HELP,
335334
num_args = 1..,
336335
)]
@@ -584,7 +583,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
584583

585584
match subcmd {
586585
RustupSubcmd::DumpTestament => common::dump_testament(process),
587-
RustupSubcmd::Install { opts } => update(cfg, opts, false).await,
586+
RustupSubcmd::Install { opts } => update(cfg, opts, true).await,
588587
RustupSubcmd::Uninstall { opts } => toolchain_remove(cfg, opts),
589588
RustupSubcmd::Show { verbose, subcmd } => handle_epipe(match subcmd {
590589
None => show(cfg, verbose),
@@ -615,7 +614,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
615614
.await
616615
}
617616
RustupSubcmd::Toolchain { subcmd } => match subcmd {
618-
ToolchainSubcmd::Install { opts } => update(cfg, opts, false).await,
617+
ToolchainSubcmd::Install { opts } => update(cfg, opts, true).await,
619618
ToolchainSubcmd::List { verbose, quiet } => {
620619
handle_epipe(common::list_toolchains(cfg, verbose, quiet))
621620
}

tests/suite/cli-ui/rustup/rustup_toolchain_cmd_help_flag_stdout.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Usage: rustup[EXE] toolchain <COMMAND>
88
99
Commands:
1010
list List installed toolchains
11-
install Install or update a given toolchain
11+
install Install or update the given toolchains, or by default the active toolchain
1212
uninstall Uninstall the given toolchains
1313
link Create a custom toolchain by symlinking to a directory
1414
help Print this message or the help of the given subcommand(s)

tests/suite/cli-ui/rustup/rustup_toolchain_cmd_install_cmd_help_flag_stdout.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
bin.name = "rustup"
22
args = ["toolchain", "install", "--help"]
33
stdout = """
4-
...
5-
Install or update a given toolchain
4+
Install or update the given toolchains, or by default the active toolchain
65
7-
Usage: rustup[EXE] toolchain install [OPTIONS] <TOOLCHAIN>...
6+
Usage: rustup[EXE] toolchain install [OPTIONS] [TOOLCHAIN]...
87
98
Arguments:
10-
<TOOLCHAIN>... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
9+
[TOOLCHAIN]... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
1110
`rustup help toolchain`
1211
1312
Options:

tests/suite/cli_rustup.rs

+41-15
Original file line numberDiff line numberDiff line change
@@ -1450,12 +1450,49 @@ async fn toolchain_install_is_like_update_quiet() {
14501450
}
14511451

14521452
#[tokio::test]
1453-
async fn toolchain_install_is_like_update_except_that_bare_install_is_an_error() {
1454-
let cx = CliTestContext::new(Scenario::None).await;
1453+
async fn toolchain_install_without_args_installs_active() {
1454+
let cx = CliTestContext::new(Scenario::SimpleV2).await;
1455+
1456+
let cwd = cx.config.current_dir();
1457+
let toolchain_file = cwd.join("rust-toolchain.toml");
1458+
raw::write_file(
1459+
&toolchain_file,
1460+
r#"
1461+
[toolchain]
1462+
profile = "minimal"
1463+
channel = "nightly"
1464+
"#,
1465+
)
1466+
.unwrap();
1467+
14551468
cx.config
1456-
.expect_err(
1469+
.expect_stderr_ok(
14571470
&["rustup", "toolchain", "install"],
1458-
"arguments were not provided",
1471+
&format!(
1472+
"\
1473+
info: syncing channel updates for 'nightly-{0}'
1474+
info: latest update on 2015-01-02, rust version 1.3.0 (hash-nightly-2)
1475+
info: downloading component 'rustc'
1476+
info: installing component 'rustc'
1477+
info: the active toolchain `nightly-{0}` has been installed
1478+
info: it's active because: overridden by '{1}'",
1479+
this_host_triple(),
1480+
toolchain_file.display(),
1481+
),
1482+
)
1483+
.await;
1484+
1485+
cx.config
1486+
.expect_stderr_ok(
1487+
&["rustup", "toolchain", "install"],
1488+
&format!(
1489+
"\
1490+
info: using existing install for 'nightly-{0}'
1491+
info: the active toolchain `nightly-{0}` has been installed
1492+
info: it's active because: overridden by '{1}'",
1493+
this_host_triple(),
1494+
toolchain_file.display(),
1495+
),
14591496
)
14601497
.await;
14611498
}
@@ -1494,17 +1531,6 @@ async fn toolchain_uninstall_is_like_uninstall() {
14941531
.await;
14951532
}
14961533

1497-
#[tokio::test]
1498-
async fn toolchain_update_is_like_update_except_that_bare_install_is_an_error() {
1499-
let cx = CliTestContext::new(Scenario::None).await;
1500-
cx.config
1501-
.expect_err(
1502-
&["rustup", "toolchain", "update"],
1503-
"arguments were not provided",
1504-
)
1505-
.await;
1506-
}
1507-
15081534
#[tokio::test]
15091535
async fn proxy_toolchain_shorthand() {
15101536
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;

0 commit comments

Comments
 (0)