rustutils_unlink/
lib.rs

1use clap::Parser;
2use rustutils_runnable::Runnable;
3use std::error::Error;
4use std::fs::remove_file;
5use std::io;
6use std::path::PathBuf;
7
8/// Remove files by calling the unlink function.
9#[derive(Parser, Clone, Debug)]
10#[clap(author, version, about)]
11pub struct Unlink {
12    /// List of files to remove.
13    #[clap(required = true)]
14    pub files: Vec<PathBuf>,
15}
16
17impl Unlink {
18    /// Iterate through supplied files and remove them.
19    pub fn run(&self) -> Result<(), io::Error> {
20        for file in &self.files {
21            remove_file(&file)?;
22        }
23        Ok(())
24    }
25}
26
27impl Runnable for Unlink {
28    fn run(&self) -> Result<(), Box<dyn Error>> {
29        self.run().map_err(|e| Box::new(e) as Box<dyn Error>)
30    }
31}