Skip to content

Commit

Permalink
shims: fix bug that displayed debug info if -v or -vv was passed (#…
Browse files Browse the repository at this point in the history
…1184)

* shims: fix bug that displayed debug info if `-v` or `-vv` was passed

* lint

* lint

* lint
  • Loading branch information
jdx authored Dec 14, 2023
1 parent 5a314a6 commit f4b8c34
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/cli/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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" {
Expand All @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ pub static RTX_EXE: Lazy<PathBuf> = Lazy::new(|| {
.or_else(|| current_exe().ok())
.unwrap_or_else(|| "rtx".into())
});
pub static RTX_BIN_NAME: Lazy<String> = Lazy::new(|| {
let arg0 = &ARGS.read().unwrap()[0];
arg0.rsplit_once('/').unwrap_or(("", &arg0)).1.to_string()
});
pub static RTX_LOG_LEVEL: Lazy<LevelFilter> = Lazy::new(log_level);
pub static RTX_LOG_FILE_LEVEL: Lazy<LevelFilter> = Lazy::new(log_file_level);
pub static RTX_FETCH_REMOTE_VERSIONS_TIMEOUT: Lazy<Duration> = Lazy::new(|| {
Expand Down Expand Up @@ -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('=') {
Expand Down
7 changes: 3 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions src/shims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OsString> = 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,
Expand Down

0 comments on commit f4b8c34

Please sign in to comment.