Skip to content

Commit 44ebbfd

Browse files
committed
--version should just print the command name, not the path
This will fix the parsing for old autoconf Closes: uutils#8880
1 parent 0c3eb12 commit 44ebbfd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/uucore/src/lib/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,14 @@ static UTIL_NAME: LazyLock<String> = LazyLock::new(|| {
328328
let is_man = usize::from(ARGV[base_index].eq("manpage"));
329329
let argv_index = base_index + is_man;
330330

331-
ARGV[argv_index].to_string_lossy().into_owned()
331+
// Strip directory path to show only utility name
332+
// (e.g., "mkdir" instead of "./target/debug/mkdir")
333+
// in version output, error messages, and other user-facing output
334+
std::path::Path::new(&ARGV[argv_index])
335+
.file_name()
336+
.unwrap_or(&ARGV[argv_index])
337+
.to_string_lossy()
338+
.into_owned()
332339
});
333340

334341
/// Derive the utility name.

tests/by-util/test_mkdir.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ fn test_invalid_arg() {
2424
new_ucmd!().arg("--definitely-invalid").fails_with_code(1);
2525
}
2626

27+
#[test]
28+
fn test_version_no_path() {
29+
let result = new_ucmd!().arg("--version").succeeds();
30+
let stdout = result.stdout_str();
31+
32+
assert!(stdout.starts_with("mkdir (uutils coreutils)"));
33+
34+
let first_line = stdout.lines().next().unwrap();
35+
assert!(!first_line.starts_with("./") && !first_line.starts_with('/'));
36+
}
37+
2738
#[test]
2839
fn test_no_arg() {
2940
new_ucmd!()

0 commit comments

Comments
 (0)