From fe37a3672c9746825c4989c2297685fe3339a779 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 31 Aug 2023 08:50:00 -0500 Subject: [PATCH] refactor(cli): Pull out rustup check --- src/bin/cargo/cli.rs | 7 ++----- src/cargo/util/mod.rs | 7 +++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bin/cargo/cli.rs b/src/bin/cargo/cli.rs index ce6112817ec..d39dce754e5 100644 --- a/src/bin/cargo/cli.rs +++ b/src/bin/cargo/cli.rs @@ -12,6 +12,7 @@ use std::fmt::Write; use super::commands; use super::list_commands; use crate::command_prelude::*; +use crate::util::is_rustup; use cargo::core::features::HIDDEN; pub fn main(config: &mut LazyConfig) -> CliResult { @@ -511,11 +512,7 @@ impl GlobalArgs { } pub fn cli() -> Command { - // ALLOWED: `RUSTUP_HOME` should only be read from process env, otherwise - // other tools may point to executables from incompatible distributions. - #[allow(clippy::disallowed_methods)] - let is_rustup = std::env::var_os("RUSTUP_HOME").is_some(); - let usage = if is_rustup { + let usage = if is_rustup() { "cargo [+toolchain] [OPTIONS] [COMMAND]\n cargo [+toolchain] [OPTIONS] -Zscript [ARGS]..." } else { "cargo [OPTIONS] [COMMAND]\n cargo [OPTIONS] -Zscript [ARGS]..." diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index af7dd368781..2c3e5a80274 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -66,6 +66,13 @@ pub mod toml_mut; mod vcs; mod workspace; +pub fn is_rustup() -> bool { + // ALLOWED: `RUSTUP_HOME` should only be read from process env, otherwise + // other tools may point to executables from incompatible distributions. + #[allow(clippy::disallowed_methods)] + std::env::var_os("RUSTUP_HOME").is_some() +} + pub fn elapsed(duration: Duration) -> String { let secs = duration.as_secs();