use clap::Subcommand;
use super::{AuthFlow, CLAUDE_AUTH_FLOWS, CODEX_AUTH_FLOWS, auth_flow_parser};
#[derive(Clone, Copy, Debug, Eq, PartialEq, clap::ValueEnum)]
pub enum ImportProvider {
#[value(name = "claude", alias = "anthropic")]
Claude,
#[value(name = "codex", alias = "chatgpt")]
Codex,
#[value(name = "gemini", alias = "google")]
Gemini,
#[value(name = "qwen", alias = "qwen-code")]
Qwen,
#[value(name = "gh", alias = "github")]
Gh,
}
#[derive(Debug, Subcommand)]
pub enum AuthOp {
#[command(override_usage = "link-assistant-router auth import [OPTIONS] [PROVIDER] [DIR]")]
Import {
#[arg(value_enum, required_unless_present = "all")]
provider: Option<ImportProvider>,
dir: Option<String>,
#[arg(long, conflicts_with = "provider")]
all: bool,
#[command(flatten)]
target: AuthTarget,
},
Claude {
#[arg(long)]
code: Option<String>,
#[arg(long, value_parser = auth_flow_parser(&CLAUDE_AUTH_FLOWS), default_value = "auto")]
flow: AuthFlow,
#[arg(long)]
mode: Option<String>,
#[arg(long, value_name = "DIR", num_args = 0..=1, default_missing_value = "")]
from_claude_home: Option<String>,
#[arg(long, conflicts_with_all = ["code", "mode", "from_claude_home"])]
clear: bool,
#[command(flatten)]
target: AuthTarget,
},
Codex {
#[arg(long, value_parser = auth_flow_parser(&CODEX_AUTH_FLOWS), default_value = "auto")]
flow: AuthFlow,
#[arg(long, default_value_t = 1455)]
port: u16,
#[arg(long, value_name = "DIR", num_args = 0..=1, default_missing_value = "")]
from_codex_home: Option<String>,
#[arg(long, conflicts_with = "from_codex_home")]
clear: bool,
#[command(flatten)]
target: AuthTarget,
},
Gh {
#[arg(long, value_name = "DIR")]
from_gh_config: Option<String>,
#[arg(long, conflicts_with = "from_gh_config")]
token_stdin: bool,
#[arg(long, conflicts_with_all = ["from_gh_config", "token_stdin"])]
status: bool,
#[arg(long, conflicts_with_all = ["from_gh_config", "token_stdin", "status"])]
clear: bool,
#[command(flatten)]
target: AuthTarget,
},
Status {
#[arg(long = "clear-all")]
clear_all: bool,
#[command(flatten)]
target: AuthTarget,
},
}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum RemoteGh {
DescribeLocal,
Refuse,
}
impl AuthOp {
#[must_use]
pub const fn remote_gh(&self) -> Option<RemoteGh> {
match self {
Self::Gh { status: true, .. } => Some(RemoteGh::DescribeLocal),
Self::Gh { .. } => Some(RemoteGh::Refuse),
_ => None,
}
}
}
#[derive(Debug, Clone, Default, clap::Args)]
pub struct AuthTarget {
#[arg(long, conflicts_with = "server")]
pub local: bool,
#[arg(long, value_name = "URL", conflicts_with = "local")]
pub server: Option<String>,
#[arg(long, conflicts_with_all = ["local", "server"])]
pub managed: bool,
}
#[derive(Debug, Subcommand)]
pub enum TlsOp {
Ca,
Generate {
#[arg(long, value_name = "NAMES", default_value = "localhost")]
dns: String,
},
}