From 46c77a1668e3bc621052292aa8406c8a74345bc1 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Sat, 16 May 2026 16:15:02 +0900 Subject: [PATCH] support prefixed names --- src/main.rs | 18 +++++++++++------- tests/integration.rs | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index b7c2712..d0adb69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,7 @@ fn main() -> ExitCode { let exe_path = binary_path(&mut args); let exe_name = name(&exe_path); - let util_name = if exe_name == "diffutils" { + let util_name = if exe_name.as_encoded_bytes().ends_with(b"diffutils") { // Discard the item we peeked. let _ = args.next(); @@ -69,13 +69,17 @@ fn main() -> ExitCode { OsString::from(exe_name) }; - match util_name.to_str() { - Some("diff") => diff::main(args), - Some("cmp") => cmp::main(args), - Some(name) => { - eprintln!("{name}: utility not supported"); + match util_name.as_encoded_bytes() { + name if name.ends_with(b"diff") => diff::main(args), + name if name.ends_with(b"cmp") => cmp::main(args), + name => { + use std::io::{stderr, Write as _}; + let _ = writeln!( + stderr(), + "{}: utility not supported", + String::from_utf8_lossy(name) + ); ExitCode::from(2) } - None => second_arg_error(exe_name), } } diff --git a/tests/integration.rs b/tests/integration.rs index 0e8d21e..e6b14e2 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -32,7 +32,7 @@ mod common { "Expected utility name as second argument, got nothing.\n", )); - for subcmd in ["diff", "cmp"] { + for subcmd in ["diff", "cmp", "uu-diff", "uucmp"] { let mut cmd = cargo_bin_cmd!("diffutils"); cmd.arg(subcmd); cmd.arg("--foobar");