Skip to content

Commit

Permalink
feat(rustup-mode): install the active toolchain by default on `rustup…
Browse files Browse the repository at this point in the history
… toolchain install`
  • Loading branch information
rami3l committed Aug 6, 2024
1 parent 00ceced commit f9bff67
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn plus_toolchain_value_parser(s: &str) -> clap::error::Result<ResolvableToolcha
#[derive(Debug, Subcommand)]
#[command(name = "rustup", bin_name = "rustup[EXE]")]
enum RustupSubcmd {
/// Update Rust toolchains
/// Install or update the given toolchains, or by default the active toolchain
#[command(hide = true, after_help = INSTALL_HELP)]
Install {
#[command(flatten)]
Expand Down Expand Up @@ -302,7 +302,7 @@ enum ToolchainSubcmd {
quiet: bool,
},

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

match subcmd {
RustupSubcmd::DumpTestament => common::dump_testament(process),
RustupSubcmd::Install { opts } => update(cfg, opts, false).await,
RustupSubcmd::Install { opts } => update(cfg, opts, true).await,
RustupSubcmd::Uninstall { opts } => toolchain_remove(cfg, opts),
RustupSubcmd::Show { verbose, subcmd } => handle_epipe(match subcmd {
None => show(cfg, verbose),
Expand Down Expand Up @@ -615,7 +614,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
.await
}
RustupSubcmd::Toolchain { subcmd } => match subcmd {
ToolchainSubcmd::Install { opts } => update(cfg, opts, false).await,
ToolchainSubcmd::Install { opts } => update(cfg, opts, true).await,
ToolchainSubcmd::List { verbose, quiet } => {
handle_epipe(common::list_toolchains(cfg, verbose, quiet))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Usage: rustup[EXE] toolchain <COMMAND>
Commands:
list List installed toolchains
install Install or update a given toolchain
install Install or update the given toolchains, or by default the active toolchain
uninstall Uninstall the given toolchains
link Create a custom toolchain by symlinking to a directory
help Print this message or the help of the given subcommand(s)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
bin.name = "rustup"
args = ["toolchain", "install", "--help"]
stdout = """
...
Install or update a given toolchain
Install or update the given toolchains, or by default the active toolchain
Usage: rustup[EXE] toolchain install [OPTIONS] <TOOLCHAIN>...
Usage: rustup[EXE] toolchain install [OPTIONS] [TOOLCHAIN]...
Arguments:
<TOOLCHAIN>... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
[TOOLCHAIN]... Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see
`rustup help toolchain`
Options:
Expand Down
34 changes: 34 additions & 0 deletions tests/suite/cli_rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,40 @@ async fn toolchain_install_is_like_update_except_that_bare_install_is_an_error()
.await;
}

#[tokio::test]
async fn toolchain_install_without_args_installs_active() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;

let cwd = cx.config.current_dir();
let toolchain_file = cwd.join("rust-toolchain.toml");
raw::write_file(
&toolchain_file,
r#"
[toolchain]
profile = "minimal"
channel = "nightly"
"#,
)
.unwrap();

cx.config
.expect_stderr_ok(
&["rustup", "toolchain", "install"],
&format!(
"\
info: syncing channel updates for 'nightly-{0}'
info: latest update on 2015-01-02, rust version 1.3.0 (hash-nightly-2)
info: downloading component 'rustc'
info: installing component 'rustc'
info: the active toolchain `nightly-{0}` has been installed
info: it's active because: overridden by '{1}'",
this_host_triple(),
toolchain_file.display(),
),
)
.await;
}

#[tokio::test]
async fn toolchain_update_is_like_update() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
Expand Down

0 comments on commit f9bff67

Please sign in to comment.