use argh::FromArgs;
type Result<T = (), E = Box<dyn std::error::Error>> = std::result::Result<T, E>;
#[derive(Debug, FromArgs)]
struct Cli {
#[argh(switch, short = 'f')]
force: bool,
#[argh(positional)]
paths: Vec<String>,
}
fn main() -> Result {
let cli: Cli = argh::from_env();
for path in cli.paths {
match std::fs::canonicalize(path) {
Ok(path) => {
if let Err(e) = trash::delete(&path) {
if cli.force {
if path.is_file() {
if let Err(e) = std::fs::remove_file(path) {
eprintln!("{:#?}", e);
}
}
else if path.is_dir() {
if let Err(e) = std::fs::remove_dir_all(path) {
eprintln!("{:#?}", e);
}
}
}
else {
eprintln!("{:#?}", e);
}
}
}
Err(e) => eprintln!("{:#?}", e),
}
}
Ok(())
}