use std::path::PathBuf;
use abscissa_core::{status_err, Application, Command, Runnable};
use anyhow::Result;
use clap::Args;
use dialoguer::Confirm;
use organize_rs_core::{runner::Runner, state::Initialize, tags::Tag};
use crate::application::ORGANIZE_APP;
#[derive(Command, Debug, Args)]
pub struct RunConfigCmd {
#[arg(long)]
paths: Vec<PathBuf>,
#[arg(long)]
tags: Vec<Tag>,
}
impl RunConfigCmd {
fn inner_run(&self) -> Result<()> {
let runner = Runner::<Initialize>::load_configs(&self.paths)
.apply_filters(self.tags.clone())
.finish_inspection()
.preview_actions()?;
if Confirm::new().with_prompt("Are you sure, that you want to execute the previewed actions? This is irreversible.").default(false).interact()? {
runner.apply_actions()?;
}
Ok(())
}
}
impl Runnable for RunConfigCmd {
fn run(&self) {
match self.inner_run() {
Ok(_) => {}
Err(err) => {
status_err!("{}", err);
ORGANIZE_APP.shutdown(abscissa_core::Shutdown::Crash);
}
}
}
}