2023-01-14 10:36:08 -05:00
|
|
|
use super::Cmd;
|
2023-01-21 18:25:09 -05:00
|
|
|
use clap::{Arg, Command};
|
2023-02-06 18:57:28 -05:00
|
|
|
use shitbox::args;
|
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([
|
2023-01-21 18:25:09 -05:00
|
|
|
args::verbose(),
|
2023-01-14 10:36:08 -05:00
|
|
|
Arg::new("file")
|
|
|
|
.value_name("FILE")
|
|
|
|
.required(true)
|
|
|
|
.num_args(1..),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2023-02-04 08:54:27 -05:00
|
|
|
fn run(&self, matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
2023-01-14 10:36:08 -05:00
|
|
|
if let Some(files) = matches.get_many::<String>("file") {
|
|
|
|
for f in files {
|
2023-02-02 23:34:37 -05:00
|
|
|
unistd::unlink(f)?;
|
|
|
|
if matches.get_flag("verbose") {
|
2023-01-14 10:36:08 -05:00
|
|
|
println!("unlink: {f}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-02-05 23:50:59 -05:00
|
|
|
fn path(&self) -> Option<shitbox::Path> {
|
|
|
|
Some(shitbox::Path::UsrBin)
|
2023-01-14 10:36:08 -05:00
|
|
|
}
|
|
|
|
}
|