ic-query-cli 0.104.1

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
use crate::cli::clap::parsed_options;
use crate::cli::common::{
    COLLECTION_MODE_LIVE, SourceOutputOptions, collection_help, current_unix_secs,
};
use crate::nns::{NnsCommandError, write_text_or_json};
use crate::presentation::nns::registry::nns_registry_version_report_text;
use clap::{ArgMatches, Command as ClapCommand, Subcommand};
use ic_query::nns::registry::{
    DEFAULT_NNS_REGISTRY_SOURCE_ENDPOINT, NnsRegistryVersionRequest,
    build_nns_registry_version_report_with_source,
};

const REGISTRY_VERSION_HELP_AFTER: &str = "\
Examples:
  icq nns registry version
  icq --network ic nns registry version --json
  icq nns registry version --source-endpoint https://icp-api.io";

///
/// RegistryCommand
///
/// Certified Registry version operation and its source/output arguments.
///

#[derive(Subcommand)]
#[command(about = "Inspect NNS registry metadata", long_about = None)]
enum RegistryCommand {
    #[command(about = "Show the certified latest mainnet NNS registry version", long_about = None, after_help = collection_help(COLLECTION_MODE_LIVE, REGISTRY_VERSION_HELP_AFTER), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_NNS_REGISTRY_SOURCE_ENDPOINT).help("IC API endpoint used for the certified NNS registry query")))]
    Version(SourceOutputOptions),
}

pub(in crate::nns) fn registry_command() -> ClapCommand {
    RegistryCommand::augment_subcommands(ClapCommand::new("registry"))
}

pub(super) async fn run(matches: &ArgMatches, network: &str) -> Result<(), NnsCommandError> {
    let RegistryCommand::Version(options) = parsed_options(matches);
    let format = options.format();
    let request =
        NnsRegistryVersionRequest::new(network, options.source_endpoint, current_unix_secs()?);
    let report = build_nns_registry_version_report_with_source(
        &request,
        &ic_query::nns::LiveNnsSource::default(),
    )
    .await?;
    write_text_or_json(format, &report, nns_registry_version_report_text)
}