zilliz 0.1.1

TUI and CLI tool for managing Zilliz Cloud clusters and Milvus operations
Documentation
use clap::{Parser, Subcommand};

#[derive(Parser)]
#[command(
    name = "zilliz",
    about = "CLI and TUI for Zilliz Cloud",
    version,
    disable_help_flag = true,
    disable_help_subcommand = true
)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Option<Commands>,

    /// Print help
    #[arg(long, short, global = true, action = clap::ArgAction::SetTrue)]
    pub help: bool,

    /// API key (overrides env var and config file)
    #[arg(long, global = true, env = "ZILLIZ_API_KEY")]
    pub api_key: Option<String>,

    /// Output format: json, table, text, yaml, csv
    #[arg(long, short, global = true, default_value = "table")]
    pub output: Option<String>,

    /// Fetch all pages for paginated list operations
    #[arg(long, short, global = true)]
    pub all: bool,

    /// JMESPath query to filter output
    #[arg(long, global = true)]
    pub query: Option<String>,

    /// Suppress table/CSV header row
    #[arg(long, global = true)]
    pub no_header: bool,

    /// Wait for async jobs to complete (polls until terminal state)
    #[arg(long, global = true)]
    pub wait: bool,
}

#[derive(Subcommand)]
pub enum Commands {
    /// Configure API key and default settings
    #[command(hide = true)]
    Configure {
        #[command(subcommand)]
        subcmd: Option<ConfigureCommands>,
    },

    /// Manage current cluster context
    #[command(subcommand, hide = true)]
    Context(ContextCommands),

    /// Show CLI version
    #[command(hide = true)]
    Version,

    /// Log in to Zilliz Cloud
    #[command(hide = true)]
    Login {
        /// Don't automatically open the browser
        #[arg(long)]
        no_browser: bool,
        /// Login with API key instead of browser
        #[arg(long = "with-api-key")]
        with_api_key: bool,
    },

    /// Log out from Zilliz Cloud and clear stored credentials
    #[command(hide = true)]
    Logout,

    /// Authentication commands
    #[command(subcommand, hide = true)]
    Auth(AuthCommands),

    /// Shell completion management
    #[command(subcommand, hide = true)]
    Completion(CompletionCommands),

    /// Manage alert rules
    #[command(hide = true)]
    Alert {
        #[command(subcommand)]
        subcmd: Option<AlertCommands>,
    },

    /// Run a resource operation: zilliz <resource> <operation> [--flag value ...]
    #[command(external_subcommand)]
    External(Vec<String>),
}

