Skip to main content

ironflow_cli/commands/
workflow.rs

1//! Workflow subcommands: list, get.
2
3use anyhow::Result;
4use clap::{Args, Subcommand};
5use ironflow_sdk::IronflowClient;
6
7use crate::output;
8
9/// Arguments for the `workflow` command group.
10#[derive(Debug, Args)]
11pub struct WorkflowArgs {
12    /// Workflow subcommand.
13    #[command(subcommand)]
14    pub command: WorkflowCommands,
15}
16
17/// Available workflow subcommands.
18#[derive(Debug, Subcommand)]
19pub enum WorkflowCommands {
20    /// List all registered workflows.
21    List,
22    /// Get details of a specific workflow.
23    Get {
24        /// Workflow name.
25        name: String,
26    },
27}
28
29/// Execute a workflow subcommand.
30///
31/// # Errors
32///
33/// Returns an error on API failure.
34pub async fn execute(client: &IronflowClient, args: &WorkflowArgs, json_mode: bool) -> Result<()> {
35    match &args.command {
36        WorkflowCommands::List => {
37            let response = client.list_workflows().await?;
38            output::print_output(json_mode, &response, || {
39                output::workflows_table(&response.data)
40            })?;
41        }
42        WorkflowCommands::Get { name } => {
43            let response = client.get_workflow(name).await?;
44            output::print_output(json_mode, &response, || {
45                output::workflow_detail_table(&response.data)
46            })?;
47        }
48    }
49    Ok(())
50}