Skip to content

Commit

Permalink
nl: make --no-renumber a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cakebaker committed Jul 4, 2023
1 parent 6e3ab23 commit fee5225
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/uu/nl/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn parse_style(chars: &[char]) -> Result<crate::NumberingStyle, String> {
pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) -> Vec<String> {
// This vector holds error messages encountered.
let mut errs: Vec<String> = vec![];
settings.renumber = !opts.contains_id(options::NO_RENUMBER);
settings.renumber = opts.get_flag(options::NO_RENUMBER);
match opts.get_one::<String>(options::NUMBER_SEPARATOR) {
None => {}
Some(val) => {
Expand Down
3 changes: 2 additions & 1 deletion src/uu/nl/src/nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ pub fn uu_app() -> Command {
Arg::new(options::NO_RENUMBER)
.short('p')
.long(options::NO_RENUMBER)
.help("do not reset line numbers at logical pages"),
.help("do not reset line numbers at logical pages")
.action(ArgAction::SetFalse),
)
.arg(
Arg::new(options::NUMBER_SEPARATOR)
Expand Down
7 changes: 7 additions & 0 deletions tests/by-util/test_nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,10 @@ fn test_sections_and_styles() {
}
// spell-checker:enable
}

#[test]
fn test_no_renumber() {
for arg in ["-p", "--no-renumber"] {
new_ucmd!().arg(arg).succeeds();
}
}

0 comments on commit fee5225

Please sign in to comment.