#[derive(Subcommand)]
pub enum AlertCommands {
    /// List alert rules
    List {
        /// Project ID (required)
        #[arg(long)]
        project_id: String,
        /// Items per page
        #[arg(long)]
        page_size: Option<i64>,
        /// Page number
        #[arg(long)]
        page: Option<i64>,
    },
    /// Create a new alert rule
    Create {
        /// Project ID
        #[arg(long)]
        project_id: String,
        /// Metric name (e.g. CU_COMPUTATION, REQ_SEARCH_COUNT)
        #[arg(long)]
        metric_name: String,
        /// Threshold value
        #[arg(long)]
        threshold: String,
        /// Comparison operator: >, <, >=, <=, =, gt, lt, gte, lte, eq
        #[arg(long)]
        comparison: String,
        /// Rule name (defaults to "<METRIC> alert")
        #[arg(long)]
        rule_name: Option<String>,
        /// Alert level: WARNING or CRITICAL
        #[arg(long, default_value = "WARNING")]
        level: String,
        /// Time window (e.g. 5m, 1h)
        #[arg(long)]
        window_size: Option<String>,
        /// Target cluster IDs (can be specified multiple times)
        #[arg(long)]
        cluster_id: Vec<String>,
        /// Actions in type:config format (e.g. email:user@example.com). Can be repeated.
        #[arg(long)]
        action: Vec<String>,
        /// Send notification when alert is resolved
        #[arg(long)]
        send_resolved: Option<bool>,
        /// Repeat interval in seconds
        #[arg(long)]
        repeat_interval: Option<i64>,
        /// Whether the rule is enabled
        #[arg(long)]
        enabled: Option<bool>,
    },
    /// Update an existing alert rule
    Update {
        /// Alert rule ID
        #[arg(long)]
        id: String,
        /// Rule name
        #[arg(long)]
        rule_name: Option<String>,
        /// Metric name
        #[arg(long)]
        metric_name: Option<String>,
        /// Threshold value
        #[arg(long)]
        threshold: Option<String>,
        /// Comparison operator
        #[arg(long)]
        comparison: Option<String>,
        /// Alert level
        #[arg(long)]
        level: Option<String>,
        /// Time window
        #[arg(long)]
        window_size: Option<String>,
        /// Target cluster IDs (replaces existing)
        #[arg(long)]
        cluster_id: Vec<String>,
        /// Actions (replaces existing)
        #[arg(long)]
        action: Vec<String>,
        /// Send notification when resolved
        #[arg(long)]
        send_resolved: Option<bool>,
        /// Repeat interval in seconds
        #[arg(long)]
        repeat_interval: Option<i64>,
        /// Whether the rule is enabled
        #[arg(long)]
        enabled: Option<bool>,
    },
    /// Delete an alert rule
    Delete {
        /// Alert rule ID
        #[arg(long)]
        id: String,
        /// Skip confirmation prompt
        #[arg(long, short)]
        yes: bool,
    },
    /// Enable an alert rule
    Enable {
        /// Alert rule ID
        #[arg(long)]
        id: String,
    },
    /// Disable an alert rule
    Disable {
        /// Alert rule ID
        #[arg(long)]
        id: String,
    },
}

#[derive(Subcommand)]
pub enum ContextCommands {
    /// Set the current cluster context
    Set {
        /// Cluster ID
        #[arg(long)]
        cluster_id: Option<String>,
        /// Cluster endpoint URL (auto-resolved from cluster-id if omitted)
        #[arg(long)]
        endpoint: Option<String>,
        /// Database name
        #[arg(long)]
        database: Option<String>,
    },
    /// Show the current context
    Current {
        /// Output format: json, table, text
        #[arg(long, short)]
        output: Option<String>,
    },
    /// Clear the current context
    Clear,
}

#[derive(Subcommand)]
pub enum ConfigureCommands {
    /// Set a configuration value
    Set {
        /// Configuration key (e.g. api_key, base_url)
        key: String,
        /// Value to set (omit for credential keys to enter securely via prompt)
        value: Option<String>,
    },
    /// Get a configuration value
    Get {
        /// Configuration key
        key: String,
    },
    /// List all configuration values
    List,
    /// Clear all stored credentials
    Clear,
}

#[derive(Subcommand)]
pub enum AuthCommands {
    /// Show current authentication status
    Status,
    /// Switch to a different organization
    Switch {
        /// Organization ID (interactive selection if omitted)
        org_id: Option<String>,
    },
}

#[derive(Subcommand)]
pub enum CompletionCommands {
    /// Install shell completion to RC file
    Install {
        /// Shell type (auto-detected if omitted)
        #[arg(value_enum)]
        shell: Option<clap_complete::Shell>,
        /// Automatically write to shell RC file
        #[arg(long)]
        apply: bool,
    },
    /// Remove shell completion from RC file
    Uninstall {
        /// Shell type (auto-detected if omitted)
        #[arg(value_enum)]
        shell: Option<clap_complete::Shell>,
    },
    /// Check if shell completion is installed
    Status {
        /// Shell type (auto-detected if omitted)
        #[arg(value_enum)]
        shell: Option<clap_complete::Shell>,
    },
    /// Print completion script to stdout
    Show {
        /// Shell type
        #[arg(value_enum)]
        shell: clap_complete::Shell,
    },
}