diff options
author | sharkdp <davidpeter@web.de> | 2019-09-21 14:26:38 +0200 |
---|---|---|
committer | sharkdp <davidpeter@web.de> | 2019-09-21 14:28:30 +0200 |
commit | ac3ad430f1a6a6006876d18a2fdfff720b255ba5 (patch) | |
tree | 9dfe792d0440ad318fc8efceceae42b958e46de5 /src/main.rs | |
parent | 254931e15d785e21a40593a16a24eecf8cef545f (diff) |
Add '-b'/'--apparent-size' option
This commit changes `diskus` default behavior: we now report "disk
usage" instead of "apparent size" in analogy to "du -sh".
At the same time however, we introduce a new `--apparent-size` option
which can be used to switch back to "apparent size".
closes #25
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index 57f7c9e..693003d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,19 +5,19 @@ use humansize::file_size_opts::{self, FileSizeOpts}; use humansize::FileSize; use num_format::{Locale, ToFormattedString}; -use diskus::walk::{self, Walk}; +use diskus::{Error, FilesizeType, Walk}; -fn print_result(size: u64, errors: &[walk::Error], size_format: &FileSizeOpts, verbose: bool) { +fn print_result(size: u64, errors: &[Error], size_format: &FileSizeOpts, verbose: bool) { if verbose { for err in errors { match err { - walk::Error::NoMetadataForPath(path) => { + Error::NoMetadataForPath(path) => { eprintln!( "diskus: could not retrieve metadata for path '{}'", path.to_string_lossy() ); } - walk::Error::CouldNotReadDir(path) => { + Error::CouldNotReadDir(path) => { eprintln!( "diskus: could not read contents of directory '{}'", path.to_string_lossy() @@ -80,6 +80,14 @@ fn main() { .help("Do not hide filesystem errors"), ); + #[cfg(not(windows))] + let app = app.arg( + Arg::with_name("apparent-size") + .long("apparent-size") + .short("b") + .help("Compute apparent size instead of disk usage"), + ); + let matches = app.get_matches(); // Setting the number of threads to 3x the number of cores is a good tradeoff between @@ -97,6 +105,12 @@ fn main() { .map(|paths| paths.map(PathBuf::from).collect()) .unwrap_or_else(|| vec![PathBuf::from(".")]); + let filesize_type = if matches.is_present("apparent-size") { + FilesizeType::ApparentSize + } else { + FilesizeType::DiskUsage + }; + let size_format = match matches.value_of("size-format") { Some("decimal") => file_size_opts::DECIMAL, _ => file_size_opts::BINARY, @@ -104,7 +118,7 @@ fn main() { let verbose = matches.is_present("verbose"); - let walk = Walk::new(&paths, num_threads); + let walk = Walk::new(&paths, num_threads, filesize_type); let (size, errors) = walk.run(); print_result(size, &errors, &size_format, verbose); } |