mod args;
use crate::cli::common::{
COLLECTION_MODE_CACHE_REFRESH_MISSING_OR_INVALID, COLLECTION_MODE_FORCE_REFRESH,
collection_help,
};
use crate::nns::{
leaf::NnsLeafRefreshOptions,
operational_status::{self, OperationalStatusSubject, StatusOptions},
};
pub(in crate::nns) use args::{SubnetInfoOptions, SubnetListOptions};
use clap::{Command as ClapCommand, Subcommand};
use ic_query::subnet_catalog::DEFAULT_SUBNET_CATALOG_SOURCE_ENDPOINT;
const LIST_HELP_AFTER: &str = "\
Examples:
icq nns subnet list
icq nns subnet list --verbose
icq --network ic nns subnet list --json
icq nns subnet list --kind application --specialization fiduciary
Refresh stale cache:
icq nns subnet refresh";
const INFO_HELP_AFTER: &str = "\
Examples:
icq nns subnet info ryjl3-tyaaa-aaaaa-aaaba-cai
icq nns subnet info <subnet-prefix>
Refresh stale cache:
icq nns subnet refresh";
const REFRESH_HELP_AFTER: &str = "\
Examples:
icq nns subnet refresh
icq --network ic nns subnet refresh --json
icq nns subnet refresh --dry-run --output /tmp/icq-subnet-catalog.preview.json";
#[derive(Subcommand)]
#[command(about = "Inspect and refresh NNS subnet metadata", long_about = None)]
#[command(mut_subcommand("status", |command| operational_status::configure_command(command, OperationalStatusSubject::Subnet)))]
pub(in crate::nns) enum SubnetCommand {
#[command(about = "List cached mainnet IC subnets", long_about = None, after_help = collection_help(COLLECTION_MODE_CACHE_REFRESH_MISSING_OR_INVALID, LIST_HELP_AFTER))]
#[command(mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_SUBNET_CATALOG_SOURCE_ENDPOINT).help("IC API endpoint used if the subnet catalog cache is missing or invalid")))]
List(SubnetListOptions),
#[command(about = "Resolve a subnet, canister, or subnet prefix to cached subnet info", long_about = None, after_help = collection_help(COLLECTION_MODE_CACHE_REFRESH_MISSING_OR_INVALID, INFO_HELP_AFTER))]
#[command(mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_SUBNET_CATALOG_SOURCE_ENDPOINT).help("IC API endpoint used if the subnet catalog cache is missing or invalid")))]
Info(SubnetInfoOptions),
#[command(about = "Force-refresh and cache NNS subnet metadata", long_about = None, after_help = collection_help(COLLECTION_MODE_FORCE_REFRESH, REFRESH_HELP_AFTER))]
#[command(mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_SUBNET_CATALOG_SOURCE_ENDPOINT).help("IC API endpoint used for the NNS registry query")))]
#[command(mut_arg("dry-run", |arg| arg.help("Fetch and validate without replacing the cached catalog")))]
#[command(mut_arg("output", |arg| arg.help("Also write the fetched catalog JSON to this path")))]
Refresh(NnsLeafRefreshOptions),
Status(StatusOptions),
}
pub(in crate::nns) fn subnet_command() -> ClapCommand {
SubnetCommand::augment_subcommands(ClapCommand::new("subnet"))
}