feat: enable actual actions

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
2024-10-26 12:55:37 +02:00
parent 2d7a053ab0
commit 7804eaa667
7 changed files with 160 additions and 27 deletions

View File

@@ -40,8 +40,19 @@ impl Cli {
}
async fn get_commands(&self) -> anyhow::Result<Vec<clap::Command>> {
let actions = self
.cuddle
.state
.actions
.actions
.iter()
.map(|a| clap::Command::new(&a.name))
.collect::<Vec<_>>();
Ok(vec![
clap::Command::new("do").subcommand_required(true),
clap::Command::new("do")
.subcommand_required(true)
.subcommands(actions.as_slice()),
clap::Command::new("get")
.about(GetCommand::description())
.arg(
@@ -67,8 +78,23 @@ impl Cli {
.subcommand()
.ok_or(anyhow::anyhow!("failed to find subcommand"))?
{
("do", _args) => {
("do", args) => {
tracing::debug!("executing do");
let (action_name, args) = args
.subcommand()
.ok_or(anyhow::anyhow!("failed to find do subcommand"))?;
let action = self
.cuddle
.state
.actions
.actions
.iter()
.find(|a| a.name == action_name)
.ok_or(anyhow::anyhow!("failed to find {}", action_name))?;
action.call().await?;
}
("get", args) => {
if !self.cuddle.has_project() {