Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick addition to --version to mention rustc #2465

Merged
merged 4 commits into from Aug 27, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 41 additions & 7 deletions src/cli/rustup_mode.rs
Expand Up @@ -55,17 +55,51 @@ where
pub fn main() -> Result<utils::ExitCode> {
self_update::cleanup_self_updater()?;

use clap::ErrorKind::*;
let matches = match cli().get_matches_from_safe(process().args_os()) {
Ok(matches) => Ok(matches),
Err(e)
if e.kind == clap::ErrorKind::HelpDisplayed
|| e.kind == clap::ErrorKind::VersionDisplayed =>
{
writeln!(process().stdout().lock(), "{}", e.message)?;
Err(clap::Error {
kind: HelpDisplayed,
message,
..
}) => {
writeln!(process().stdout().lock(), "{}", message)?;
return Ok(utils::ExitCode(0));
}
Err(clap::Error {
kind: VersionDisplayed,
message,
..
}) => {
writeln!(process().stdout().lock(), "{}", message)?;
info!("This is the version for the rustup toolchain manager, not the rustc compiler.");
killercup marked this conversation as resolved.
Show resolved Hide resolved

fn rustc_version() -> std::result::Result<String, Box<dyn std::error::Error>> {
let cfg = &mut common::set_globals(false, true)?;
let cwd = std::env::current_dir()?;

if let Some(t) = process().args().find(|x| x.starts_with('+')) {
debug!("Fetching rustc version from toolchain `{}`", t);
cfg.set_toolchain_override(&t[1..]);
kinnison marked this conversation as resolved.
Show resolved Hide resolved
}

let toolchain = cfg.find_or_install_override_toolchain_or_default(&cwd)?.0;
killercup marked this conversation as resolved.
Show resolved Hide resolved

Ok(toolchain.rustc_version())
}

match rustc_version() {
Ok(version) => info!("The currently active `rustc` version is `{}`", version),
Err(err) => debug!("Wanted to tell you the current rustc version, too, but ran into this error: {}", err),
}
return Ok(utils::ExitCode(0));
}
Err(e) if e.kind == clap::ErrorKind::MissingArgumentOrSubcommand => {
writeln!(process().stdout().lock(), "{}", e.message)?;
Err(clap::Error {
kind: MissingArgumentOrSubcommand,
message,
..
}) => {
kinnison marked this conversation as resolved.
Show resolved Hide resolved
writeln!(process().stdout().lock(), "{}", message)?;
return Ok(utils::ExitCode(1));
}
Err(e) => Err(e),
Expand Down