use clap::{Args, Parser, Subcommand};
use super::help;
use crate::runtime::{EXIT_SUCCESS, ExitCode};
#[derive(Parser, Default)]
#[command(
name = "server",
about = "Run the local Elph server (REST + WebSocket + web UI)",
color = clap::ColorChoice::Auto
)]
pub struct ServerArgs {
#[command(subcommand)]
pub command: Option<ServerCommands>,
#[arg(short, long, default_value_t = 8080)]
pub port: u16,
#[arg(long, default_value = "127.0.0.1")]
pub host: String,
}
#[derive(Subcommand)]
pub enum ServerCommands {
Run(ServerRunArgs),
Ps,
Kill,
RotateToken,
}
#[derive(Args, Default)]
pub struct ServerRunArgs {
#[arg(long)]
pub foreground: bool,
}
pub fn handle(args: &ServerArgs) -> ExitCode {
let Some(cmd) = &args.command else {
return help::print_subcommand_help::<ServerArgs>();
};
match cmd {
ServerCommands::Run(run_args) => {
help::unimplemented(&format!(
"Server run — not yet implemented (port: {}, host: {}, foreground: {})",
args.port, args.host, run_args.foreground
));
EXIT_SUCCESS
}
ServerCommands::Ps => {
help::unimplemented("Server ps — not yet implemented");
EXIT_SUCCESS
}
ServerCommands::Kill => {
help::unimplemented("Server kill — not yet implemented");
EXIT_SUCCESS
}
ServerCommands::RotateToken => {
help::unimplemented("Server rotate-token — not yet implemented");
EXIT_SUCCESS
}
}
}