117 lines
2.7 KiB
Rust
117 lines
2.7 KiB
Rust
use std::net::SocketAddr;
|
|
use std::path::PathBuf;
|
|
|
|
use clap::{Parser, Subcommand, ValueEnum};
|
|
|
|
#[derive(Debug, Parser)]
|
|
#[command(author, version, about)]
|
|
pub struct Cli {
|
|
#[command(subcommand)]
|
|
pub command: Option<Command>,
|
|
}
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
pub enum Command {
|
|
Serve(ServeArgs),
|
|
InitDb(DbArgs),
|
|
ImportRedis(RedisImportArgs),
|
|
ExportRedis(RedisExportArgs),
|
|
ExportJson(JsonExportArgs),
|
|
ImportJson(JsonImportArgs),
|
|
Healthcheck(HealthcheckArgs),
|
|
}
|
|
|
|
#[derive(Clone, Debug, Parser)]
|
|
pub struct ServeArgs {
|
|
#[arg(long, env = "KOSYNC_DB", default_value = "./data/kosync.sqlite3")]
|
|
pub db: PathBuf,
|
|
|
|
#[arg(long, env = "KOSYNC_HTTP_ADDR", default_value = "0.0.0.0:17200")]
|
|
pub http_addr: SocketAddr,
|
|
|
|
#[arg(long, env = "KOSYNC_HTTPS_ADDR", default_value = "0.0.0.0:7200")]
|
|
pub https_addr: SocketAddr,
|
|
|
|
#[arg(long, env = "KOSYNC_TLS", value_enum, default_value = "auto")]
|
|
pub tls: TlsMode,
|
|
|
|
#[arg(long, env = "KOSYNC_TLS_CERT")]
|
|
pub tls_cert: Option<PathBuf>,
|
|
|
|
#[arg(long, env = "KOSYNC_TLS_KEY")]
|
|
pub tls_key: Option<PathBuf>,
|
|
|
|
#[arg(long, env = "ENABLE_USER_REGISTRATION")]
|
|
pub enable_user_registration: Option<String>,
|
|
}
|
|
|
|
#[derive(Clone, Debug, ValueEnum)]
|
|
pub enum TlsMode {
|
|
Off,
|
|
Auto,
|
|
On,
|
|
}
|
|
|
|
#[derive(Debug, Parser)]
|
|
pub struct DbArgs {
|
|
#[arg(long, env = "KOSYNC_DB", default_value = "./data/kosync.sqlite3")]
|
|
pub db: PathBuf,
|
|
}
|
|
|
|
#[derive(Debug, Parser)]
|
|
pub struct RedisImportArgs {
|
|
#[arg(long, env = "KOSYNC_DB", default_value = "./data/kosync.sqlite3")]
|
|
pub db: PathBuf,
|
|
|
|
#[arg(long, default_value = "redis://127.0.0.1:6379/1")]
|
|
pub redis_url: String,
|
|
}
|
|
|
|
#[derive(Debug, Parser)]
|
|
pub struct RedisExportArgs {
|
|
#[arg(long, env = "KOSYNC_DB", default_value = "./data/kosync.sqlite3")]
|
|
pub db: PathBuf,
|
|
|
|
#[arg(long, default_value = "redis://127.0.0.1:6379/1")]
|
|
pub redis_url: String,
|
|
|
|
#[arg(long)]
|
|
pub flush_target: bool,
|
|
}
|
|
|
|
#[derive(Debug, Parser)]
|
|
pub struct JsonExportArgs {
|
|
#[arg(long, env = "KOSYNC_DB", default_value = "./data/kosync.sqlite3")]
|
|
pub db: PathBuf,
|
|
|
|
#[arg(long)]
|
|
pub output: PathBuf,
|
|
}
|
|
|
|
#[derive(Debug, Parser)]
|
|
pub struct JsonImportArgs {
|
|
#[arg(long, env = "KOSYNC_DB", default_value = "./data/kosync.sqlite3")]
|
|
pub db: PathBuf,
|
|
|
|
#[arg(long)]
|
|
pub input: PathBuf,
|
|
}
|
|
|
|
#[derive(Debug, Parser)]
|
|
pub struct HealthcheckArgs {
|
|
#[arg(long, default_value = "https://127.0.0.1:7200/healthcheck")]
|
|
pub url: String,
|
|
|
|
#[arg(long)]
|
|
pub insecure: bool,
|
|
}
|
|
|
|
impl ServeArgs {
|
|
pub fn registration_enabled(&self) -> bool {
|
|
matches!(
|
|
self.enable_user_registration.as_deref(),
|
|
Some("true") | Some("1")
|
|
)
|
|
}
|
|
}
|