cellstate/entity/
gates.rs

1//! `cellstate gates` — Query policy gate information.
2//!
3//! Subcommands: metadata, stats.
4
5use anyhow::Result;
6use clap::{ArgMatches, Command};
7
8use super::client::ApiClient;
9use super::output::OutputConfig;
10
11const BASE: &str = "/api/v1/gates";
12
13pub fn build_command() -> Command {
14    Command::new("gates")
15        .about("Query policy gate information")
16        .subcommand_required(true)
17        .subcommand(Command::new("metadata").about("Get gate metadata"))
18        .subcommand(Command::new("stats").about("Get gate statistics"))
19}
20
21pub async fn dispatch(
22    matches: &ArgMatches,
23    client: &ApiClient,
24    output: &OutputConfig,
25    _session: &crate::session::CliSession,
26) -> Result<()> {
27    match matches.subcommand() {
28        Some(("metadata", _sub)) => {
29            let resp: serde_json::Value = client.get_raw(&format!("{BASE}/metadata")).await?;
30            output.print_value(&resp);
31        }
32        Some(("stats", _sub)) => {
33            let resp: serde_json::Value = client.get_raw(&format!("{BASE}/stats")).await?;
34            output.print_value(&resp);
35        }
36        _ => unreachable!("subcommand_required(true) prevents this"),
37    }
38    Ok(())
39}