shitbox/src/cmd/unlink/mod.rs

43 lines
1.2 KiB
Rust
Raw Normal View History

2023-01-14 10:36:08 -05:00
use super::Cmd;
use crate::{args, unistd};
use clap::{Arg, Command};
use std::io;
2023-01-14 10:36:08 -05:00
#[derive(Debug, Default)]
pub struct Unlink;
impl Cmd for Unlink {
fn cli(&self) -> clap::Command {
Command::new("unlink")
.about("call the unlink function to remove the specified file")
.author("Nathan Fisher")
.version(env!("CARGO_PKG_VERSION"))
.args([
args::verbose(),
2023-01-14 10:36:08 -05:00
Arg::new("file")
.value_name("FILE")
.required(true)
.num_args(1..),
])
}
fn run(&self, matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
let Some(matches) = matches else {
return Err(Box::new(io::Error::new(io::ErrorKind::Other, "no input")));
};
if let Some(files) = matches.get_many::<String>("file") {
for f in files {
unistd::unlink(f)?;
if matches.get_flag("verbose") {
2023-01-14 10:36:08 -05:00
println!("unlink: {f}");
}
}
}
Ok(())
}
fn path(&self) -> Option<crate::Path> {
Some(crate::Path::UsrBin)
}
}