From c8983aff97a024d55a69b8f1c9af271effa633ee Mon Sep 17 00:00:00 2001 From: MarcusGrass Date: Mon, 9 Jun 2025 19:48:49 +0200 Subject: [PATCH 1/3] feat: add `--version` argument to print main binary version Issue #8071 --- src/bin/coreutils.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 2821988c2..50a97d6d0 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -145,6 +145,10 @@ fn main() { } process::exit(0); } + "--version" => { + println!("{binary_as_util} {VERSION} (multi-call binary)"); + process::exit(0); + } // Not a special command: fallthrough to calling a util _ => {} } From 3c98dc1bc5836dda6facba728607c5d6eeaaccaf Mon Sep 17 00:00:00 2001 From: MarcusGrass Date: Tue, 10 Jun 2025 20:35:32 +0200 Subject: [PATCH 2/3] feat: make `-V` on main binary also output version information --- src/bin/coreutils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 50a97d6d0..da318d741 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -145,7 +145,7 @@ fn main() { } process::exit(0); } - "--version" => { + "--version" | "-V" => { println!("{binary_as_util} {VERSION} (multi-call binary)"); process::exit(0); } From 6ea6e8cbb40848509c86e0c3ceaa0c26be6ed857 Mon Sep 17 00:00:00 2001 From: MarcusGrass Date: Tue, 10 Jun 2025 20:36:17 +0200 Subject: [PATCH 3/3] fix: Add test for main binary version information output --- tests/test_util_name.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_util_name.rs b/tests/test_util_name.rs index cd0356edc..efa8fe08a 100644 --- a/tests/test_util_name.rs +++ b/tests/test_util_name.rs @@ -251,3 +251,29 @@ fn util_manpage() { let output_str = String::from_utf8(output.stdout).unwrap(); assert!(output_str.contains("\n.TH true 1 "), "{output_str:?}"); } + +#[test] +fn util_version() { + use std::process::{Command, Stdio}; + + let scenario = TestScenario::new("--version"); + if !scenario.bin_path.exists() { + println!("Skipping test: Binary not found at {:?}", scenario.bin_path); + return; + } + for arg in ["-V", "--version"] { + let child = Command::new(&scenario.bin_path) + .arg(arg) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .unwrap(); + let output = child.wait_with_output().unwrap(); + assert_eq!(output.status.code(), Some(0)); + assert_eq!(output.stderr, b""); + let output_str = String::from_utf8(output.stdout).unwrap(); + let ver = std::env::var("CARGO_PKG_VERSION").unwrap(); + assert_eq!(format!("coreutils {ver} (multi-call binary)\n"), output_str); + } +}