Skip to content

Commit c8da02e

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

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
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

+32
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,38 @@ async fn toolchain_install_is_like_update_except_that_bare_install_is_an_error()
14601460
.await;
14611461
}
14621462

1463+
#[tokio::test]
1464+
async fn toolchain_install_without_args_installs_active() {
1465+
let cx = CliTestContext::new(Scenario::SimpleV2).await;
1466+
1467+
let cwd = cx.config.current_dir();
1468+
let toolchain_file = cwd.join("rust-toolchain");
1469+
raw::write_file(
1470+
&toolchain_file,
1471+
r#"
1472+
[toolchain]
1473+
profile = "minimal"
1474+
channel = "nightly"
1475+
"#,
1476+
)
1477+
.unwrap();
1478+
1479+
cx.config
1480+
.expect_stderr_ok(
1481+
&["rustup", "toolchain", "install"],
1482+
for_host!(
1483+
"\
1484+
info: syncing channel updates for 'nightly-{0}'
1485+
info: latest update on 2015-01-02, rust version 1.3.0 (hash-nightly-2)
1486+
info: downloading component 'rustc'
1487+
info: installing component 'rustc'
1488+
info: the active toolchain `nightly-{0}` has been installed
1489+
info: it's active because: overridden by '"
1490+
),
1491+
)
1492+
.await;
1493+
}
1494+
14631495
#[tokio::test]
14641496
async fn toolchain_update_is_like_update() {
14651497
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;

0 commit comments

Comments
 (0)