ic-query-cli 0.104.0

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
//! Module: ic
//!
//! Responsibility: compose and dispatch official IC report command families.
//! Does not own: family-specific parsing, transport, report construction, or rendering.
//! Boundary: exposes certified state and bounded Dashboard wiring to the top-level CLI.

mod api_boundary_node;
mod canister;
mod metrics;
mod network;
mod replica_version;

use crate::cli::{clap::parsed_options, common::CurrentUnixSecsError};
use clap::{ArgMatches, Command as ClapCommand, Subcommand};
use ic_query::ic::IcApiBoundaryNodeHostError;
use ic_query::ic::IcHostError;
use std::io;
use thiserror::Error as ThisError;

///
/// IcCommandError
///
/// Errors surfaced while parsing or running an `icq ic` command.
///

#[derive(Debug, ThisError)]
pub enum IcCommandError {
    #[error("{0}")]
    Usage(String),

    #[error(transparent)]
    Host(#[from] IcHostError),

    /// Certified state-tree collection or report construction failed.
    #[error(transparent)]
    CertifiedState(#[from] IcApiBoundaryNodeHostError),

    #[error(transparent)]
    Clock(#[from] CurrentUnixSecsError),

    #[error(transparent)]
    Io(#[from] io::Error),

    #[error(transparent)]
    Json(#[from] serde_json::Error),
}

pub async fn run_matches(matches: &ArgMatches) -> Result<(), IcCommandError> {
    match parsed_options::<IcCommand>(matches) {
        IcCommand::ApiBoundaryNode(command) => api_boundary_node::run(command).await,
        IcCommand::Canister(command) => canister::run(command).await,
        IcCommand::Metrics(options) => metrics::run(options).await,
        IcCommand::Network(command) => network::run(command).await,
        IcCommand::ReplicaVersion(command) => replica_version::run(command).await,
    }
}

pub fn command() -> ClapCommand {
    IcCommand::augment_subcommands(ClapCommand::new("ic"))
}

///
/// IcCommand
///
/// Typed IC command family and its admitted operation arguments.
///

#[derive(Subcommand)]
#[command(about = "Inspect certified IC state and official Dashboard data", long_about = None)]
enum IcCommand {
    #[command(subcommand)]
    ApiBoundaryNode(api_boundary_node::ApiBoundaryNodeCommand),
    #[command(subcommand)]
    Canister(canister::CanisterCommand),
    Metrics(metrics::MetricOptions),
    #[command(subcommand)]
    Network(network::NetworkCommand),
    #[command(subcommand)]
    ReplicaVersion(replica_version::ReplicaVersionCommand),
}

#[cfg(test)]
mod tests;