From d0b853cd83b1a9d57e7c1b5c9da5cb684f30ca4e Mon Sep 17 00:00:00 2001 From: binhvq Date: Sun, 29 Nov 2026 08:16:01 +0700 Subject: [PATCH] ptx: accept unambiguous abbreviations of --format --- src/uu/ptx/Cargo.toml | 2 +- src/uu/ptx/src/ptx.rs | 3 ++- tests/by-util/test_ptx.rs | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/uu/ptx/Cargo.toml b/src/uu/ptx/Cargo.toml index af66badbc74..24df359d979 100644 --- a/src/uu/ptx/Cargo.toml +++ b/src/uu/ptx/Cargo.toml @@ -22,7 +22,7 @@ fluent = { workspace = true } regex = { workspace = true } rustc-hash = { workspace = true } thiserror = { workspace = true } -uucore = { workspace = true } +uucore = { workspace = true, features = ["parser-num"] } [dev-dependencies] divan = { workspace = true } diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 84600626ed2..a83095ecd2a 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -21,6 +21,7 @@ use rustc_hash::FxHashSet; use uucore::display::Quotable; use uucore::error::{FromIo, UResult, USimpleError, UUsageError}; use uucore::format_usage; +use uucore::parser::shortcut_value_parser::ShortcutValueParser; use uucore::translate; /// GNU's regex engine treats a trailing lone backslash as a literal backslash, @@ -995,7 +996,7 @@ pub fn uu_app() -> Command { Arg::new(options::FORMAT) .long(options::FORMAT) .hide(true) - .value_parser(["roff", "tex"]) + .value_parser(ShortcutValueParser::new(["roff", "tex"])) .overrides_with_all([options::FORMAT, options::format::ROFF, options::format::TEX]), ) .arg( diff --git a/tests/by-util/test_ptx.rs b/tests/by-util/test_ptx.rs index 26943607e6e..cc6fec8bbc9 100644 --- a/tests/by-util/test_ptx.rs +++ b/tests/by-util/test_ptx.rs @@ -237,6 +237,17 @@ fn test_format() { .stdout_only("\\xx {}{}{a}{}{}\n"); } +#[rstest] +#[case::roff("--format=r", ".xx \"\" \"\" \"a\" \"\"\n")] +#[case::tex("--format=te", "\\xx {}{}{a}{}{}\n")] +fn test_format_abbreviation(#[case] arg: &str, #[case] expected: &str) { + new_ucmd!() + .args(&["-G", arg]) + .pipe_in("a") + .succeeds() + .stdout_only(expected); +} + #[cfg(target_os = "linux")] #[test] fn test_failed_write_is_reported() {