From 8cff520efea00331636328afbadae0582dd03025 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Tue, 17 Mar 2026 15:57:07 +0900 Subject: [PATCH] Start deprecating dangerous -h/-V aliases --- docs/src/extensions.md | 2 +- src/bin/coreutils.rs | 6 +++--- tests/test_util_name.rs | 29 ++++++++++++++--------------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/docs/src/extensions.md b/docs/src/extensions.md index bb0dfff0617..ce7ff0ecbb7 100644 --- a/docs/src/extensions.md +++ b/docs/src/extensions.md @@ -23,7 +23,7 @@ $ ls -w=80 ``` With GNU coreutils, `--help` usually prints the help message and `--version` prints the version. -We also commonly provide short options: `-h` for help and `-V` for version. +We also have short aliases for them: `-h` for help and `-V` for version for few utils. But we deprecate them since it cause confusion at some cases e.g. `sort -h`. ## `coreutils` diff --git a/src/bin/coreutils.rs b/src/bin/coreutils.rs index 59634849a6b..44aa44e585d 100644 --- a/src/bin/coreutils.rs +++ b/src/bin/coreutils.rs @@ -77,7 +77,7 @@ fn main() { match util { "--list" => { // If --help is also present, show usage instead of list - if args.any(|arg| arg == "--help" || arg == "-h") { + if args.any(|arg| arg == "--help") { usage(&utils, binary_as_util); process::exit(0); } @@ -87,7 +87,7 @@ fn main() { } process::exit(0); } - "--version" | "-V" => { + "--version" => { println!("{binary_as_util} {VERSION} (multi-call binary)"); process::exit(0); } @@ -106,7 +106,7 @@ fn main() { process::exit(uumain(vec![util_os].into_iter().chain(args))); } None => { - if util == "--help" || util == "-h" { + if util == "--help" { // see if they want help on a specific util if let Some(util_os) = args.next() { let Some(util) = util_os.to_str() else { diff --git a/tests/test_util_name.rs b/tests/test_util_name.rs index 17b9dc36e5e..15bf69f49ae 100644 --- a/tests/test_util_name.rs +++ b/tests/test_util_name.rs @@ -192,21 +192,20 @@ fn util_version() { 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 = env::var("CARGO_PKG_VERSION").unwrap(); - assert_eq!(format!("coreutils {ver} (multi-call binary)\n"), output_str); - } + + let child = Command::new(&scenario.bin_path) + .arg("--version") + .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 = env::var("CARGO_PKG_VERSION").unwrap(); + assert_eq!(format!("coreutils {ver} (multi-call binary)\n"), output_str); } #[test]