1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 20:17:45 +00:00

sort: fix ignore-leading-blanks long option

This commit is contained in:
Michael Debertol 2021-06-10 22:49:17 +02:00
parent fb035aa049
commit b8d4411291
2 changed files with 14 additions and 12 deletions

View file

@ -91,7 +91,7 @@ mod options {
pub const MERGE: &str = "merge"; pub const MERGE: &str = "merge";
pub const DEBUG: &str = "debug"; pub const DEBUG: &str = "debug";
pub const IGNORE_CASE: &str = "ignore-case"; pub const IGNORE_CASE: &str = "ignore-case";
pub const IGNORE_BLANKS: &str = "ignore-blanks"; pub const IGNORE_LEADING_BLANKS: &str = "ignore-leading-blanks";
pub const IGNORE_NONPRINTING: &str = "ignore-nonprinting"; pub const IGNORE_NONPRINTING: &str = "ignore-nonprinting";
pub const OUTPUT: &str = "output"; pub const OUTPUT: &str = "output";
pub const REVERSE: &str = "reverse"; pub const REVERSE: &str = "reverse";
@ -149,7 +149,7 @@ impl SortMode {
pub struct GlobalSettings { pub struct GlobalSettings {
mode: SortMode, mode: SortMode,
debug: bool, debug: bool,
ignore_blanks: bool, ignore_leading_blanks: bool,
ignore_case: bool, ignore_case: bool,
dictionary_order: bool, dictionary_order: bool,
ignore_non_printing: bool, ignore_non_printing: bool,
@ -219,7 +219,7 @@ impl Default for GlobalSettings {
GlobalSettings { GlobalSettings {
mode: SortMode::Default, mode: SortMode::Default,
debug: false, debug: false,
ignore_blanks: false, ignore_leading_blanks: false,
ignore_case: false, ignore_case: false,
dictionary_order: false, dictionary_order: false,
ignore_non_printing: false, ignore_non_printing: false,
@ -310,7 +310,7 @@ impl From<&GlobalSettings> for KeySettings {
fn from(settings: &GlobalSettings) -> Self { fn from(settings: &GlobalSettings) -> Self {
Self { Self {
mode: settings.mode, mode: settings.mode,
ignore_blanks: settings.ignore_blanks, ignore_blanks: settings.ignore_leading_blanks,
ignore_case: settings.ignore_case, ignore_case: settings.ignore_case,
ignore_non_printing: settings.ignore_non_printing, ignore_non_printing: settings.ignore_non_printing,
reverse: settings.reverse, reverse: settings.reverse,
@ -517,7 +517,7 @@ impl<'a> Line<'a> {
&& !settings.stable && !settings.stable
&& !settings.unique && !settings.unique
&& (settings.dictionary_order && (settings.dictionary_order
|| settings.ignore_blanks || settings.ignore_leading_blanks
|| settings.ignore_case || settings.ignore_case
|| settings.ignore_non_printing || settings.ignore_non_printing
|| settings.mode != SortMode::Default || settings.mode != SortMode::Default
@ -681,9 +681,11 @@ impl FieldSelector {
// This would be ideal for a try block, I think. In the meantime this closure allows // This would be ideal for a try block, I think. In the meantime this closure allows
// to use the `?` operator here. // to use the `?` operator here.
Self::new( Self::new(
KeyPosition::new(from, 1, global_settings.ignore_blanks)?, KeyPosition::new(from, 1, global_settings.ignore_leading_blanks)?,
to.map(|(to, _)| KeyPosition::new(to, 0, global_settings.ignore_blanks)) to.map(|(to, _)| {
.transpose()?, KeyPosition::new(to, 0, global_settings.ignore_leading_blanks)
})
.transpose()?,
KeySettings::from(global_settings), KeySettings::from(global_settings),
) )
})() })()
@ -1040,9 +1042,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
), ),
) )
.arg( .arg(
Arg::with_name(options::IGNORE_BLANKS) Arg::with_name(options::IGNORE_LEADING_BLANKS)
.short("b") .short("b")
.long(options::IGNORE_BLANKS) .long(options::IGNORE_LEADING_BLANKS)
.help("ignore leading blanks when finding sort keys in each line"), .help("ignore leading blanks when finding sort keys in each line"),
) )
.arg( .arg(
@ -1247,7 +1249,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
settings.ignore_case = matches.is_present(options::IGNORE_CASE); settings.ignore_case = matches.is_present(options::IGNORE_CASE);
settings.ignore_blanks = matches.is_present(options::IGNORE_BLANKS); settings.ignore_leading_blanks = matches.is_present(options::IGNORE_LEADING_BLANKS);
settings.output_file = matches.value_of(options::OUTPUT).map(String::from); settings.output_file = matches.value_of(options::OUTPUT).map(String::from);
settings.reverse = matches.is_present(options::REVERSE); settings.reverse = matches.is_present(options::REVERSE);

View file

@ -794,7 +794,7 @@ fn test_nonexistent_file() {
#[test] #[test]
fn test_blanks() { fn test_blanks() {
test_helper("blanks", &["-b", "--ignore-blanks"]); test_helper("blanks", &["-b", "--ignore-leading-blanks"]);
} }
#[test] #[test]