use axon::axon_server;
use clap::Parser;
use std::process;
#[derive(Parser)]
#[command(
name = "axon-server",
about = "AXON runtime — serves governed flows over HTTP/SSE/WebSocket.",
long_about = "The AXON runtime daemon: deploys and executes governed flows, \
serving them over HTTP, SSE and WebSocket.\n\n\
The compiler and governance CLI is the separate `axon` binary — use it to \
type-check (`axon check`), compile, and produce audit artefacts. Both binaries \
ship from the `axon-lang` crate under AGPL; this one requires the `server` \
feature (`cargo install axon-lang --features server`).",
version = axon::version::AXON_VERSION,
)]
struct Cli {
#[arg(long, default_value = "127.0.0.1")]
host: String,
#[arg(long, default_value_t = 8420)]
port: u16,
#[arg(long, default_value = "memory")]
channel: String,
#[arg(long, default_value = "")]
auth_token: String,
#[arg(long, default_value = "info")]
log_level: String,
#[arg(long, default_value = "json")]
log_format: String,
#[arg(long)]
log_file: Option<String>,
#[arg(long)]
database_url: Option<String>,
#[arg(long)]
strict_type_driven_transport: bool,
#[arg(long)]
backend: Option<String>,
#[arg(long)]
schemas_dir: Option<String>,
}
fn main() {
let cli = Cli::parse();
let exit_code = axon_server::run_serve(axon_server::ServerConfig {
host: cli.host,
port: cli.port,
channel: cli.channel,
auth_token: cli.auth_token,
log_level: cli.log_level,
log_format: cli.log_format,
log_file: cli.log_file,
database_url: cli.database_url.or_else(|| std::env::var("DATABASE_URL").ok()),
config_path: None,
strict_type_driven_transport: cli.strict_type_driven_transport
|| axon::env_flags::parse_truthy_env("AXON_STRICT_TYPE_DRIVEN_TRANSPORT"),
default_backend: cli
.backend
.or_else(|| std::env::var("AXON_DEFAULT_BACKEND").ok())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty()),
schemas_dir: cli
.schemas_dir
.or_else(|| std::env::var("AXON_SCHEMAS_DIR").ok())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty()),
});
process::exit(exit_code);
}