64 lines
1.4 KiB
Rust
64 lines
1.4 KiB
Rust
#![feature(io_error_more, fs_try_exists)]
|
|
|
|
mod args;
|
|
mod directory;
|
|
mod unit;
|
|
|
|
use args::Args;
|
|
use directory::Directory;
|
|
|
|
use clap::Parser;
|
|
|
|
use std::process::ExitCode;
|
|
|
|
fn main() -> ExitCode {
|
|
let args = Args::parse().post_process();
|
|
// dbg!(&args);
|
|
|
|
let mut total = 0;
|
|
for path in args.iter() {
|
|
let dir_structure = match Directory::new(path, &args) {
|
|
Ok(Some(ds)) => ds,
|
|
// this only ever returns None when persistant,
|
|
// so we don't need a match guard
|
|
Ok(None) => continue,
|
|
Err(e) => {
|
|
if args.persistant() {
|
|
continue;
|
|
}
|
|
if !args.minimal() {
|
|
eprintln!("hb: {e}");
|
|
}
|
|
return ExitCode::FAILURE;
|
|
}
|
|
};
|
|
|
|
total += dir_structure.size();
|
|
|
|
if args.minimal() {
|
|
// skip printing (this is a matter of indentation)
|
|
continue;
|
|
}
|
|
|
|
if args.tree() {
|
|
println!("{}", dir_structure.tree(&args));
|
|
} else {
|
|
println!(
|
|
"{}: {}",
|
|
dir_structure.path().display(),
|
|
args.unit().convert(dir_structure.size())
|
|
);
|
|
}
|
|
}
|
|
|
|
let total = args.unit().convert(total);
|
|
|
|
if args.total() {
|
|
println!("total: {total}");
|
|
}
|
|
else if args.minimal() {
|
|
print!("{total}");
|
|
}
|
|
|
|
ExitCode::SUCCESS
|
|
} |