Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/uu/pr/src/pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +241 to +243

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need three lines of comment here. Please make it shorter, or remove it.

.num_args(0..=1)
.value_name("[char][width]"),
)
.arg(
Expand Down
13 changes: 13 additions & 0 deletions tests/by-util/test_pr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading