From 0e35fb23bfeb773527a98403818fa3c2f751ea53 Mon Sep 17 00:00:00 2001 From: arbelonson-source <269032023+arbelonson-source@users.noreply.github.com> Date: Mon, 31 Aug 2026 09:48:03 +0300 Subject: [PATCH] csplit: accept a hyphen-leading --suffix-format value --suffix-format's value was rejected as an unrecognized flag when given as its own argument (csplit --suffix-format -%02d f /pat/, not the attached -b-%02d or --suffix-format=-%02d): the Arg was missing allow_hyphen_values, the same gap already fixed this session for several other options (sort --parallel, nl's numeric options, ptx --gap-size/--width, join -t). GNU's own --suffix-format accepts any argument as the format string regardless of its first character. AI-assisted-by: Claude Opus 5, via Claude Code --- src/uu/csplit/src/csplit.rs | 1 + tests/by-util/test_csplit.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index fe96f41534f..c4e9d9f5eed 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -680,6 +680,7 @@ pub fn uu_app() -> Command { .short('b') .long(options::SUFFIX_FORMAT) .value_name("FORMAT") + .allow_hyphen_values(true) .help(translate!("csplit-help-suffix-format")), ) .arg( diff --git a/tests/by-util/test_csplit.rs b/tests/by-util/test_csplit.rs index ec60cfa2b9f..93985cc1bc4 100644 --- a/tests/by-util/test_csplit.rs +++ b/tests/by-util/test_csplit.rs @@ -1445,6 +1445,20 @@ fn precision_format() { } } +#[test] +fn suffix_format_hyphen_leading_as_separate_arg() { + // A hyphen-leading suffix format passed as its own argument (not + // attached with `-b-%02d`/`=`) must not be mistaken for a new, + // unrecognized flag. + let (at, mut ucmd) = at_and_ucmd!(); + ucmd.args(&["numbers50.txt", "10", "--suffix-format", "-%02d"]) + .succeeds() + .stdout_only("18\n123\n"); + + assert_eq!(at.read("xx-00"), generate(1, 10)); + assert_eq!(at.read("xx-01"), generate(10, 51)); +} + #[test] fn zero_precision_format() { let (at, mut ucmd) = at_and_ucmd!();