ic-query-cli 0.104.1

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
//! Dispatch admitted proposal operations without reparsing their arguments.

use super::commands::{ProposalCacheCommand, ProposalCommand};
use crate::{
    cli::{clap::parsed_options, common::current_unix_secs},
    nns::{NnsCommandError, collection, write_text_or_json},
    presentation::nns::proposals::{
        nns_proposal_activity_report_text, nns_proposal_list_report_text, nns_proposal_report_text,
    },
    storage::cache_root,
};
use clap::ArgMatches;
use ic_query::nns::{
    LiveNnsSource, NnsGovernanceCacheRequest,
    proposals::{
        build_nns_proposal_activity_report_from_cache, build_nns_proposal_cache_status_report,
        build_nns_proposal_list_report_with_cache_and_source,
        build_nns_proposal_report_with_cache_and_source,
        refresh_nns_proposal_cache_with_source_and_progress,
    },
};

pub(in crate::nns) async fn run(
    matches: &ArgMatches,
    network: &str,
) -> Result<(), NnsCommandError> {
    match parsed_options::<ProposalCommand>(matches) {
        ProposalCommand::Activity(options) => {
            let (format, request) = options.into_request();
            let cache = NnsGovernanceCacheRequest::new(cache_root()?, network);
            let report = build_nns_proposal_activity_report_from_cache(&cache, &request)?;
            write_text_or_json(format, &report, nns_proposal_activity_report_text)
        }
        ProposalCommand::List(options) => {
            let text = crate::presentation::TextOptions {
                verbose: options.verbose,
            };
            let (format, request) = options.into_request(network, current_unix_secs()?)?;
            let report = build_nns_proposal_list_report_with_cache_and_source(
                &request,
                &cache_root()?,
                &LiveNnsSource::default(),
            )
            .await?;
            write_text_or_json(format, &report, |report| {
                nns_proposal_list_report_text(report, text)
            })
        }
        ProposalCommand::Info(options) => {
            let text = crate::presentation::TextOptions {
                verbose: options.verbose,
            };
            let (format, request) = options.into_request(network, current_unix_secs()?);
            let report = build_nns_proposal_report_with_cache_and_source(
                &request,
                &cache_root()?,
                &LiveNnsSource::default(),
            )
            .await?;
            write_text_or_json(format, &report, |report| {
                nns_proposal_report_text(report, text)
            })
        }
        ProposalCommand::Refresh(options) => {
            collection::run_refresh(options, network, async |request, progress| {
                refresh_nns_proposal_cache_with_source_and_progress(
                    request,
                    &LiveNnsSource::default(),
                    progress,
                )
                .await
            })
            .await
        }
        ProposalCommand::Cache(ProposalCacheCommand::Status(options)) => {
            collection::run_cache_status(options, network, build_nns_proposal_cache_status_report)
        }
    }
}