ic-query-cli 0.10.1

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
use super::{announce_missing_catalog, cache_request};
use crate::{
    cli::common::write_text_or_json,
    nns::{
        NnsCommandError, command_args, now_unix_secs,
        subnet::{commands::info_usage, options::CatalogInfoOptions},
    },
};
use ic_query::subnet_catalog::{
    DEFAULT_STALE_AFTER_SECONDS, SubnetCatalogInfoRequest, build_subnet_catalog_info_report,
    subnet_catalog_info_report_text,
};
use std::ffi::OsString;

pub(super) fn run_catalog_info(args: Vec<OsString>) -> Result<(), NnsCommandError> {
    let Some(args) = command_args(args, info_usage) else {
        return Ok(());
    };
    let options = CatalogInfoOptions::parse(args)?;
    let format = options.format;
    let cache = cache_request(&options.network)?;
    announce_missing_catalog(&cache, &options.source_endpoint);
    let mut request = SubnetCatalogInfoRequest::new(
        cache,
        options.source_endpoint,
        options.input,
        now_unix_secs()?,
        DEFAULT_STALE_AFTER_SECONDS,
    );
    if let Some(forced) = options.forced {
        request = request.with_forced(forced);
    }
    let report = build_subnet_catalog_info_report(&request)?;
    write_text_or_json(format, &report, subnet_catalog_info_report_text)
}