mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +00:00
Merge pull request #277 from ebfe/du
du: exit with status 1 on invalid arguments
This commit is contained in:
commit
e8c12735e8
1 changed files with 12 additions and 11 deletions
23
du/du.rs
23
du/du.rs
|
@ -200,11 +200,11 @@ ers of 1000).",
|
||||||
match (max_depth_str, max_depth) {
|
match (max_depth_str, max_depth) {
|
||||||
(Some(ref s), _) if summarize => {
|
(Some(ref s), _) if summarize => {
|
||||||
println!("{}: warning: summarizing conflicts with --max-depth={:s}", program, *s);
|
println!("{}: warning: summarizing conflicts with --max-depth={:s}", program, *s);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
(Some(ref s), None) => {
|
(Some(ref s), None) => {
|
||||||
println!("{}: invalid maximum depth '{:s}'", program, *s);
|
println!("{}: invalid maximum depth '{:s}'", program, *s);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
(Some(_), Some(_)) | (None, _) => { /* valid */ }
|
(Some(_), Some(_)) | (None, _) => { /* valid */ }
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ ers of 1000).",
|
||||||
for c in s.as_slice().chars() {
|
for c in s.as_slice().chars() {
|
||||||
if found_letter && c.is_digit() || !found_number && !c.is_digit() {
|
if found_letter && c.is_digit() || !found_number && !c.is_digit() {
|
||||||
println!("{}: invalid --block-size argument '{}'", program, s);
|
println!("{}: invalid --block-size argument '{}'", program, s);
|
||||||
return 0;
|
return 1;
|
||||||
} else if c.is_digit() {
|
} else if c.is_digit() {
|
||||||
found_number = true;
|
found_number = true;
|
||||||
numbers.push(c as u8);
|
numbers.push(c as u8);
|
||||||
|
@ -261,7 +261,8 @@ ers of 1000).",
|
||||||
"ZB" => 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000,
|
"ZB" => 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000,
|
||||||
"YB" => 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000,
|
"YB" => 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000,
|
||||||
_ => {
|
_ => {
|
||||||
println!("{}: invalid --block-size argument '{}'", program, s); return 0;
|
println!("{}: invalid --block-size argument '{}'", program, s);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
number * multiple
|
number * multiple
|
||||||
|
@ -271,9 +272,9 @@ ers of 1000).",
|
||||||
|
|
||||||
let convert_size = |size: u64| -> String {
|
let convert_size = |size: u64| -> String {
|
||||||
if matches.opt_present("human-readable") || matches.opt_present("si") {
|
if matches.opt_present("human-readable") || matches.opt_present("si") {
|
||||||
if size > MB {
|
if size >= MB {
|
||||||
format!("{:.1f}M", (size as f64) / (MB as f64))
|
format!("{:.1f}M", (size as f64) / (MB as f64))
|
||||||
} else if size > KB {
|
} else if size >= KB {
|
||||||
format!("{:.1f}K", (size as f64) / (KB as f64))
|
format!("{:.1f}K", (size as f64) / (KB as f64))
|
||||||
} else {
|
} else {
|
||||||
format!("{}B", size)
|
format!("{}B", size)
|
||||||
|
@ -300,7 +301,7 @@ Valid arguments are:
|
||||||
- 'long-iso'
|
- 'long-iso'
|
||||||
- 'iso'
|
- 'iso'
|
||||||
Try '{program} --help' for more information.", s, program = program);
|
Try '{program} --help' for more information.", s, program = program);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -339,7 +340,7 @@ Try '{program} --help' for more information.", s, program = program);
|
||||||
Valid arguments are:
|
Valid arguments are:
|
||||||
- 'accessed', 'created', 'modified'
|
- 'accessed', 'created', 'modified'
|
||||||
Try '{program} --help' for more information.", program = program);
|
Try '{program} --help' for more information.", program = program);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => stat.fstat.modified
|
None => stat.fstat.modified
|
||||||
|
@ -350,11 +351,11 @@ Try '{program} --help' for more information.", s, program = program);
|
||||||
time::at(time_spec).strftime(time_format_str)
|
time::at(time_spec).strftime(time_format_str)
|
||||||
};
|
};
|
||||||
if !summarize || (summarize && index == len-1) {
|
if !summarize || (summarize && index == len-1) {
|
||||||
print!("{:<10} {:<30} {}{}", convert_size(size), time_str, stat.path.display(), line_separator);
|
print!("{}\t{}\t{}{}", convert_size(size), time_str, stat.path.display(), line_separator);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if !summarize || (summarize && index == len-1) {
|
if !summarize || (summarize && index == len-1) {
|
||||||
print!("{:<10} {}{}", convert_size(size), stat.path.display(), line_separator);
|
print!("{}\t{}{}", convert_size(size), stat.path.display(), line_separator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if options_arc.total && index == (len - 1) {
|
if options_arc.total && index == (len - 1) {
|
||||||
|
@ -366,7 +367,7 @@ Try '{program} --help' for more information.", s, program = program);
|
||||||
}
|
}
|
||||||
|
|
||||||
if options_arc.total {
|
if options_arc.total {
|
||||||
print!("{:<10} total", convert_size(grand_total));
|
print!("{}\ttotal", convert_size(grand_total));
|
||||||
print!("{}", line_separator);
|
print!("{}", line_separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue