ironflow_cli/commands/
stats.rs1use anyhow::Result;
4use clap::{Args, Subcommand};
5use ironflow_sdk::IronflowClient;
6use ironflow_sdk::client::StatsHistoryParams;
7use uuid::Uuid;
8
9use crate::output;
10
11#[derive(Debug, Args)]
19pub struct StatsArgs {
20 #[command(subcommand)]
22 pub command: Option<StatsCommands>,
23}
24
25#[derive(Debug, Subcommand)]
33pub enum StatsCommands {
34 History {
36 #[arg(long)]
38 workflow: Option<String>,
39 #[arg(long, default_value = "7d")]
41 period: String,
42 #[arg(long)]
44 granularity: Option<String>,
45 #[arg(long)]
47 status: Option<String>,
48 #[arg(long)]
50 label: Option<String>,
51 #[arg(long)]
53 has_steps: Option<bool>,
54 #[arg(long)]
58 created_by: Option<Uuid>,
59 #[arg(long)]
61 concurrency_group: Option<String>,
62 },
63 Roles {
65 #[arg(long, default_value = "7d")]
67 period: String,
68 },
69}
70
71pub async fn execute(client: &IronflowClient, args: &StatsArgs, json_mode: bool) -> Result<()> {
77 match &args.command {
78 None => {
79 let response = client.get_stats().await?;
80 output::print_output(json_mode, &response, || output::stats_table(&response.data))?;
81 }
82 Some(StatsCommands::History {
83 workflow,
84 period,
85 granularity,
86 status,
87 label,
88 has_steps,
89 created_by,
90 concurrency_group,
91 }) => {
92 let params = StatsHistoryParams {
93 workflow: workflow.as_deref(),
94 period: Some(period.as_str()),
95 granularity: granularity.as_deref(),
96 status: status.as_deref(),
97 label: label.as_deref(),
98 has_steps: *has_steps,
99 created_by: *created_by,
100 concurrency_group: concurrency_group.as_deref(),
101 };
102 let response = client.stats_history_with(¶ms).await?;
103 output::print_output(json_mode, &response, || {
104 output::stats_history_table(&response.data)
105 })?;
106 }
107 Some(StatsCommands::Roles { period }) => {
108 let response = client.agent_role_stats(Some(period.as_str())).await?;
109 output::print_output(json_mode, &response, || {
110 output::agent_role_stats_table(&response.data)
111 })?;
112 }
113 }
114 Ok(())
115}