use std::path::PathBuf;
use clap::{
Parser, Subcommand, ValueEnum,
builder::Styles,
builder::styling::{AnsiColor, Effects},
};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, ValueEnum)]
pub enum UiLang {
#[default]
En,
Zh,
}
impl std::fmt::Display for UiLang {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
UiLang::En => write!(f, "en"),
UiLang::Zh => write!(f, "zh"),
}
}
}
fn embystream_styles() -> Styles {
Styles::styled()
.header(AnsiColor::Yellow.on_default() | Effects::BOLD)
.usage(AnsiColor::Green.on_default() | Effects::BOLD)
.literal(AnsiColor::Cyan.on_default())
.placeholder(AnsiColor::Green.on_default())
}
#[derive(Parser, Debug)]
#[command(
name = "embystream",
author,
version,
about = "Emby streaming proxy: run frontend, backend, or dual gateways from TOML config.",
long_about = None
)]
#[command(propagate_version = true)]
#[command(styles = embystream_styles())]
#[command(color = clap::ColorChoice::Auto)]
pub struct Cli {
#[arg(
long = "lang",
global = true,
default_value_t = UiLang::En,
value_name = "LANG"
)]
pub lang: UiLang,
#[command(subcommand)]
pub command: Option<Commands>,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Run(RunArgs),
Web(WebArgs),
Auth(AuthArgs),
Config(ConfigArgs),
}
#[derive(Parser, Debug)]
pub struct AuthArgs {
#[command(subcommand)]
pub sub: AuthSubcommand,
}
#[derive(Subcommand, Debug)]
pub enum AuthSubcommand {
Google(GoogleAuthCliArgs),
}
#[derive(Parser, Debug, Clone)]
pub struct GoogleAuthCliArgs {
#[arg(long = "client-id", value_name = "CLIENT_ID")]
pub client_id: String,
#[arg(long = "secret", value_name = "CLIENT_SECRET")]
pub client_secret: String,
#[arg(long = "no-browser")]
pub no_browser: bool,
}
#[derive(Parser, Debug)]
pub struct ConfigArgs {
#[command(subcommand)]
pub sub: Option<ConfigSubcommand>,
}
#[derive(Subcommand, Debug, Clone, Copy)]
pub enum ConfigSubcommand {
Show,
Template,
}
#[derive(Parser, Debug)]
pub struct RunArgs {
#[arg(short, long, value_name = "FILE")]
pub config: Option<PathBuf>,
#[arg(long)]
pub web: bool,
#[arg(long, value_name = "ADDR", default_value = "0.0.0.0:6888")]
pub web_listen: String,
#[arg(long, value_name = "DIR", default_value = "web-config/data")]
pub web_data_dir: PathBuf,
#[arg(long, value_name = "KEY")]
pub web_tmdb_api_key: Option<String>,
#[arg(long, value_name = "DIR", default_value = "web-config/logs")]
pub web_runtime_log_dir: PathBuf,
#[arg(long, value_name = "FILE")]
pub ssl_cert_file: Option<PathBuf>,
#[arg(long, value_name = "FILE")]
pub ssl_key_file: Option<PathBuf>,
}
#[derive(Parser, Debug)]
pub struct WebArgs {
#[command(subcommand)]
pub sub: WebSubcommand,
}
#[derive(Subcommand, Debug)]
pub enum WebSubcommand {
Serve(WebServeArgs),
Admin(WebAdminArgs),
}
#[derive(Parser, Debug, Clone)]
pub struct WebServeArgs {
#[arg(long, value_name = "ADDR", default_value = "0.0.0.0:6888")]
pub listen: String,
#[arg(long, value_name = "DIR", default_value = "web-config/data")]
pub data_dir: PathBuf,
#[arg(long, value_name = "KEY")]
pub tmdb_api_key: Option<String>,
#[arg(long, value_name = "DIR", default_value = "web-config/logs")]
pub runtime_log_dir: PathBuf,
#[arg(long, value_name = "DIR", default_value = "./logs")]
pub stream_log_dir: PathBuf,
}
#[derive(Parser, Debug)]
pub struct WebAdminArgs {
#[command(subcommand)]
pub sub: WebAdminSubcommand,
}
#[derive(Subcommand, Debug)]
pub enum WebAdminSubcommand {
ResetPassword(WebAdminResetPasswordArgs),
}
#[derive(Parser, Debug, Clone)]
pub struct WebAdminResetPasswordArgs {
#[arg(long, value_name = "NAME", default_value = "admin")]
pub username: String,
#[arg(long, value_name = "DIR", default_value = "web_data")]
pub data_dir: PathBuf,
}