mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 13:07:46 +00:00
Merge pull request #4995 from cakebaker/nl_implement_default_for_settings
nl: implement Default for Settings
This commit is contained in:
commit
ed71bb60e0
1 changed files with 21 additions and 18 deletions
|
@ -6,8 +6,6 @@
|
||||||
// * file that was distributed with this source code.
|
// * file that was distributed with this source code.
|
||||||
// *
|
// *
|
||||||
|
|
||||||
// spell-checker:ignore (ToDO) corasick memchr
|
|
||||||
|
|
||||||
use clap::{crate_version, Arg, ArgAction, Command};
|
use clap::{crate_version, Arg, ArgAction, Command};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{stdin, BufRead, BufReader, Read};
|
use std::io::{stdin, BufRead, BufReader, Read};
|
||||||
|
@ -18,8 +16,8 @@ use uucore::{format_usage, help_about, help_usage};
|
||||||
|
|
||||||
mod helper;
|
mod helper;
|
||||||
|
|
||||||
static ABOUT: &str = help_about!("nl.md");
|
const ABOUT: &str = help_about!("nl.md");
|
||||||
static USAGE: &str = help_usage!("nl.md");
|
const USAGE: &str = help_usage!("nl.md");
|
||||||
|
|
||||||
// Settings store options used by nl to produce its output.
|
// Settings store options used by nl to produce its output.
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
@ -42,6 +40,24 @@ pub struct Settings {
|
||||||
number_separator: String,
|
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.
|
// NumberingStyle stores which lines are to be numbered.
|
||||||
// The possible options are:
|
// The possible options are:
|
||||||
// 1. Number all lines
|
// 1. Number all lines
|
||||||
|
@ -87,20 +103,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
|
|
||||||
let matches = uu_app().try_get_matches_from(args)?;
|
let matches = uu_app().try_get_matches_from(args)?;
|
||||||
|
|
||||||
// A mutable settings object, initialized with the defaults.
|
let mut settings = Settings::default();
|
||||||
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"),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Update the settings from the command line options, and terminate the
|
// Update the settings from the command line options, and terminate the
|
||||||
// program if some options could not successfully be parsed.
|
// program if some options could not successfully be parsed.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue