From f4b8c347af6251e0e94949f75fac3426185315cb Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Thu, 14 Dec 2023 07:59:35 -0600 Subject: [PATCH] shims: fix bug that displayed debug info if `-v` or `-vv` was passed (#1184) * shims: fix bug that displayed debug info if `-v` or `-vv` was passed * lint * lint * lint --- src/cli/version.rs | 7 ++++--- src/env.rs | 7 ++++++- src/main.rs | 7 +++---- src/shims.rs | 8 ++++---- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/cli/version.rs b/src/cli/version.rs index babb777ee6..e1bf552e9c 100644 --- a/src/cli/version.rs +++ b/src/cli/version.rs @@ -9,7 +9,7 @@ use versions::Versioning; use crate::build_time::{built_info, BUILD_TIME}; use crate::cli::self_update::SelfUpdate; -use crate::env::CI; +use crate::env; use crate::file::modified_duration; use crate::{dirs, duration, file}; @@ -50,7 +50,8 @@ impl Version { } } -pub fn print_version_if_requested(args: &[String]) { +pub fn print_version_if_requested() { + let args = env::ARGS.read().unwrap(); if args.len() == 2 && (args[0] == "rtx" || args[0].ends_with("/rtx")) { let cmd = &args[1].to_lowercase(); if cmd == "version" || cmd == "-v" || cmd == "--version" { @@ -66,7 +67,7 @@ fn show_version() { } fn show_latest() { - if *CI { + if *env::CI { return; } if let Some(latest) = check_for_new_version(duration::DAILY) { diff --git a/src/env.rs b/src/env.rs index ce1767bbf1..71e0528bcf 100644 --- a/src/env.rs +++ b/src/env.rs @@ -49,6 +49,10 @@ pub static RTX_EXE: Lazy = Lazy::new(|| { .or_else(|| current_exe().ok()) .unwrap_or_else(|| "rtx".into()) }); +pub static RTX_BIN_NAME: Lazy = Lazy::new(|| { + let arg0 = &ARGS.read().unwrap()[0]; + arg0.rsplit_once('/').unwrap_or(("", &arg0)).1.to_string() +}); pub static RTX_LOG_LEVEL: Lazy = Lazy::new(log_level); pub static RTX_LOG_FILE_LEVEL: Lazy = Lazy::new(log_file_level); pub static RTX_FETCH_REMOTE_VERSIONS_TIMEOUT: Lazy = Lazy::new(|| { @@ -349,7 +353,8 @@ fn log_level() -> LevelFilter { } let args = ARGS.read().unwrap(); for (i, arg) in args.iter().enumerate() { - if arg == "--" { + // stop parsing after "--" or if we're executing as a shim + if arg == "--" || &*RTX_BIN_NAME != "rtx" { break; } if let Some(("--log-level", level)) = arg.split_once('=') { diff --git a/src/main.rs b/src/main.rs index 6d766d7af7..059ba99647 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,18 +80,17 @@ fn main() -> Result<()> { } fn run() -> Result<()> { - let args = env::ARGS.read().unwrap(); // show version before loading config in case of error - cli::version::print_version_if_requested(&args); + cli::version::print_version_if_requested(); migrate::run(); let config = Config::try_get()?; - shims::handle_shim(&config, &args)?; + shims::handle_shim(&config)?; if config.should_exit_early { return Ok(()); } let cli = Cli::new_with_external_commands(&config); - cli.run(&args) + cli.run(&env::ARGS.read().unwrap()) } fn handle_ctrlc() { diff --git a/src/shims.rs b/src/shims.rs index c5fc75be51..5aa47db0be 100644 --- a/src/shims.rs +++ b/src/shims.rs @@ -23,13 +23,13 @@ use crate::{dirs, file}; // executes as if it was a shim if the command is not "rtx", e.g.: "node" #[allow(dead_code)] -pub fn handle_shim(config: &Config, args: &[String]) -> Result<()> { - let (_, bin_name) = args[0].rsplit_once('/').unwrap_or(("", &args[0])); - if bin_name == "rtx" { +pub fn handle_shim(config: &Config) -> Result<()> { + if *env::RTX_BIN_NAME == "rtx" { return Ok(()); } + let args = env::ARGS.read().unwrap(); let mut args: Vec = args.iter().map(OsString::from).collect(); - args[0] = which_shim(config, bin_name)?.into(); + args[0] = which_shim(config, &env::RTX_BIN_NAME)?.into(); let exec = Exec { tool: vec![], c: None,