Skip to content

Commit 58da229

Browse files
authored
support prefixed names (#231)
1 parent 250f935 commit 58da229

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/main.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn main() -> ExitCode {
5858
let exe_path = binary_path(&mut args);
5959
let exe_name = name(&exe_path);
6060

61-
let util_name = if exe_name == "diffutils" {
61+
let util_name = if exe_name.as_encoded_bytes().ends_with(b"diffutils") {
6262
// Discard the item we peeked.
6363
let _ = args.next();
6464

@@ -69,13 +69,17 @@ fn main() -> ExitCode {
6969
OsString::from(exe_name)
7070
};
7171

72-
match util_name.to_str() {
73-
Some("diff") => diff::main(args),
74-
Some("cmp") => cmp::main(args),
75-
Some(name) => {
76-
eprintln!("{name}: utility not supported");
72+
match util_name.as_encoded_bytes() {
73+
name if name.ends_with(b"diff") => diff::main(args),
74+
name if name.ends_with(b"cmp") => cmp::main(args),
75+
name => {
76+
use std::io::{stderr, Write as _};
77+
let _ = writeln!(
78+
stderr(),
79+
"{}: utility not supported",
80+
String::from_utf8_lossy(name)
81+
);
7782
ExitCode::from(2)
7883
}
79-
None => second_arg_error(exe_name),
8084
}
8185
}

tests/integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod common {
3232
"Expected utility name as second argument, got nothing.\n",
3333
));
3434

35-
for subcmd in ["diff", "cmp"] {
35+
for subcmd in ["diff", "cmp", "uu-diff", "uucmp"] {
3636
let mut cmd = cargo_bin_cmd!("diffutils");
3737
cmd.arg(subcmd);
3838
cmd.arg("--foobar");

0 commit comments

Comments
 (0)