codex-switch 0.1.14

Local CLI account switcher for Codex
use std::path::PathBuf;

use clap::{Parser, Subcommand};

#[derive(Debug, Parser)]
#[command(name = "codex-switch")]
#[command(about = "Local Codex account switcher")]
#[command(version)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Command,
}

#[derive(Debug, Subcommand)]
pub enum Command {
    /// List stored accounts.
    List,
    /// Log in with ChatGPT/OpenAI OAuth and save the account.
    Login {
        /// Account display name.
        name: String,
        /// Replace an existing ChatGPT OAuth account with the same name after login succeeds.
        #[arg(long)]
        replace: bool,
        /// Use device authorization instead of browser OAuth.
        #[arg(long = "device-auth")]
        device_auth: bool,
    },
    /// Import an existing Codex CLI auth.json.
    Import {
        /// Account display name.
        name: String,
        /// Path to auth.json. Defaults to the current Codex auth.json.
        #[arg(long)]
        file: Option<PathBuf>,
    },
    /// Export a stored account as Codex CLI auth.json.
    Export {
        /// Account name, full ID, or unique ID prefix.
        account: String,
        /// Write auth.json to this file instead of stdout.
        #[arg(long)]
        file: Option<PathBuf>,
        /// Overwrite the output file if it already exists.
        #[arg(long, requires = "file")]
        force: bool,
    },
    /// Switch Codex to a stored account.
    Switch {
        /// Account name, full ID, or unique ID prefix.
        account: String,
    },
    /// Switch to a usable account when the current Codex auth account is out of usage.
    AutoSwitch,
    /// Run Codex with runtime account auto-switching.
    Run {
        /// Codex executable to launch.
        #[arg(long, default_value = "codex")]
        codex_bin: String,
        /// Arguments forwarded to `codex`.
        #[arg(value_name = "CODEX_ARGS", num_args = 0.., trailing_var_arg = true, allow_hyphen_values = true)]
        codex_args: Vec<String>,
    },
    /// Update codex-switch from GitHub Releases.
    Update {
        /// Only check whether an update is available.
        #[arg(long)]
        check: bool,
        /// Install a specific release version, such as 0.1.10 or v0.1.10.
        #[arg(long)]
        version: Option<String>,
    },
    /// Show usage for one account, the current Codex auth account, or all accounts.
    Usage {
        /// Query every stored account.
        #[arg(long, conflicts_with = "account")]
        all: bool,
        /// Account name, full ID, or unique ID prefix. Defaults to the current Codex auth account.
        account: Option<String>,
    },
    /// Delete a stored account.
    Delete {
        /// Account name, full ID, or unique ID prefix.
        account: String,
    },
    /// Rename a stored account.
    Rename {
        /// Account name, full ID, or unique ID prefix.
        account: String,
        /// New account display name.
        new_name: String,
    },
}