use clap::{Args, Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(name = "k2db-api")]
#[command(about = "Single-binary Rust server for the k2db API")]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
Serve(BootstrapArgs),
Init(BootstrapArgs),
Recover(BootstrapArgs),
Keys(KeysArgs),
Config(ConfigArgs),
}
#[derive(Debug, Clone, Args)]
pub struct BootstrapArgs {
#[arg(long)]
pub mongo_uri: Option<String>,
#[arg(long)]
pub mongo_uri_env: Option<String>,
#[arg(long)]
pub bootstrap_token: Option<String>,
#[arg(long)]
pub bootstrap_token_env: Option<String>,
#[arg(long, default_value = "k2_system")]
pub system_db_name: String,
#[arg(long)]
pub listen_host: Option<String>,
#[arg(long)]
pub listen_port: Option<u16>,
#[arg(long)]
pub ownership_mode: Option<String>,
#[arg(long)]
pub slow_query_ms: Option<u64>,
#[arg(long)]
pub seed_key_name: Option<String>,
#[arg(long)]
pub seed_key_database: Option<String>,
#[arg(long = "seed-key-permission")]
pub seed_key_permissions: Vec<String>,
}
#[derive(Debug, Clone, Subcommand)]
pub enum KeysCommand {
Create(CreateKeyArgs),
Revoke(RevokeKeyArgs),
List,
}
#[derive(Debug, Clone, Args)]
pub struct KeysArgs {
#[command(flatten)]
pub bootstrap: BootstrapArgs,
#[command(subcommand)]
pub command: KeysCommand,
}
#[derive(Debug, Clone, Args)]
pub struct CreateKeyArgs {
#[arg(long)]
pub name: String,
#[arg(long)]
pub database: String,
#[arg(long = "permission")]
pub permissions: Vec<String>,
}
#[derive(Debug, Clone, Args)]
pub struct RevokeKeyArgs {
#[arg(long)]
pub key_id: String,
}
#[derive(Debug, Clone, Subcommand)]
pub enum ConfigCommand {
Get,
Set(SetConfigArgs),
}
#[derive(Debug, Clone, Args)]
pub struct ConfigArgs {
#[command(flatten)]
pub bootstrap: BootstrapArgs,
#[command(subcommand)]
pub command: ConfigCommand,
}
#[derive(Debug, Clone, Args)]
pub struct SetConfigArgs {
#[arg(long)]
pub listen_host: Option<String>,
#[arg(long)]
pub listen_port: Option<u16>,
#[arg(long)]
pub ownership_mode: Option<String>,
#[arg(long)]
pub slow_query_ms: Option<u64>,
#[arg(long, default_value_t = false)]
pub clear_slow_query_ms: bool,
}