ic-query-cli 0.104.0

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
//! Module: icrc::commands
//!
//! Responsibility: compose generic ICRC CLI command families and shared arguments.
//! Does not own: live ledger calls, report DTOs, or text rendering.
//! Boundary: keeps ledger and account grammar separate behind one ICRC facade.

mod account;
mod analytics;
mod dispatch;
mod ledger;
pub(in crate::icrc) mod options;
#[cfg(test)]
mod tests;
use account::AccountCommand;
use analytics::AnalyticsCommand;
pub use dispatch::run_matches;
use ledger::LedgerCommand;

use crate::cli::clap::principal_text_value_parser;
use clap::{Command as ClapCommand, Subcommand, builder::ValueParser};
use ic_query::icrc::normalize_subaccount_hex;

const DEFAULT_ICRC_TRANSACTIONS_LIMIT: &str = "25";
const MAX_ICRC_TRANSACTIONS_LIMIT: u64 = 100;
const DEFAULT_ICRC_ACCOUNT_TRANSACTION_PAGE_SIZE: &str = "100";

///
/// IcrcCommand
///
/// Parsed ICRC family and its complete typed operation tree.
///

#[derive(Subcommand)]
#[command(about = "Inspect generic ICRC ledgers and official analytics", long_about = None)]
enum IcrcCommand {
    #[command(subcommand)]
    Ledger(LedgerCommand),
    #[command(subcommand)]
    Account(AccountCommand),
    #[command(subcommand)]
    Analytics(AnalyticsCommand),
}

pub fn command() -> ClapCommand {
    IcrcCommand::augment_subcommands(ClapCommand::new("icrc"))
        .mut_subcommand("ledger", |command| {
            command.mut_subcommands(|command| {
                command
                    .mut_arg("source-endpoint", |arg| {
                        arg.help("IC API endpoint used for ICRC ledger queries")
                            .display_order(20)
                    })
                    .mut_arg("json", |arg| arg.display_order(22))
            })
        })
        .mut_subcommand("account", with_account_endpoint)
        .mut_subcommand("analytics", analytics::configure)
}

fn with_account_endpoint(command: ClapCommand) -> ClapCommand {
    if command.has_subcommands() {
        command.mut_subcommands(with_account_endpoint)
    } else {
        command
            .mut_arg("source-endpoint", |arg| {
                arg.help("IC API endpoint used for ICRC ledger queries")
                    .display_order(1000)
            })
            .mut_arg("json", |arg| arg.display_order(1001))
    }
}

fn subaccount_hex_value_parser() -> ValueParser {
    ValueParser::new(|value: &str| normalize_subaccount_hex(value).map_err(|err| err.to_string()))
}