Skip to content

Commit 194026d

Browse files
authored
Merge pull request #1633 from lazorgator/1632-rustup-print-default
Print default toolchain on `rustup default` without arguments
2 parents 2ba84ae + ec7b52f commit 194026d

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

src/rustup-cli/rustup_mode.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub fn cli() -> App<'static, 'static> {
189189
.arg(
190190
Arg::with_name("toolchain")
191191
.help(TOOLCHAIN_ARG_HELP)
192-
.required(true),
192+
.required(false),
193193
),
194194
)
195195
.subcommand(
@@ -572,23 +572,37 @@ fn default_bare_triple_check(cfg: &Cfg, name: &str) -> Result<()> {
572572
}
573573

574574
fn default_(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
575-
let ref toolchain = m.value_of("toolchain").expect("");
576-
default_bare_triple_check(cfg, toolchain)?;
577-
let ref toolchain = cfg.get_toolchain(toolchain, false)?;
578-
579-
let status = if !toolchain.is_custom() {
580-
Some(toolchain.install_from_dist_if_not_installed()?)
581-
} else if !toolchain.exists() {
582-
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
583-
} else {
584-
None
585-
};
575+
if m.is_present("toolchain") {
576+
let ref toolchain = m.value_of("toolchain").expect("");
577+
default_bare_triple_check(cfg, toolchain)?;
578+
let ref toolchain = cfg.get_toolchain(toolchain, false)?;
579+
580+
let status = if !toolchain.is_custom() {
581+
Some(toolchain.install_from_dist_if_not_installed()?)
582+
} else if !toolchain.exists() {
583+
return Err(ErrorKind::ToolchainNotInstalled(toolchain.name().to_string()).into());
584+
} else {
585+
None
586+
};
586587

587-
toolchain.make_default()?;
588+
toolchain.make_default()?;
588589

589-
if let Some(status) = status {
590-
println!();
591-
common::show_channel_update(cfg, toolchain.name(), Ok(status))?;
590+
if let Some(status) = status {
591+
println!();
592+
common::show_channel_update(cfg, toolchain.name(), Ok(status))?;
593+
}
594+
} else {
595+
let installed_toolchains = cfg.list_toolchains()?;
596+
if installed_toolchains.len() > 0 {
597+
let default_toolchain = cfg.get_default()?;
598+
if default_toolchain != "" {
599+
let mut t = term2::stdout();
600+
let _ = t.attr(term2::Attr::Bold);
601+
let _ = write!(t, "Default toolchain: ");
602+
let _ = t.reset();
603+
println!("{}", default_toolchain);
604+
}
605+
}
592606
}
593607

594608
Ok(())

0 commit comments

Comments
 (0)