mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2026-01-16 10:11:01 +00:00
du: reduce the complexity by moving get_convert_size_fn option mgmt into a function
This commit is contained in:
parent
f475a36204
commit
b2fd72878e
1 changed files with 17 additions and 13 deletions
|
|
@ -400,6 +400,20 @@ fn convert_size_other(size: u64, _multiplier: u64, block_size: u64) -> String {
|
|||
format!("{}", ((size as f64) / (block_size as f64)).ceil())
|
||||
}
|
||||
|
||||
fn get_convert_size_fn(matches: &ArgMatches) -> Box<dyn Fn(u64, u64, u64) -> String> {
|
||||
if matches.get_flag(options::HUMAN_READABLE) || matches.get_flag(options::SI) {
|
||||
Box::new(convert_size_human)
|
||||
} else if matches.get_flag(options::BYTES) {
|
||||
Box::new(convert_size_b)
|
||||
} else if matches.get_flag(options::BLOCK_SIZE_1K) {
|
||||
Box::new(convert_size_k)
|
||||
} else if matches.get_flag(options::BLOCK_SIZE_1M) {
|
||||
Box::new(convert_size_m)
|
||||
} else {
|
||||
Box::new(convert_size_other)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum DuError {
|
||||
InvalidMaxDepthArg(String),
|
||||
|
|
@ -556,19 +570,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
|||
} else {
|
||||
1024
|
||||
};
|
||||
let convert_size_fn = {
|
||||
if matches.get_flag(options::HUMAN_READABLE) || matches.get_flag(options::SI) {
|
||||
convert_size_human
|
||||
} else if matches.get_flag(options::BYTES) {
|
||||
convert_size_b
|
||||
} else if matches.get_flag(options::BLOCK_SIZE_1K) {
|
||||
convert_size_k
|
||||
} else if matches.get_flag(options::BLOCK_SIZE_1M) {
|
||||
convert_size_m
|
||||
} else {
|
||||
convert_size_other
|
||||
}
|
||||
};
|
||||
|
||||
let convert_size_fn = get_convert_size_fn(&matches);
|
||||
|
||||
let convert_size = |size: u64| {
|
||||
if options.inodes {
|
||||
size.to_string()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue