use clap::Subcommand;
#[derive(Debug, Clone, Subcommand)]
pub enum ClusterCommands {
Init,
Status,
}
#[derive(Debug, Clone, Subcommand)]
pub enum TenantCommands {
Create,
List,
}
#[derive(Debug, Subcommand)]
pub enum PluginAction {
List {
#[arg(long)]
detailed: bool,
#[arg(long)]
category: Option<String>,
},
Install {
#[arg(long)]
plugin_name: Option<String>,
#[arg(long)]
plugin_path: Option<String>,
#[arg(long)]
force: bool,
},
}
#[derive(Subcommand)]
pub enum Commands {
Create {
#[arg(short, long)]
name: Option<String>,
#[arg(short, long, default_value = "startup")]
template: String,
#[arg(short, long)]
data_dir: Option<String>,
#[arg(short, long)]
interactive: bool,
#[arg(long)]
dry_run: bool,
},
Migrate {
#[arg(short, long, default_value = "postgres")]
from: String,
#[arg(short, long)]
to: String,
#[arg(short, long)]
source: String,
#[arg(short, long)]
data_dir: Option<String>,
#[arg(short, long)]
table: Option<String>,
#[arg(short, long, default_value = "1000")]
batch_size: usize,
#[arg(short, long)]
progress: bool,
},
Start {
#[arg(short, long)]
data_dir: Option<String>,
#[arg(short = 'p', long, default_value = "8080")]
port: u16,
#[arg(long, default_value = "127.0.0.1")]
host: String,
},
Stop,
Status {
#[arg(short, long)]
data_dir: Option<String>,
},
Key {
#[command(subcommand)]
action: KeyAction,
},
Config {
#[command(subcommand)]
action: ConfigAction,
},
Cluster {
#[command(subcommand)]
action: ClusterCommands,
},
Tenant {
#[command(subcommand)]
action: TenantCommands,
},
Plugin {
#[command(subcommand)]
action: PluginAction,
},
}
#[derive(Subcommand)]
pub enum KeyAction {
Generate {
#[arg(long, default_value = "aegis256")]
algorithm: String,
#[arg(long, default_value = "64")]
length: usize,
#[arg(long, default_value = "hex")]
format: String,
},
List,
Rotate {
#[arg(long)]
dry_run: bool,
#[arg(long)]
force: bool,
},
Rollback {
#[arg(long)]
version: Option<String>,
},
Show {
key_id: String,
},
}
#[derive(Subcommand)]
pub enum ConfigAction {
Show,
Set {
key: String,
value: String,
},
Reset,
Validate,
}
impl From<ClusterCommands> for crate::commands::cluster::ClusterCommands {
fn from(placeholder: ClusterCommands) -> Self {
match placeholder {
ClusterCommands::Init => crate::commands::cluster::ClusterCommands::Init(
crate::commands::cluster::InitArgs {
bind_address: "127.0.0.1:8080".parse().unwrap_or_else(|_| "127.0.0.1:8080".parse().unwrap()),
min_nodes: 3,
replication_factor: 3,
heartbeat_interval: 500,
election_timeout: 5000,
}
),
ClusterCommands::Status => crate::commands::cluster::ClusterCommands::Status,
}
}
}
impl From<TenantCommands> for crate::commands::tenant::TenantCommands {
fn from(placeholder: TenantCommands) -> Self {
match placeholder {
TenantCommands::Create => crate::commands::tenant::TenantCommands::Create(
crate::commands::tenant::CreateArgs {
name: "default".to_string(),
description: None,
max_databases: None,
max_storage: None,
max_connections: None,
resources: None,
}
),
TenantCommands::List => crate::commands::tenant::TenantCommands::List(
crate::commands::tenant::ListArgs {
detailed: false,
status: None,
limit: None,
}
),
}
}
}
impl From<PluginAction> for crate::commands::plugin::PluginAction {
fn from(placeholder: PluginAction) -> Self {
match placeholder {
PluginAction::List { detailed, category } => {
crate::commands::plugin::PluginAction::List {
detailed,
category,
}
}
PluginAction::Install { plugin_name, plugin_path: _, force: _ } => {
crate::commands::plugin::PluginAction::Search {
query: plugin_name.unwrap_or_default(),
limit: 10,
}
}
}
}
}