hb/src/main.rs

58 lines
1.3 KiB
Rust

#![feature(io_error_more, fs_try_exists)]
mod args;
mod directory;
mod unit;
use args::Args;
use directory::Directory;
use std::process::ExitCode;
fn main() -> ExitCode {
let args = Args::parse_and_process();
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.minimal() && !args.quiet() {
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.unit()));
} 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
}