ironflow_cli/commands/
stats.rs1use anyhow::Result;
4use clap::{Args, Subcommand};
5use ironflow_sdk::IronflowClient;
6
7use crate::output;
8
9#[derive(Debug, Args)]
17pub struct StatsArgs {
18 #[command(subcommand)]
20 pub command: Option<StatsCommands>,
21}
22
23#[derive(Debug, Subcommand)]
31pub enum StatsCommands {
32 History {
34 #[arg(long)]
36 workflow: Option<String>,
37 #[arg(long, default_value = "7d")]
39 period: String,
40 #[arg(long)]
42 granularity: Option<String>,
43 },
44}
45
46pub async fn execute(client: &IronflowClient, args: &StatsArgs, json_mode: bool) -> Result<()> {
52 match &args.command {
53 None => {
54 let response = client.get_stats().await?;
55 output::print_output(json_mode, &response, || output::stats_table(&response.data))?;
56 }
57 Some(StatsCommands::History {
58 workflow,
59 period,
60 granularity,
61 }) => {
62 let response = client
63 .stats_history(
64 workflow.as_deref(),
65 Some(period.as_str()),
66 granularity.as_deref(),
67 )
68 .await?;
69 output::print_output(json_mode, &response, || {
70 output::stats_history_table(&response.data)
71 })?;
72 }
73 }
74 Ok(())
75}