Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nl: implement Default for Settings #4995

Merged
merged 3 commits into from
Jun 24, 2023
Merged
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
39 changes: 21 additions & 18 deletions src/uu/nl/src/nl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// * file that was distributed with this source code.
// *

// spell-checker:ignore (ToDO) corasick memchr

use clap::{crate_version, Arg, ArgAction, Command};
use std::fs::File;
use std::io::{stdin, BufRead, BufReader, Read};
Expand All @@ -18,8 +16,8 @@ use uucore::{format_usage, help_about, help_usage};

mod helper;

static ABOUT: &str = help_about!("nl.md");
static USAGE: &str = help_usage!("nl.md");
const ABOUT: &str = help_about!("nl.md");
const USAGE: &str = help_usage!("nl.md");

// Settings store options used by nl to produce its output.
pub struct Settings {
Expand All @@ -42,6 +40,24 @@ pub struct Settings {
number_separator: String,
}

impl Default for Settings {
fn default() -> Self {
Self {
header_numbering: NumberingStyle::NumberForNone,
body_numbering: NumberingStyle::NumberForAll,
footer_numbering: NumberingStyle::NumberForNone,
section_delimiter: ['\\', ':'],
starting_line_number: 1,
line_increment: 1,
join_blank_lines: 1,
number_width: 6,
number_format: NumberFormat::Right,
renumber: true,
number_separator: String::from("\t"),
}
}
}

// NumberingStyle stores which lines are to be numbered.
// The possible options are:
// 1. Number all lines
Expand Down Expand Up @@ -87,20 +103,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {

let matches = uu_app().try_get_matches_from(args)?;

// A mutable settings object, initialized with the defaults.
let mut settings = Settings {
header_numbering: NumberingStyle::NumberForNone,
body_numbering: NumberingStyle::NumberForAll,
footer_numbering: NumberingStyle::NumberForNone,
section_delimiter: ['\\', ':'],
starting_line_number: 1,
line_increment: 1,
join_blank_lines: 1,
number_width: 6,
number_format: NumberFormat::Right,
renumber: true,
number_separator: String::from("\t"),
};
let mut settings = Settings::default();

// Update the settings from the command line options, and terminate the
// program if some options could not successfully be parsed.
Expand Down