use anyhow::Result;
use crate::config::Config;
use crate::make_tokio_runtime;
use crate::params::config::ConfigParams;
#[derive(Debug, clap::Parser)]
#[command(name = "rm", about = "Remove object", disable_version_flag = true)]
pub struct RmCmd {
#[command(flatten)]
pub config_params: ConfigParams,
#[arg()]
pub target: String,
#[arg(short, long)]
pub recursive: bool,
}
impl RmCmd {
pub fn run(self) -> Result<()> {
make_tokio_runtime(1).block_on(self.do_run())
}
async fn do_run(self) -> Result<()> {
let cfg = Config::load(&self.config_params.config)?;
let (op, path) = cfg.parse_location(&self.target)?;
if !self.recursive {
println!("Delete: {path}");
op.delete(&path).await?;
return Ok(());
}
println!("Delete all: {path}");
op.remove_all(&path).await?;
Ok(())
}
}