use crate::cli::common::{
COLLECTION_MODE_CACHE_REFRESH_MISSING, COLLECTION_MODE_FORCE_REFRESH, SourceOutputOptions,
collection_help,
};
use clap::Subcommand;
use ic_query::nns::topology::DEFAULT_NNS_TOPOLOGY_SOURCE_ENDPOINT;
const TOPOLOGY_COMPONENT_CACHE_SOURCE_HELP: &str =
"IC API endpoint used if a topology component cache is missing";
const TOPOLOGY_OPERATOR_CACHE_SOURCE_HELP: &str =
"IC API endpoint used if the node-operator cache is missing";
const TOPOLOGY_DATA_CENTER_CACHE_SOURCE_HELP: &str =
"IC API endpoint used if the data-center cache is missing";
const TOPOLOGY_REFRESH_HELP_AFTER: &str = "\
Examples:
icq nns topology refresh
icq nns topology refresh --dry-run
icq --network ic nns topology refresh --json
icq nns topology refresh --source-endpoint https://icp-api.io";
const TOPOLOGY_REFRESH_SOURCE_HELP: &str =
"IC API endpoint used for NNS topology component refreshes";
#[derive(clap::Args)]
#[group(skip)]
pub(in crate::nns) struct TopologyRefreshOptions {
#[command(flatten)]
pub(in crate::nns) source: crate::cli::common::SourceOutputOptions,
#[arg(
id = "dry-run",
long = "dry-run",
help = "Fetch and validate without replacing topology component caches"
)]
pub(in crate::nns) dry_run: bool,
}
#[derive(Subcommand)]
#[command(about = "Inspect joined NNS topology metadata", long_about = None)]
pub(in crate::nns::topology) enum TopologyCommand {
#[command(about = "Summarize cached mainnet NNS topology reports", long_about = None, after_help = read_help("summary"), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_NNS_TOPOLOGY_SOURCE_ENDPOINT).help(TOPOLOGY_COMPONENT_CACHE_SOURCE_HELP)))]
Summary(SourceOutputOptions),
#[command(about = "Show cached mainnet NNS topology join coverage", long_about = None, after_help = read_help("coverage"), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_NNS_TOPOLOGY_SOURCE_ENDPOINT).help(TOPOLOGY_COMPONENT_CACHE_SOURCE_HELP)))]
Coverage(SourceOutputOptions),
#[command(about = "Show cached mainnet NNS topology component registry versions", long_about = None, after_help = read_help("versions"), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_NNS_TOPOLOGY_SOURCE_ENDPOINT).help(TOPOLOGY_COMPONENT_CACHE_SOURCE_HELP)))]
Versions(SourceOutputOptions),
#[command(about = "Check cached mainnet NNS topology consistency", long_about = None, after_help = read_help("check"), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_NNS_TOPOLOGY_SOURCE_ENDPOINT).help(TOPOLOGY_COMPONENT_CACHE_SOURCE_HELP)))]
Check(SourceOutputOptions),
#[command(about = "List cached mainnet NNS topology join gaps", long_about = None, after_help = read_help("gaps"), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_NNS_TOPOLOGY_SOURCE_ENDPOINT).help(TOPOLOGY_COMPONENT_CACHE_SOURCE_HELP)))]
Gaps(SourceOutputOptions),
#[command(about = "Show cached mainnet NNS node-operator capacity", long_about = None, after_help = read_help("capacity"), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_NNS_TOPOLOGY_SOURCE_ENDPOINT).help(TOPOLOGY_OPERATOR_CACHE_SOURCE_HELP)))]
Capacity(SourceOutputOptions),
#[command(about = "Summarize cached mainnet NNS topology by region", long_about = None, after_help = read_help("regions"), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_NNS_TOPOLOGY_SOURCE_ENDPOINT).help(TOPOLOGY_DATA_CENTER_CACHE_SOURCE_HELP)))]
Regions(SourceOutputOptions),
#[command(about = "Summarize cached mainnet NNS topology by node provider", long_about = None, after_help = read_help("providers"), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_NNS_TOPOLOGY_SOURCE_ENDPOINT).help(TOPOLOGY_COMPONENT_CACHE_SOURCE_HELP)))]
Providers(SourceOutputOptions),
#[command(about = "Refresh cached mainnet NNS topology component reports", long_about = None, after_help = collection_help(COLLECTION_MODE_FORCE_REFRESH, TOPOLOGY_REFRESH_HELP_AFTER), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_NNS_TOPOLOGY_SOURCE_ENDPOINT).help(TOPOLOGY_REFRESH_SOURCE_HELP)))]
Refresh(TopologyRefreshOptions),
}
pub(in crate::nns) fn topology_command() -> clap::Command {
TopologyCommand::augment_subcommands(clap::Command::new("topology"))
}
fn read_help(name: &str) -> String {
collection_help(
COLLECTION_MODE_CACHE_REFRESH_MISSING,
&format!(
"Examples:\n icq nns topology {name}\n icq --network ic nns topology {name} --json\n icq nns topology {name} --source-endpoint https://icp-api.io"
),
)
}