ic-query-cli 0.102.0

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
//! Typed neuron read and cache dispatch.
use super::{
    SnsCommandError, options,
    spec::{CacheCommand, NeuronCommand, SnsCommand, sns_command},
};
use crate::presentation::sns::{
    sns_neuron_detail_report_text, sns_neurons_cache_list_report_text,
    sns_neurons_cache_status_report_text, sns_neurons_report_text,
    sns_snapshot_refresh_report_text,
};
use crate::{
    cli::{
        clap::parsed_options,
        common::{OutputFormat, current_unix_secs, write_text_or_json},
    },
    progress::StderrQueryProgress,
    storage::cache_root,
};
use ic_query::sns::{
    LiveSnsSource, build_sns_neuron_detail_report, build_sns_neurons_cache_list_report,
    build_sns_neurons_cache_status_report, build_sns_neurons_report,
    refresh_sns_neurons_cache_with_source_and_progress,
};

pub fn command() -> clap::Command {
    sns_command()
}
pub async fn run_matches(matches: &clap::ArgMatches, network: &str) -> Result<(), SnsCommandError> {
    let SnsCommand::Neuron(command) = parsed_options(matches);
    match command {
        NeuronCommand::Info(options) => {
            let (format, request) =
                options::neuron_request(options, network, current_unix_secs()?)?;
            let report = build_sns_neuron_detail_report(&request).await?;
            write_text_or_json(format, &report, sns_neuron_detail_report_text)
        }
        NeuronCommand::List(options) => {
            let verbose = options.verbose;
            let (format, request) =
                options::neurons_request(options, network, current_unix_secs()?, || {
                    Ok(cache_root()?)
                })?;
            let report = build_sns_neurons_report(&request).await?;
            write_text_or_json(format, &report, |report| {
                sns_neurons_report_text(report, crate::presentation::TextOptions { verbose })
            })
        }
        NeuronCommand::Refresh(options) => {
            let (format, request) = options::snapshot_refresh_request(
                options,
                network,
                cache_root()?,
                current_unix_secs()?,
            )?;
            let report = refresh_sns_neurons_cache_with_source_and_progress(
                &request,
                &LiveSnsSource::default(),
                &mut StderrQueryProgress::new(),
            )
            .await?;
            write_text_or_json(format, &report, sns_snapshot_refresh_report_text)
        }
        NeuronCommand::Cache(CacheCommand::List { json }) => {
            let format = OutputFormat::from_json(json);
            let request = ic_query::sns::SnsCacheListRequest {
                network: network.to_string(),
                cache_root: cache_root()?,
            };
            let report = build_sns_neurons_cache_list_report(&request)?;
            write_text_or_json(format, &report, sns_neurons_cache_list_report_text)
        }
        NeuronCommand::Cache(CacheCommand::Status(options)) => {
            let (format, request) = options::cache_status_request(options, network, cache_root()?);
            let report = build_sns_neurons_cache_status_report(&request)?;
            write_text_or_json(format, &report, sns_neurons_cache_status_report_text)
        }
    }
}