use anyhow::Result;
use crate::dev_oidc_issuer;
#[derive(Debug, Clone, clap::Subcommand)]
pub enum BackendCommands {
#[cfg(feature = "backend")]
Server,
#[cfg(feature = "backend")]
CheckConfig,
#[cfg(feature = "backend")]
ConfigSchema,
DevOidcIssuer {
#[arg(long, short, default_value = "5678")]
port: u16,
#[arg(long)]
token: Option<String>,
},
}
pub async fn handle_backend_command(cmd: BackendCommands) -> Result<()> {
match cmd {
#[cfg(feature = "backend")]
BackendCommands::Server => {
let settings = crate::server::settings::Settings::new()?;
crate::server::run_server(settings).await
}
#[cfg(feature = "backend")]
BackendCommands::CheckConfig => {
println!("Checking backend configuration...");
match crate::server::settings::Settings::new() {
Ok(_) => {
println!("✓ Configuration is valid");
Ok(())
}
Err(e) => {
eprintln!("✗ Configuration error: {}", e);
std::process::exit(1);
}
}
}
#[cfg(feature = "backend")]
BackendCommands::ConfigSchema => {
let schema = crate::server::settings::Settings::json_schema_value()?;
println!("{}", serde_json::to_string_pretty(&schema)?);
Ok(())
}
BackendCommands::DevOidcIssuer { port, token } => dev_oidc_issuer::run(port, token).await,
}
}