use clap::{Args, Parser, Subcommand, ValueEnum};
use std::path::PathBuf;
#[derive(Debug, Parser)]
#[command(name = "coproxy")]
#[command(version)]
#[command(about = "Serve GHCP through an OpenAI-compatible API")]
pub struct Cli {
#[arg(long, global = true)]
pub state_dir: Option<PathBuf>,
#[arg(long, global = true, env = "GHCP_GITHUB_TOKEN")]
pub github_token: Option<String>,
#[arg(long, global = true, default_value = "info")]
pub log_level: String,
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
Serve(ServeArgs),
Auth {
#[command(subcommand)]
command: AuthCommand,
},
Models {
#[arg(long)]
json: bool,
},
}
#[derive(Clone, Copy, Debug, ValueEnum)]
pub enum ApiSurface {
Chat,
ChatResponses,
ChatEmbeddings,
All,
}
impl ApiSurface {
pub fn responses_enabled(self) -> bool {
matches!(self, Self::ChatResponses | Self::All)
}
pub fn embeddings_enabled(self) -> bool {
matches!(self, Self::ChatEmbeddings | Self::All)
}
}
#[derive(Debug, Args)]
pub struct ServeArgs {
#[arg(long, default_value = "127.0.0.1")]
pub host: String,
#[arg(long, default_value_t = 8080)]
pub port: u16,
#[arg(long, value_enum, default_value_t = ApiSurface::Chat)]
pub api_surface: ApiSurface,
#[arg(long, env = "GHCP_PROXY_API_KEY")]
pub api_key: Option<String>,
#[arg(long)]
pub default_model: Option<String>,
#[arg(long)]
pub no_auto_login: bool,
#[arg(short = 'd', long, conflicts_with = "stop")]
pub daemon: bool,
#[arg(long)]
pub stop: bool,
}
#[derive(Debug, Subcommand)]
pub enum AuthCommand {
Login,
Status,
Logout,
}