mod collection;
mod data_center;
mod governance;
mod leaf;
mod neuron;
mod node;
mod node_operator;
mod node_provider;
mod operational_status;
mod proposals;
mod registry;
mod subnet;
#[cfg(test)]
mod tests;
mod topology;
use crate::{
cli::common::{CurrentUnixSecsError, OutputFormat, write_text_or_json},
storage::CacheRootError,
};
use clap::{ArgMatches, Command as ClapCommand};
use ic_query::ic::IcHostError;
use ic_query::ic::IcNodeStatusHostError;
use ic_query::nns::NnsInventoryError;
use ic_query::nns::governance::NnsGovernanceError;
use ic_query::nns::neuron::NnsNeuronHostError;
use ic_query::nns::proposals::NnsProposalHostError;
use ic_query::nns::registry::NnsRegistryHostError;
use ic_query::nns::topology::NnsTopologyHostError;
use ic_query::subnet_catalog::SubnetCatalogHostError;
use std::io;
use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub enum NnsCommandError {
#[error("{0}")]
Usage(String),
#[error("{0}")]
SubnetHost(#[source] Box<SubnetCatalogHostError>),
#[error(transparent)]
InventoryHost(#[from] NnsInventoryError),
#[error(transparent)]
Governance(#[from] NnsGovernanceError),
#[error(transparent)]
NeuronHost(#[from] NnsNeuronHostError),
#[error(transparent)]
ProposalHost(#[from] NnsProposalHostError),
#[error(transparent)]
RegistryHost(#[from] NnsRegistryHostError),
#[error(transparent)]
TopologyHost(#[from] NnsTopologyHostError),
#[error(transparent)]
NodeStatusHost(#[from] IcNodeStatusHostError),
#[error(transparent)]
DashboardHost(#[from] IcHostError),
#[error(transparent)]
Clock(#[from] CurrentUnixSecsError),
#[error(transparent)]
Io(#[from] io::Error),
#[error(transparent)]
Json(#[from] serde_json::Error),
}
impl From<CacheRootError> for NnsCommandError {
fn from(error: CacheRootError) -> Self {
Self::Usage(error.to_string())
}
}
impl From<SubnetCatalogHostError> for NnsCommandError {
fn from(source: SubnetCatalogHostError) -> Self {
Self::SubnetHost(Box::new(source))
}
}
pub async fn run_matches(matches: &ArgMatches, network: &str) -> Result<(), NnsCommandError> {
match matches.subcommand() {
Some(("subnet", matches)) => subnet::run(matches, network).await,
Some(("data-center", matches)) => data_center::run(matches, network).await,
Some(("governance", matches)) => governance::run(matches, network).await,
Some(("node", matches)) => node::run(matches, network).await,
Some(("neuron", matches)) => neuron::run(matches, network).await,
Some(("node-provider", matches)) => node_provider::run(matches, network).await,
Some(("node-operator", matches)) => node_operator::run(matches, network).await,
Some(("proposal", matches)) => proposals::run(matches, network).await,
Some(("registry", matches)) => registry::run(matches, network).await,
Some(("topology", matches)) => topology::run(matches, network).await,
_ => unreachable!("clap requires a known NNS subcommand"),
}
}
pub fn command() -> ClapCommand {
ClapCommand::new("nns")
.about("Inspect NNS metadata")
.subcommand(subnet::subnet_command())
.subcommand(data_center::command())
.subcommand(governance::governance_command())
.subcommand(node::node_command())
.subcommand(neuron::neuron_command())
.subcommand(node_provider::command())
.subcommand(node_operator::command())
.subcommand(proposals::nns_proposal_command())
.subcommand(registry::registry_command())
.subcommand(topology::topology_command())
}