From 6a8c3d32ea4ade627ea843169a339ca97cbd343f Mon Sep 17 00:00:00 2001 From: Coro Date: Wed, 12 Aug 2026 20:34:55 -0600 Subject: [PATCH] pr: make -n/--number-lines argument optional to match GNU GNU pr treats the -n/--number-lines argument as optional: a bare -n numbers the lines with a 5-wide, tab-separated line number. uutils required a value, so `pr -t -n` and `pr -t --number-lines` failed with "a value is required". Set num_args(0..=1) so the value is optional; the existing fallback already supplies the default numbering mode. --- src/uu/pr/src/pr.rs | 4 ++++ tests/by-util/test_pr.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/uu/pr/src/pr.rs b/src/uu/pr/src/pr.rs index ec154d6b027..b4ba1b007e2 100644 --- a/src/uu/pr/src/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -238,6 +238,10 @@ pub fn uu_app() -> Command { .long(options::NUMBER_LINES) .help(translate!("pr-help-number-lines")) .allow_hyphen_values(true) + // GNU pr treats the -n/--number-lines argument as optional and + // defaults to a 5-wide, tab-separated line number; without this a + // bare -n or --number-lines fails asking for a value. + .num_args(0..=1) .value_name("[char][width]"), ) .arg( diff --git a/tests/by-util/test_pr.rs b/tests/by-util/test_pr.rs index 9df12978580..91b42b79569 100644 --- a/tests/by-util/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -81,6 +81,19 @@ fn test_number_lines_empty_value_is_rejected() { .stderr_contains("pr: '-n' extra characters or invalid number in the argument"); } +#[test] +fn test_number_lines_without_value_numbers_lines() { + // GNU pr treats -n/--number-lines as optional, defaulting to a 5-wide, + // tab-separated line number, instead of requiring an explicit value. + for arg in ["-n", "--number-lines"] { + new_ucmd!() + .args(&["-t", arg]) + .pipe_in("a\nb\n") + .succeeds() + .stdout_is(" 1\ta\n 2\tb\n"); + } +} + #[test] fn test_without_any_options() { let test_file_path = "test_one_page.log";