use super::commands::{NeuronCacheCommand, NeuronCommand};
use crate::{
cli::{
clap::parsed_options,
common::{OutputFormat, current_unix_secs},
},
nns::{NnsCommandError, collection, write_text_or_json},
presentation::nns::neuron::{
nns_neuron_distribution_report_text, nns_neuron_info_report_text,
nns_neuron_list_report_text,
},
storage::cache_root,
};
use clap::ArgMatches;
use ic_query::nns::{
LiveNnsSource, NnsGovernanceCacheRequest,
neuron::{
build_nns_neuron_cache_status_report, build_nns_neuron_distribution_report_from_cache,
build_nns_neuron_info_report_with_cache_and_source,
build_nns_neuron_list_report_with_cache_and_source,
refresh_nns_neuron_cache_with_source_and_progress,
},
};
pub(in crate::nns) async fn run(
matches: &ArgMatches,
network: &str,
) -> Result<(), NnsCommandError> {
match parsed_options::<NeuronCommand>(matches) {
NeuronCommand::Distribution(options) => {
let report = build_nns_neuron_distribution_report_from_cache(
&NnsGovernanceCacheRequest::new(cache_root()?, network),
)?;
write_text_or_json(
OutputFormat::from_json(options.json),
&report,
nns_neuron_distribution_report_text,
)
}
NeuronCommand::List(options) => {
let text = crate::presentation::TextOptions {
verbose: options.verbose,
};
let (format, request) = options.into_request(network, current_unix_secs()?);
let report = build_nns_neuron_list_report_with_cache_and_source(
&request,
&cache_root()?,
&LiveNnsSource::default(),
)
.await?;
write_text_or_json(format, &report, |report| {
nns_neuron_list_report_text(report, text)
})
}
NeuronCommand::Info(options) => {
let (format, request) = options.into_request(network, current_unix_secs()?);
let report = build_nns_neuron_info_report_with_cache_and_source(
&request,
&cache_root()?,
&LiveNnsSource::default(),
)
.await?;
write_text_or_json(format, &report, nns_neuron_info_report_text)
}
NeuronCommand::Refresh(options) => {
collection::run_refresh(options, network, async |request, progress| {
refresh_nns_neuron_cache_with_source_and_progress(
request,
&LiveNnsSource::default(),
progress,
)
.await
})
.await
}
NeuronCommand::Cache(NeuronCacheCommand::Status(options)) => {
collection::run_cache_status(options, network, build_nns_neuron_cache_status_report)
}
}
}