Skip to content

Commit

Permalink
show active-toolchain with rustc info
Browse files Browse the repository at this point in the history
  • Loading branch information
Rustin170506 committed Apr 5, 2021
1 parent 84974df commit ee9645f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub fn main() -> Result<utils::ExitCode> {
Ok(match matches.subcommand() {
("dump-testament", _) => common::dump_testament()?,
("show", Some(c)) => match c.subcommand() {
("active-toolchain", Some(_)) => handle_epipe(show_active_toolchain(cfg))?,
("active-toolchain", Some(m)) => handle_epipe(show_active_toolchain(cfg, m))?,
("home", Some(_)) => handle_epipe(show_rustup_home(cfg))?,
("profile", Some(_)) => handle_epipe(show_profile(cfg))?,
("keys", Some(_)) => handle_epipe(show_keys(cfg))?,
Expand Down Expand Up @@ -243,7 +243,14 @@ pub fn cli() -> App<'static, 'static> {
.subcommand(
SubCommand::with_name("active-toolchain")
.about("Show the active toolchain")
.after_help(SHOW_ACTIVE_TOOLCHAIN_HELP),
.after_help(SHOW_ACTIVE_TOOLCHAIN_HELP)
.arg(
Arg::with_name("verbose")
.help("Enable verbose output with rustc information")
.takes_value(false)
.short("v")
.long("verbose"),
),
)
.subcommand(
SubCommand::with_name("home")
Expand Down Expand Up @@ -1182,17 +1189,22 @@ fn show(cfg: &Cfg) -> Result<utils::ExitCode> {
Ok(utils::ExitCode(0))
}

fn show_active_toolchain(cfg: &Cfg) -> Result<utils::ExitCode> {
fn show_active_toolchain(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
let verbose = m.is_present("verbose");
let cwd = utils::current_dir()?;
match cfg.find_or_install_override_toolchain_or_default(&cwd) {
Err(crate::Error(crate::ErrorKind::ToolchainNotSelected, _)) => {}
Err(e) => return Err(e.into()),
Ok((toolchain, reason)) => {
if let Some(reason) = reason {
writeln!(process().stdout(), "{} ({})", toolchain.name(), reason)?;
write!(process().stdout(), "{} ({})", toolchain.name(), reason,)?;
} else {
writeln!(process().stdout(), "{} (default)", toolchain.name())?;
write!(process().stdout(), "{} (default)", toolchain.name(),)?;
}
if verbose {
write!(process().stdout(), " - {}", toolchain.rustc_version())?;
}
writeln!(process().stdout())?
}
}
Ok(utils::ExitCode(0))
Expand Down Expand Up @@ -1446,7 +1458,7 @@ fn override_remove(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<utils::ExitCode> {
Ok(utils::ExitCode(0))
}

const DOCS_DATA: &[(&str, &str, &str,)] = &[
const DOCS_DATA: &[(&str, &str, &str, )] = &[
// flags can be used to open specific documents, e.g. `rustup doc --nomicon`
// tuple elements: document name used as flag, help message, document index path
("alloc", "The Rust core allocation and collections library", "alloc/index.html"),
Expand Down

0 comments on commit ee9645f

Please sign in to comment.