use anyhow::Result;
use clap::{Args, Subcommand};
use ironflow_sdk::IronflowClient;
use crate::output;
#[derive(Debug, Args)]
pub struct StatsArgs {
#[command(subcommand)]
pub command: Option<StatsCommands>,
}
#[derive(Debug, Subcommand)]
pub enum StatsCommands {
History {
#[arg(long)]
workflow: Option<String>,
#[arg(long, default_value = "7d")]
period: String,
#[arg(long)]
granularity: Option<String>,
},
}
pub async fn execute(client: &IronflowClient, args: &StatsArgs, json_mode: bool) -> Result<()> {
match &args.command {
None => {
let response = client.get_stats().await?;
output::print_output(json_mode, &response, || output::stats_table(&response.data))?;
}
Some(StatsCommands::History {
workflow,
period,
granularity,
}) => {
let response = client
.stats_history(
workflow.as_deref(),
Some(period.as_str()),
granularity.as_deref(),
)
.await?;
output::print_output(json_mode, &response, || {
output::stats_history_table(&response.data)
})?;
}
}
Ok(())
}