diskr-cli 1.0.0

Save your disk space, without fear of deleting the wrong thing.
Documentation
use anyhow::{Context, Result};
use std::path::Path;

pub fn move_to_trash(paths: &[&Path]) -> Result<usize> {
    let mut moved = 0;
    for p in paths {
        trash::delete(p).with_context(|| format!("failed to trash {}", p.display()))?;
        moved += 1;
    }
    Ok(moved)
}

pub fn restore_from_trash(name_contains: &str) -> Result<usize> {
    let items = trash::os_limited::list()?;
    let matches: Vec<_> = items.into_iter()
        .filter(|i| i.name.to_string_lossy().contains(name_contains))
        .collect();
    if matches.is_empty() {
        return Ok(0);
    }
    trash::os_limited::restore_all(matches.clone())?;
    Ok(matches.len())
}