From 0ee67d78ef7d6ee074262aa9ca912ab13d291594 Mon Sep 17 00:00:00 2001 From: Gideon <87426140+GideonBear@users.noreply.github.com> Date: Mon, 21 Apr 2025 12:46:00 +0200 Subject: [PATCH] Fix conflict between hx (hexdump alternative) and Helix (#1135) * Fix conflict between hx (hexdump alternative) and Helix * Remove uneccessary unit parameter * Use helix-centered detection --- src/steps/generic.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/steps/generic.rs b/src/steps/generic.rs index 6cf7faf3..4e7e9796 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -1006,8 +1006,39 @@ pub fn run_dotnet_upgrade(ctx: &ExecutionContext) -> Result<()> { Ok(()) } +enum Hx { + Helix(PathBuf), + HxHexdump, +} + +impl Hx { + fn helix(self) -> Result { + match self { + Hx::Helix(hx) => Ok(hx), + Hx::HxHexdump => { + Err(SkipStep("Command `hx` probably points to hx (hexdump alternative)".to_string()).into()) + } + } + } +} + +fn get_hx(ctx: &ExecutionContext) -> Result { + let hx = require("hx")?; + + // Check if `hx --help` mentions "helix". Helix does, hx (hexdump alternative) doesn't. + let output = ctx.run_type().execute(&hx).arg("--help").output_checked()?; + + if String::from_utf8(output.stdout)?.contains("helix") { + debug!("Detected `hx` as Helix"); + Ok(Hx::Helix(hx)) + } else { + debug!("Detected `hx` as hx (hexdump alternative)"); + Ok(Hx::HxHexdump) + } +} + pub fn run_helix_grammars(ctx: &ExecutionContext) -> Result<()> { - let helix = require("helix").or(require("hx"))?; + let helix = require("helix").or(get_hx(ctx)?.helix())?; print_separator("Helix");