1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-31 04:57:45 +00:00

du/od/sort: refactor - replace map_or_else with unwrap_or_else

This commit is contained in:
Jan Scheer 2021-06-06 21:55:39 +02:00
parent 81e07a6a4d
commit 884f570125
3 changed files with 12 additions and 20 deletions

View file

@ -229,10 +229,8 @@ fn get_file_info(path: &Path) -> Option<FileInfo> {
fn read_block_size(s: Option<&str>) -> usize {
if let Some(s) = s {
parse_size(s).map_or_else(
|e| crash!(1, "{}", format_error_message(e, s, options::BLOCK_SIZE)),
|n| n,
)
parse_size(s)
.unwrap_or_else(|e| crash!(1, "{}", format_error_message(e, s, options::BLOCK_SIZE)))
} else {
for env_var in &["DU_BLOCK_SIZE", "BLOCK_SIZE", "BLOCKSIZE"] {
if let Ok(env_size) = env::var(env_var) {

View file

@ -134,10 +134,9 @@ impl OdOptions {
}
let mut skip_bytes = matches.value_of(options::SKIP_BYTES).map_or(0, |s| {
parse_number_of_bytes(s).map_or_else(
|e| crash!(1, "{}", format_error_message(e, s, options::SKIP_BYTES)),
|n| n,
)
parse_number_of_bytes(s).unwrap_or_else(|e| {
crash!(1, "{}", format_error_message(e, s, options::SKIP_BYTES))
})
});
let mut label: Option<usize> = None;
@ -165,10 +164,8 @@ impl OdOptions {
if matches.occurrences_of(options::WIDTH) == 0 {
return 16;
};
parse_number_of_bytes(s).map_or_else(
|e| crash!(1, "{}", format_error_message(e, s, options::WIDTH)),
|n| n,
)
parse_number_of_bytes(s)
.unwrap_or_else(|e| crash!(1, "{}", format_error_message(e, s, options::WIDTH)))
});
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 read_bytes = matches.value_of(options::READ_BYTES).map(|s| {
parse_number_of_bytes(s).map_or_else(
|e| crash!(1, "{}", format_error_message(e, s, options::READ_BYTES)),
|n| n,
)
parse_number_of_bytes(s).unwrap_or_else(|e| {
crash!(1, "{}", format_error_message(e, s, options::READ_BYTES))
})
});
let radix = match matches.value_of(options::ADDRESS_RADIX) {

View file

@ -1158,10 +1158,8 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
settings.buffer_size = matches
.value_of(OPT_BUF_SIZE)
.map_or(DEFAULT_BUF_SIZE, |s| {
GlobalSettings::parse_byte_count(s).map_or_else(
|e| crash!(2, "{}", format_error_message(e, s, OPT_BUF_SIZE)),
|n| n,
)
GlobalSettings::parse_byte_count(s)
.unwrap_or_else(|e| crash!(2, "{}", format_error_message(e, s, OPT_BUF_SIZE)))
});
settings.tmp_dir = matches