use std::path::PathBuf;
use std::process::ExitCode;
use clap::Parser;
#[derive(Parser, Debug)]
#[command(name = "assay-engine", version, about = "Assay workflow + auth engine")]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(clap::Subcommand, Debug)]
enum Command {
Serve {
#[arg(long, short, env = "ASSAY_ENGINE_CONFIG")]
config: PathBuf,
},
}
#[tokio::main]
async fn main() -> ExitCode {
let cli = Cli::parse();
match cli.command {
Command::Serve { config } => {
let cfg = match assay_engine::EngineConfig::from_file(&config) {
Ok(c) => c,
Err(e) => {
eprintln!("config error: {e:#}");
return ExitCode::from(2);
}
};
init_tracing(&cfg.logging.level, &cfg.logging.format);
if let Err(e) = assay_engine::run(cfg).await {
eprintln!("engine error: {e:#}");
return ExitCode::from(1);
}
ExitCode::SUCCESS
}
}
}
fn init_tracing(level: &str, format: &str) {
use tracing_subscriber::{EnvFilter, fmt};
let filter = EnvFilter::try_from_default_env()
.or_else(|_| EnvFilter::try_new(level))
.unwrap_or_else(|_| EnvFilter::new("info"));
let builder = fmt().with_env_filter(filter);
match format {
"json" => builder.json().init(),
_ => builder.init(),
}
}