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}
64
65pub async fn execute(client: &IronflowClient, args: &StatsArgs, json_mode: bool) -> Result<()> {
71 match &args.command {
72 None => {
73 let response = client.get_stats().await?;
74 output::print_output(json_mode, &response, || output::stats_table(&response.data))?;
75 }
76 Some(StatsCommands::History {
77 workflow,
78 period,
79 granularity,
80 status,
81 label,
82 has_steps,
83 created_by,
84 concurrency_group,
85 }) => {
86 let params = StatsHistoryParams {
87 workflow: workflow.as_deref(),
88 period: Some(period.as_str()),
89 granularity: granularity.as_deref(),
90 status: status.as_deref(),
91 label: label.as_deref(),
92 has_steps: *has_steps,
93 created_by: *created_by,
94 concurrency_group: concurrency_group.as_deref(),
95 };
96 let response = client.stats_history_with(¶ms).await?;
97 output::print_output(json_mode, &response, || {
98 output::stats_history_table(&response.data)
99 })?;
100 }
101 }
102 Ok(())
103}