Skip to content

Commit fe37a36

Browse files
committed
refactor(cli): Pull out rustup check
1 parent b87c932 commit fe37a36

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/bin/cargo/cli.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::fmt::Write;
1212
use super::commands;
1313
use super::list_commands;
1414
use crate::command_prelude::*;
15+
use crate::util::is_rustup;
1516
use cargo::core::features::HIDDEN;
1617

1718
pub fn main(config: &mut LazyConfig) -> CliResult {
@@ -511,11 +512,7 @@ impl GlobalArgs {
511512
}
512513

513514
pub fn cli() -> Command {
514-
// ALLOWED: `RUSTUP_HOME` should only be read from process env, otherwise
515-
// other tools may point to executables from incompatible distributions.
516-
#[allow(clippy::disallowed_methods)]
517-
let is_rustup = std::env::var_os("RUSTUP_HOME").is_some();
518-
let usage = if is_rustup {
515+
let usage = if is_rustup() {
519516
"cargo [+toolchain] [OPTIONS] [COMMAND]\n cargo [+toolchain] [OPTIONS] -Zscript <MANIFEST_RS> [ARGS]..."
520517
} else {
521518
"cargo [OPTIONS] [COMMAND]\n cargo [OPTIONS] -Zscript <MANIFEST_RS> [ARGS]..."

src/cargo/util/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ pub mod toml_mut;
6666
mod vcs;
6767
mod workspace;
6868

69+
pub fn is_rustup() -> bool {
70+
// ALLOWED: `RUSTUP_HOME` should only be read from process env, otherwise
71+
// other tools may point to executables from incompatible distributions.
72+
#[allow(clippy::disallowed_methods)]
73+
std::env::var_os("RUSTUP_HOME").is_some()
74+
}
75+
6976
pub fn elapsed(duration: Duration) -> String {
7077
let secs = duration.as_secs();
7178

0 commit comments

Comments
 (0)