mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 05:27:45 +00:00
du/od/sort: refactor - replace map_or_else with unwrap_or_else
This commit is contained in:
parent
81e07a6a4d
commit
884f570125
3 changed files with 12 additions and 20 deletions
|
@ -229,10 +229,8 @@ fn get_file_info(path: &Path) -> Option<FileInfo> {
|
||||||
|
|
||||||
fn read_block_size(s: Option<&str>) -> usize {
|
fn read_block_size(s: Option<&str>) -> usize {
|
||||||
if let Some(s) = s {
|
if let Some(s) = s {
|
||||||
parse_size(s).map_or_else(
|
parse_size(s)
|
||||||
|e| crash!(1, "{}", format_error_message(e, s, options::BLOCK_SIZE)),
|
.unwrap_or_else(|e| crash!(1, "{}", format_error_message(e, s, options::BLOCK_SIZE)))
|
||||||
|n| n,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
for env_var in &["DU_BLOCK_SIZE", "BLOCK_SIZE", "BLOCKSIZE"] {
|
for env_var in &["DU_BLOCK_SIZE", "BLOCK_SIZE", "BLOCKSIZE"] {
|
||||||
if let Ok(env_size) = env::var(env_var) {
|
if let Ok(env_size) = env::var(env_var) {
|
||||||
|
|
|
@ -134,10 +134,9 @@ impl OdOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut skip_bytes = matches.value_of(options::SKIP_BYTES).map_or(0, |s| {
|
let mut skip_bytes = matches.value_of(options::SKIP_BYTES).map_or(0, |s| {
|
||||||
parse_number_of_bytes(s).map_or_else(
|
parse_number_of_bytes(s).unwrap_or_else(|e| {
|
||||||
|e| crash!(1, "{}", format_error_message(e, s, options::SKIP_BYTES)),
|
crash!(1, "{}", format_error_message(e, s, options::SKIP_BYTES))
|
||||||
|n| n,
|
})
|
||||||
)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut label: Option<usize> = None;
|
let mut label: Option<usize> = None;
|
||||||
|
@ -165,10 +164,8 @@ impl OdOptions {
|
||||||
if matches.occurrences_of(options::WIDTH) == 0 {
|
if matches.occurrences_of(options::WIDTH) == 0 {
|
||||||
return 16;
|
return 16;
|
||||||
};
|
};
|
||||||
parse_number_of_bytes(s).map_or_else(
|
parse_number_of_bytes(s)
|
||||||
|e| crash!(1, "{}", format_error_message(e, s, options::WIDTH)),
|
.unwrap_or_else(|e| crash!(1, "{}", format_error_message(e, s, options::WIDTH)))
|
||||||
|n| n,
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let min_bytes = formats.iter().fold(1, |max, next| {
|
let min_bytes = formats.iter().fold(1, |max, next| {
|
||||||
|
@ -182,10 +179,9 @@ impl OdOptions {
|
||||||
let output_duplicates = matches.is_present(options::OUTPUT_DUPLICATES);
|
let output_duplicates = matches.is_present(options::OUTPUT_DUPLICATES);
|
||||||
|
|
||||||
let read_bytes = matches.value_of(options::READ_BYTES).map(|s| {
|
let read_bytes = matches.value_of(options::READ_BYTES).map(|s| {
|
||||||
parse_number_of_bytes(s).map_or_else(
|
parse_number_of_bytes(s).unwrap_or_else(|e| {
|
||||||
|e| crash!(1, "{}", format_error_message(e, s, options::READ_BYTES)),
|
crash!(1, "{}", format_error_message(e, s, options::READ_BYTES))
|
||||||
|n| n,
|
})
|
||||||
)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let radix = match matches.value_of(options::ADDRESS_RADIX) {
|
let radix = match matches.value_of(options::ADDRESS_RADIX) {
|
||||||
|
|
|
@ -1158,10 +1158,8 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
settings.buffer_size = matches
|
settings.buffer_size = matches
|
||||||
.value_of(OPT_BUF_SIZE)
|
.value_of(OPT_BUF_SIZE)
|
||||||
.map_or(DEFAULT_BUF_SIZE, |s| {
|
.map_or(DEFAULT_BUF_SIZE, |s| {
|
||||||
GlobalSettings::parse_byte_count(s).map_or_else(
|
GlobalSettings::parse_byte_count(s)
|
||||||
|e| crash!(2, "{}", format_error_message(e, s, OPT_BUF_SIZE)),
|
.unwrap_or_else(|e| crash!(2, "{}", format_error_message(e, s, OPT_BUF_SIZE)))
|
||||||
|n| n,
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
settings.tmp_dir = matches
|
settings.tmp_dir = matches
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue