remove bad error messages, enable multiple input paths

This commit is contained in:
Luca Bilke 2024-05-02 19:37:36 +02:00
parent 6c35d32acf
commit 0eb45bab22
No known key found for this signature in database
GPG Key ID: AD6630D0A1E650AC
1 changed files with 6 additions and 18 deletions

View File

@ -16,7 +16,7 @@ enum Commands {
/// Lists trashed files /// Lists trashed files
List { path: Option<PathBuf> }, List { path: Option<PathBuf> },
/// Put a file into the trash /// Put a file into the trash
Put { path: PathBuf }, Put { path: Vec<PathBuf> },
/// Restore a file by its id /// Restore a file by its id
Restore { id: PathBuf }, Restore { id: PathBuf },
/// Prune files older than n days (defaults to 7) /// Prune files older than n days (defaults to 7)
@ -24,10 +24,7 @@ enum Commands {
} }
fn list<P: Fn(&trash::TrashItem) -> bool>(predicate: P) -> Vec<trash::TrashItem> { fn list<P: Fn(&trash::TrashItem) -> bool>(predicate: P) -> Vec<trash::TrashItem> {
let trashed = match trash::os_limited::list() { let trashed = trash::os_limited::list().unwrap();
Ok(t) => t,
Err(_) => panic!("Error listing trashed files"),
};
trashed.into_iter().filter(predicate).collect() trashed.into_iter().filter(predicate).collect()
} }
@ -52,11 +49,8 @@ fn print_list(path: Option<PathBuf>) {
} }
} }
fn put(path: PathBuf) { fn put(path: Vec<PathBuf>) {
match trash::delete(path) { trash::delete_all(path).unwrap()
Ok(_) => (),
Err(_) => panic!("Error trashing file"),
}
} }
fn restore(id: PathBuf) { fn restore(id: PathBuf) {
@ -68,10 +62,7 @@ fn restore(id: PathBuf) {
_ => panic!("Multiple trashed files with that id"), _ => panic!("Multiple trashed files with that id"),
} }
match trash::os_limited::restore_all(items) { trash::os_limited::restore_all(items).unwrap()
Ok(_) => (),
Err(_) => panic!("Error restoring trashed file"),
}
} }
fn prune(max_days: Option<u64>) { fn prune(max_days: Option<u64>) {
@ -81,10 +72,7 @@ fn prune(max_days: Option<u64>) {
let items: Vec<trash::TrashItem> = list(predicate).into_iter().collect(); let items: Vec<trash::TrashItem> = list(predicate).into_iter().collect();
match trash::os_limited::purge_all(items) { trash::os_limited::purge_all(items).unwrap()
Ok(_) => (),
Err(_) => panic!("Error pruning files"),
}
} }
fn main() { fn main() {