oauth-db-cli 0.1.0

Command-line tool for managing OAuth-DB platform
Documentation
use clap::{Parser, Subcommand};

#[derive(Debug, Parser)]
#[command(name = "oauth-db")]
#[command(about = "OAuth-DB CLI - Manage your OAuth-DB platform", long_about = None)]
#[command(version)]
pub struct Cli {
    /// Server URL (overrides config)
    #[arg(short, long, global = true)]
    pub server: Option<String>,

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

    /// Disable colored output
    #[arg(long, global = true)]
    pub no_color: bool,

    /// Verbose output
    #[arg(short, long, global = true)]
    pub verbose: bool,

    /// Quiet mode
    #[arg(short, long, global = true)]
    pub quiet: bool,

    #[command(subcommand)]
    pub command: Commands,
}

#[derive(Debug, Subcommand)]
pub enum Commands {
    /// Login to the platform
    Login(LoginArgs),

    /// Logout from the current account
    Logout,

    /// Show current user information
    Whoami,

    /// Manage accounts
    Accounts {
        #[command(subcommand)]
        command: AccountsCommands,
    },

    /// Manage applications
    App {
        #[command(subcommand)]
        command: AppCommands,
    },

    /// Manage application users
    User {
        #[command(subcommand)]
        command: UserCommands,
    },

    /// Platform administration (admin only)
    Admin {
        #[command(subcommand)]
        command: AdminCommands,
    },

    /// Manage CLI configuration
    Config {
        #[command(subcommand)]
        command: ConfigCommands,
    },
}

#[derive(Debug, Clone, Parser)]
pub struct LoginArgs {
    /// Server URL
    #[arg(short, long)]
    pub server: Option<String>,

    /// Username
    #[arg(short, long)]
    pub username: Option<String>,

    /// Password (will prompt if not provided)
    #[arg(short, long)]
    pub password: Option<String>,
}

#[derive(Debug, Clone, Subcommand)]
pub enum AccountsCommands {
    /// List all saved accounts
    List,

    /// Switch to a different account
    Switch {
        /// Account name to switch to
        name: String,
    },

    /// Remove an account
    Remove {
        /// Account name to remove
        name: String,
    },
}

#[derive(Debug, Clone, Subcommand)]
pub enum AppCommands {
    /// Create a new application
    Create {
        /// Application name
        name: String,
        #[arg(long, default_value = "main")]
        default_db: String,
        #[arg(long, default_value = "main")]
        allowed_dbs: String,
        #[arg(long, default_value = "1000")]
        max_users: u32,
        #[arg(long, default_value = "100")]
        storage_quota: u32,
        #[arg(long, default_value = "10")]
        max_connections: u32,
        #[arg(long, default_value = "100")]
        qps_limit: u32,
    },
    /// List applications
    List {
        #[arg(long)]
        status: Option<String>,
        #[arg(long, default_value = "1")]
        page: u32,
        #[arg(long, default_value = "20")]
        page_size: u32,
    },
    /// Show application details
    Show { app_id: String },
    /// Update application settings
    Update {
        app_id: String,
        #[arg(long)]
        name: Option<String>,
        #[arg(long)]
        default_db: Option<String>,
        #[arg(long)]
        allowed_dbs: Option<String>,
        #[arg(long)]
        max_users: Option<u32>,
        #[arg(long)]
        storage_quota: Option<u32>,
        #[arg(long)]
        max_connections: Option<u32>,
        #[arg(long)]
        qps_limit: Option<u32>,
    },
    /// Enable an application
    Enable { app_id: String },
    /// Disable an application
    Disable { app_id: String },
    /// Delete an application
    Delete {
        app_id: String,
        #[arg(long)]
        force: bool,
    },
    /// Reset application token
    ResetToken { app_id: String },
    /// Show application statistics
    Stats { app_id: String },
}

#[derive(Debug, Clone, Subcommand)]
pub enum UserCommands {
    /// Create a new application user
    Create {
        /// Application ID
        app_id: String,
        /// Custom token (optional)
        #[arg(long)]
        token: Option<String>,
        /// Label for the user
        #[arg(long)]
        label: Option<String>,
        /// Storage quota (MB)
        #[arg(long)]
        storage_quota: Option<u32>,
        /// Max connections
        #[arg(long)]
        max_connections: Option<u32>,
        /// QPS limit
        #[arg(long)]
        qps_limit: Option<u32>,
    },
    /// List application users
    List {
        /// Application ID
        app_id: String,
        /// Filter by status
        #[arg(long)]
        status: Option<String>,
        /// Page number
        #[arg(long, default_value = "1")]
        page: u32,
        /// Page size
        #[arg(long, default_value = "20")]
        page_size: u32,
    },
    /// Show user details
    Show {
        /// Application ID
        app_id: String,
        /// User UID
        user_uid: String,
    },
    /// Update user
    Update {
        /// Application ID
        app_id: String,
        /// User UID
        user_uid: String,
        /// New label
        #[arg(long)]
        label: Option<String>,
        /// Storage quota (MB, use 'null' to inherit)
        #[arg(long)]
        storage_quota: Option<String>,
        /// Max connections (use 'null' to inherit)
        #[arg(long)]
        max_connections: Option<String>,
        /// QPS limit (use 'null' to inherit)
        #[arg(long)]
        qps_limit: Option<String>,
    },
    /// Enable user
    Enable {
        /// Application ID
        app_id: String,
        /// User UID
        user_uid: String,
    },
    /// Disable user
    Disable {
        /// Application ID
        app_id: String,
        /// User UID
        user_uid: String,
    },
    /// Delete user
    Delete {
        /// Application ID
        app_id: String,
        /// User UID
        user_uid: String,
        /// Skip confirmation
        #[arg(long)]
        force: bool,
    },
    /// Reset user token
    ResetToken {
        /// Application ID
        app_id: String,
        /// User UID
        user_uid: String,
    },
    /// Show user statistics
    Stats {
        /// Application ID
        app_id: String,
        /// User UID
        user_uid: String,
    },
}

#[derive(Debug, Clone, Subcommand)]
pub enum AdminCommands {
    /// Manage platform users
    Users {
        #[command(subcommand)]
        command: AdminUsersCommands,
    },
    /// Show system statistics
    Stats,
}

#[derive(Debug, Clone, Subcommand)]
pub enum AdminUsersCommands {
    List {
        #[arg(long)]
        role: Option<String>,
        #[arg(long)]
        status: Option<String>,
        #[arg(long, default_value = "1")]
        page: u32,
        #[arg(long, default_value = "20")]
        page_size: u32,
    },
    Show { user_id: String },
    Create {
        #[arg(long)]
        username: String,
        #[arg(long)]
        email: String,
        #[arg(long, default_value = "user")]
        role: String,
        #[arg(long)]
        password: Option<String>,
    },
    Enable { user_id: String },
    Disable { user_id: String },
    SetRole {
        user_id: String,
        #[arg(long)]
        role: String,
    },
}

#[derive(Debug, Clone, Subcommand)]
pub enum ConfigCommands {
    Set { key: String, value: String },
    Get { key: String },
    List,
    Reset,
}