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
2 changes: 2 additions & 0 deletions src/uu/nl/src/nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ pub fn uu_app() -> Command {
.long(options::LINE_INCREMENT)
.help(translate!("nl-help-line-increment"))
.value_name("NUMBER")
.allow_hyphen_values(true)
.value_parser(clap::value_parser!(i64)),
)
.arg(
Expand Down Expand Up @@ -368,6 +369,7 @@ pub fn uu_app() -> Command {
.long(options::STARTING_LINE_NUMBER)
.help(translate!("nl-help-starting-line-number"))
.value_name("NUMBER")
.allow_hyphen_values(true)
.value_parser(clap::value_parser!(i64)),
)
.arg(
Expand Down
21 changes: 21 additions & 0 deletions tests/by-util/test_nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@ fn test_negative_starting_line_number() {
}
}

#[test]
fn test_negative_starting_line_number_space_separated() {
// GNU nl accepts a negative value passed as a separate argument, e.g.
// `nl -v -10`. Without `allow_hyphen_values` clap rejected the `-10` token.
new_ucmd!()
.args(&["-v", "-10"])
.pipe_in("test")
.succeeds()
.stdout_is(" -10\ttest\n");
}

#[test]
fn test_invalid_starting_line_number() {
for arg in ["-vinvalid", "--starting-line-number=invalid"] {
Expand Down Expand Up @@ -298,6 +309,16 @@ fn test_negative_line_increment() {
}
}

#[test]
fn test_negative_line_increment_space_separated() {
// GNU nl accepts `nl -i -10` with the value as a separate argument.
new_ucmd!()
.args(&["-i", "-10"])
.pipe_in("a\nb\nc")
.succeeds()
.stdout_is(" 1\ta\n -9\tb\n -19\tc\n");
}

#[test]
fn test_invalid_line_increment() {
for arg in ["-iinvalid", "--line-increment=invalid"] {
Expand Down
Loading