use std::path::PathBuf; use clap::{Args, Parser, Subcommand}; #[derive(Parser)] #[command(name = "cdxs", version, about = "Codex Switch CLI")] pub struct Cli { #[command(subcommand)] pub command: Option, } #[derive(Subcommand)] pub enum Commands { /// Login to Codex through OpenAI OAuth. Login(LoginArgs), /// Import an existing Codex auth file. Import(ImportArgs), /// List saved accounts. List { #[arg(long)] json: bool, #[arg(short, long)] force: bool, }, /// Switch Codex auth.json to a saved account. Switch { #[arg( value_name = "ACCOUNT_ID_OR_EMAIL", help = "Account id, exact email, or email prefix" )] account: Option, #[arg(short, long, conflicts_with = "account")] auto: bool, #[arg(long)] codex_home: Option, #[arg(long)] apply_fingerprint: bool, }, /// Prepare auth, set CODEX_HOME, and execute a command. Run(RunArgs), /// Refresh and display Codex quota. Quota { #[arg(value_name = "ACCOUNT_ID_OR_EMAIL")] accounts: Vec, #[arg(long)] json: bool, }, /// Account management commands. Account { #[command(subcommand)] command: AccountCommands, }, /// Managed CODEX_HOME commands. Home { #[command(subcommand)] command: HomeCommands, }, /// Run or manage the cdxs sync server. Server { #[command(subcommand)] command: ServerCommands, }, /// Sync local cdxs.toml with a server. Sync { #[command(subcommand)] command: SyncCommands, }, /// Inspect and manage Codex sessions. Session { #[command(subcommand)] command: SessionCommands, }, } #[derive(Args)] pub struct LoginArgs { /// Start OpenAI OAuth login for Codex. #[command(subcommand)] pub command: Option, #[arg(long)] pub manual: bool, #[arg(long, default_value_t = 1455)] pub port: u16, #[arg(long)] pub switch: bool, } #[derive(Args)] pub struct ImportArgs { /// Import OAuth/API-key auth from auth.json. #[command(subcommand)] pub command: Option, #[arg(long)] pub file: Option, #[arg(long)] pub codex_home: Option, #[arg(long)] pub switch: bool, } #[derive(Subcommand)] pub enum LoginCommands { /// Start OpenAI OAuth login for Codex. Oauth { #[arg(long)] manual: bool, #[arg(long, default_value_t = 1455)] port: u16, #[arg(long)] switch: bool, }, } #[derive(Subcommand)] pub enum ImportCommands { /// Import OAuth/API-key auth from auth.json. Auth { #[arg(long)] file: Option, #[arg(long)] codex_home: Option, #[arg(long)] switch: bool, }, } #[derive(Subcommand)] pub enum AccountCommands { List { #[arg(long)] json: bool, #[arg(short, long)] force: bool, }, Current { #[arg(long)] json: bool, }, Show { account: String, #[arg(long)] json: bool, }, Remove { account: String, }, AddApiKey { #[arg(long)] key: String, #[arg(long)] base_url: Option, #[arg(long)] switch: bool, }, } #[derive(Subcommand)] pub enum HomeCommands { List { #[arg(long)] json: bool, }, Create { name: String, #[arg(long)] path: PathBuf, #[arg(long)] account: Option, }, Bind { name: String, account: String, }, Path { name: String, }, Remove { name: String, }, } #[derive(Subcommand)] pub enum ServerCommands { Run { #[arg(long, default_value = "127.0.0.1:8765")] bind: String, #[arg(long)] data: Option, }, User { #[command(subcommand)] command: ServerUserCommands, }, } #[derive(Subcommand)] pub enum ServerUserCommands { Add { username: String, #[arg(long)] password: String, #[arg(long)] data: Option, }, } #[derive(Subcommand)] pub enum SyncCommands { Login { #[arg(long)] server: String, #[arg(long)] user: String, #[arg(long)] password: String, }, Pull, Push, Status, } #[derive(Subcommand)] pub enum SessionCommands { /// List Codex sessions from state_5.sqlite. List { #[arg(long)] all_homes: bool, #[arg(long)] json: bool, }, /// Show token and file statistics for one session. Stats { session_id: String, #[arg(long)] all_homes: bool, #[arg(long)] json: bool, }, /// Move sessions into the cdxs trash and hide them from Codex. Trash { session_ids: Vec, #[arg(long)] all_homes: bool, }, /// List sessions stored in cdxs trash. TrashList { #[arg(long)] all_homes: bool, #[arg(long)] json: bool, }, /// Restore sessions from cdxs trash. Restore { session_ids: Vec, #[arg(long)] all_homes: bool, }, /// Check or repair Codex session visibility. Visibility { #[command(subcommand)] command: SessionVisibilityCommands, }, /// Copy missing session threads across managed CODEX_HOME directories. SyncThreads { #[arg(long)] all_homes: bool, #[arg(long)] dry_run: bool, #[arg(long)] json: bool, }, } #[derive(Subcommand)] pub enum SessionVisibilityCommands { Check { #[arg(long)] all_homes: bool, #[arg(long)] json: bool, }, Repair { #[arg(long)] all_homes: bool, #[arg(long)] json: bool, }, } #[derive(Args)] pub struct RunArgs { #[arg(long, conflicts_with = "home")] pub account: Option, #[arg(long, conflicts_with = "account")] pub home: Option, #[arg(long)] pub codex_home: Option, /// Command after `--`, for example: cdxs run --account me -- codex #[arg(required = true, trailing_var_arg = true, allow_hyphen_values = true)] pub command: Vec, }