ic-query-cli 0.103.0

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
//! Clap command definitions for explicitly targeted SNS neuron reads and caches.

use super::options::{SnsCacheStatusOptions, SnsListOptions, SnsNeuronOptions, SnsRefreshOptions};
use crate::cli::common::{
    COLLECTION_MODE_CACHE_ONLY, COLLECTION_MODE_FORCE_REFRESH, COLLECTION_MODE_LIVE,
    COLLECTION_MODE_LIVE_OR_CACHE_BY_VIEW, collection_help,
};
use clap::{Command as ClapCommand, Subcommand};
use ic_query::sns::DEFAULT_SNS_SOURCE_ENDPOINT;

const SNS_NEURONS_HELP_AFTER: &str = "\
Examples:
  icq sns neuron list <governance-canister-id>
  icq sns neuron list <governance-canister-id> --limit 10
  icq sns neuron list <governance-canister-id> --owner zqfso-syaaa-aaaaq-aaafq-cai
  icq sns neuron list <governance-canister-id> --verbose
  icq sns neuron refresh <governance-canister-id>
  icq sns neuron cache list
  icq sns neuron cache status <governance-canister-id>
  icq sns neuron list <governance-canister-id> --limit 500 --sort stake
  icq --network ic sns neuron list <governance-canister-id> --json";

const SNS_NEURON_INFO_HELP_AFTER: &str = "\
Examples:
  icq sns neuron info <governance-canister-id> 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
  icq --network ic sns neuron info <governance-canister-id> 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f --json";

const SNS_NEURONS_CACHE_HELP_AFTER: &str = "\
Examples:
  icq sns neuron cache list
  icq sns neuron cache status <governance-canister-id>
  icq sns neuron cache status <governance-canister-id>
  icq sns neuron cache status <governance-canister-id> --json";

const SNS_NEURONS_CACHE_LIST_HELP_AFTER: &str = "\
Examples:
  icq sns neuron cache list
  icq sns neuron cache list --json";

const SNS_NEURONS_CACHE_STATUS_HELP_AFTER: &str = "\
Examples:
  icq sns neuron cache status <governance-canister-id>
  icq sns neuron cache status <governance-canister-id>
  icq sns neuron cache status <governance-canister-id> --json";

const SNS_NEURONS_REFRESH_HELP_AFTER: &str = "\
Examples:
  icq sns neuron refresh <governance-canister-id>
  icq sns neuron refresh <governance-canister-id>
  icq sns neuron refresh <governance-canister-id> --page-size 100
  icq --network ic sns neuron refresh <governance-canister-id> --json";

pub(super) fn sns_command() -> ClapCommand {
    SnsCommand::augment_subcommands(ClapCommand::new("sns"))
}

///
/// SnsCommand
///
/// Typed SNS command namespace.
///

#[derive(Subcommand)]
#[command(about = "Inspect neuron ownership and stake", long_about = None)]
pub(super) enum SnsCommand {
    #[command(subcommand)]
    Neuron(NeuronCommand),
}

///
/// NeuronCommand
///
/// Explicit neuron reads, refreshes and local cache inspection.
///

#[derive(Subcommand)]
#[command(about = "List, inspect, and refresh SNS governance neurons", long_about = None)]
pub(super) enum NeuronCommand {
    #[command(about = "Show one neuron stake and permissions by exact 32-byte id", long_about = None, after_help = collection_help(COLLECTION_MODE_LIVE, SNS_NEURON_INFO_HELP_AFTER), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_SNS_SOURCE_ENDPOINT).help("IC API endpoint used for Governance queries")))]
    Info(SnsNeuronOptions),
    #[command(about = "List SNS governance neurons by Governance canister principal", long_about = None, after_help = collection_help(COLLECTION_MODE_LIVE_OR_CACHE_BY_VIEW, SNS_NEURONS_HELP_AFTER), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_SNS_SOURCE_ENDPOINT).help("IC API endpoint used for Governance neuron queries")))]
    List(SnsListOptions),
    #[command(about = "Force-refresh and cache a complete SNS governance neuron snapshot", long_about = None, after_help = collection_help(COLLECTION_MODE_FORCE_REFRESH, SNS_NEURONS_REFRESH_HELP_AFTER), mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_SNS_SOURCE_ENDPOINT).help("IC API endpoint used for Governance neuron queries")))]
    Refresh(SnsRefreshOptions),
    #[command(subcommand)]
    Cache(CacheCommand),
}

///
/// CacheCommand
///
/// Local neuron snapshot inspection.
///

#[derive(Subcommand)]
#[command(about = "Inspect local complete SNS governance neuron snapshots", long_about = None, after_help = collection_help(COLLECTION_MODE_CACHE_ONLY, SNS_NEURONS_CACHE_HELP_AFTER))]
pub(super) enum CacheCommand {
    #[command(about = "List local complete SNS neuron snapshots", long_about = None, after_help = collection_help(COLLECTION_MODE_CACHE_ONLY, SNS_NEURONS_CACHE_LIST_HELP_AFTER))]
    List {
        #[arg(long, help = "Print raw JSON instead of human-readable text")]
        json: bool,
    },
    #[command(about = "Show local SNS neuron snapshot and refresh-attempt status", long_about = None, after_help = collection_help(COLLECTION_MODE_CACHE_ONLY, SNS_NEURONS_CACHE_STATUS_HELP_AFTER))]
    Status(SnsCacheStatusOptions),
}