use crate::cli::common::{
COLLECTION_MODE_CACHE_ONLY, COLLECTION_MODE_CACHE_PREFERRED_LIVE_FALLBACK,
COLLECTION_MODE_FORCE_REFRESH, collection_help,
};
use clap::{Command as ClapCommand, Subcommand, builder::RangedU64ValueParser};
use ic_query::nns::neuron::DEFAULT_NNS_NEURON_SOURCE_ENDPOINT;
use ic_query::nns::neuron::NNS_NEURON_MAX_PAGE_SIZE;
const LIST_DEFAULT_LIMIT: &str = "25";
const REFRESH_DEFAULT_PAGE_SIZE: &str = "300";
const NEURON_HELP_AFTER: &str = "\
Examples:
icq nns neuron distribution
icq nns neuron distribution --json
icq nns neuron list
icq nns neuron info 123456789
icq nns neuron refresh
icq nns neuron cache status";
const LIST_HELP_AFTER: &str = "\
Examples:
icq nns neuron list
icq nns neuron list --limit 100 --start-neuron-id 123456789
icq nns neuron list --verbose
icq nns neuron list --json";
const INFO_HELP_AFTER: &str = "\
Examples:
icq nns neuron info 123456789
icq nns neuron info 123456789 --verbose
icq nns neuron info 123456789 --json";
const REFRESH_HELP_AFTER: &str = "\
Examples:
icq nns neuron refresh
icq nns neuron refresh --page-size 300
icq nns neuron refresh --max-pages 5
icq nns neuron refresh --json";
const CACHE_HELP_AFTER: &str = "\
Examples:
icq nns neuron cache status
icq nns neuron cache status --json";
#[derive(clap::Args)]
#[group(skip)]
pub(in crate::nns) struct NeuronListOptions {
#[command(flatten)]
pub(in crate::nns) source: crate::cli::common::SourceOutputOptions,
#[arg(long, value_name = "count", default_value = LIST_DEFAULT_LIMIT, value_parser = RangedU64ValueParser::<u32>::new() .range(1..=u64::from(NNS_NEURON_MAX_PAGE_SIZE)), help = "Maximum public neurons to return")]
pub(in crate::nns) limit: u32,
#[arg(id = "start-neuron-id", long, value_name = "neuron-id", value_parser = RangedU64ValueParser::<u64>::new().range(1..), help = "Return neurons with ids greater than this exclusive cursor")]
pub(in crate::nns) start_neuron_id: Option<u64>,
#[arg(long, help = "Show expanded public neuron details in text output")]
pub(in crate::nns) verbose: bool,
}
#[derive(clap::Args)]
#[group(skip)]
pub(in crate::nns) struct NeuronInfoOptions {
#[arg(id = "neuron-id", value_name = "neuron-id", value_parser = RangedU64ValueParser::<u64>::new().range(1..), help = "NNS Governance neuron id")]
pub(in crate::nns) neuron_id: u64,
#[command(flatten)]
pub(in crate::nns) source: crate::cli::common::SourceOutputOptions,
#[arg(long, help = "Show expanded public neuron details in text output")]
pub(in crate::nns) verbose: bool,
}
#[derive(Subcommand)]
#[command(about = "Inspect public NNS Governance neuron views", long_about = None, after_help = NEURON_HELP_AFTER)]
pub(in crate::nns) enum NeuronCommand {
#[command(about = "Summarize public-neuron distribution from the complete local snapshot", long_about = None, after_help = collection_help(COLLECTION_MODE_CACHE_ONLY, "Examples:\n icq nns neuron distribution\n icq nns neuron distribution --json"))]
Distribution(crate::nns::collection::JsonOptions),
#[command(about = "List public NNS neurons", long_about = None, after_help = collection_help(COLLECTION_MODE_CACHE_PREFERRED_LIVE_FALLBACK, LIST_HELP_AFTER))]
List(NeuronListOptions),
#[command(about = "Show one public NNS neuron", long_about = None, after_help = collection_help(COLLECTION_MODE_CACHE_PREFERRED_LIVE_FALLBACK, INFO_HELP_AFTER))]
Info(NeuronInfoOptions),
#[command(about = "Refresh the complete public NNS neuron snapshot", long_about = None, after_help = collection_help(COLLECTION_MODE_FORCE_REFRESH, REFRESH_HELP_AFTER))]
Refresh(crate::nns::leaf::NnsPagedRefreshOptions),
#[command(subcommand, about = "Inspect the local complete public NNS neuron snapshot", long_about = None, after_help = collection_help(COLLECTION_MODE_CACHE_ONLY, CACHE_HELP_AFTER))]
Cache(NeuronCacheCommand),
}
#[derive(Subcommand)]
pub(in crate::nns) enum NeuronCacheCommand {
#[command(about = "Show public NNS neuron snapshot and refresh-attempt status", long_about = None, after_help = collection_help(COLLECTION_MODE_CACHE_ONLY, CACHE_HELP_AFTER))]
Status(crate::nns::collection::JsonOptions),
}
pub(in crate::nns) fn neuron_command() -> ClapCommand {
NeuronCommand::augment_subcommands(ClapCommand::new("neuron"))
.mut_subcommands(|command| {
if matches!(command.get_name(), "list" | "info" | "refresh") {
command.mut_arg("source-endpoint", |arg| {
arg.default_value(DEFAULT_NNS_NEURON_SOURCE_ENDPOINT)
.help("IC API endpoint used for the native NNS Governance query")
})
} else {
command
}
})
.mut_subcommand("refresh", |command| {
command
.mut_arg("source-endpoint", |arg| {
arg.help("IC API endpoint used for every native NNS Governance page")
})
.mut_arg("page-size", |arg| {
arg.default_value(REFRESH_DEFAULT_PAGE_SIZE)
.value_parser(
RangedU64ValueParser::<u32>::new()
.range(1..=u64::from(NNS_NEURON_MAX_PAGE_SIZE)),
)
.help("Maximum public neurons requested per Governance page")
})
.mut_arg("max-pages", |arg| {
arg.help("Stop without publishing if this cap precedes API exhaustion")
})
})
}