use crate::commands::{Runnable, RunnableInvokeRules};
use crate::context::AppContext;
use crate::exec::{ExecMode, run_all, run_one};
use anyhow::Result;
use async_trait::async_trait;
use clap::Args;
#[derive(Args, Debug)]
pub struct ExecCmd {
#[arg(value_name = "NAME")]
name: Option<String>,
#[arg(short, long, conflicts_with = "flagged")]
all: bool,
#[arg(short, long, conflicts_with = "all")]
flagged: bool,
}
#[async_trait]
impl Runnable for ExecCmd {
fn get_invoke_rules(&self) -> RunnableInvokeRules {
RunnableInvokeRules {
do_config_autosync: true,
require_sudo: false,
respect_lock: true,
}
}
async fn run(&self, ctx: &AppContext) -> Result<()> {
let loaded_config = ctx.config.load().await?;
let mode = if self.all {
ExecMode::All
} else if self.flagged {
ExecMode::Flagged
} else {
ExecMode::Regular
};
if let Some(cmd_name) = &self.name {
run_one(loaded_config, cmd_name).await?;
} else {
run_all(loaded_config, mode).await?;
}
Ok(())
}
}