ic-query-cli 0.104.0

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
use super::options::node_list_request;
use crate::cli::{
    clap::parsed_options,
    common::{current_unix_secs, write_text_or_json_verbose},
};
use crate::nns::{NnsCommandError, leaf};
use crate::presentation::nns::node::{nns_node_info_report_text, nns_node_list_report_text};
use crate::progress::StderrQueryProgress;
use crate::storage::cache_root;
use clap::ArgMatches;
use ic_query::nns::NnsInventoryCacheRequest;
use ic_query::nns::node::{
    build_nns_node_info_report_with_source_and_progress,
    build_nns_node_list_report_with_source_and_progress,
};
use ic_query::nns::refresh_nns_registry_inventory_with_source;

pub(in crate::nns) async fn run(
    matches: &ArgMatches,
    network: &str,
) -> Result<(), NnsCommandError> {
    match matches.subcommand() {
        Some(("status", matches)) => {
            crate::nns::operational_status::run(
                crate::nns::operational_status::OperationalStatusSubject::Node,
                parsed_options(matches),
                network,
            )
            .await
        }
        Some(("list", matches)) => run_node_list(matches, network).await,
        Some(("info", matches)) => {
            leaf::run_cached_leaf_info(
                matches,
                network,
                async |request, progress| {
                    build_nns_node_info_report_with_source_and_progress(
                        request,
                        &ic_query::nns::LiveNnsSource::default(),
                        progress,
                    )
                    .await
                },
                nns_node_info_report_text,
            )
            .await
        }
        Some(("refresh", matches)) => {
            leaf::run_cached_leaf_refresh(
                matches,
                network,
                async |request| {
                    refresh_nns_registry_inventory_with_source(
                        request,
                        &ic_query::nns::LiveNnsSource::default(),
                    )
                    .await
                },
                crate::presentation::nns::nns_inventory_refresh_report_text,
            )
            .await
        }
        _ => unreachable!("clap requires a known NNS node subcommand"),
    }
}

async fn run_node_list(matches: &ArgMatches, network: &str) -> Result<(), NnsCommandError> {
    let (format, verbose, request) = node_list_request(
        matches,
        NnsInventoryCacheRequest::new(cache_root()?, network),
        current_unix_secs()?,
    );
    let report = build_nns_node_list_report_with_source_and_progress(
        &request,
        &ic_query::nns::LiveNnsSource::default(),
        &mut StderrQueryProgress::new(),
    )
    .await?;
    write_text_or_json_verbose(format, &report, verbose, nns_node_list_report_text)
}