haste_health/commands/
server.rs1use std::sync::Arc;
2
3use clap::Subcommand;
4use figment::{
5 Figment,
6 providers::{Env, Format as _, Toml},
7};
8use haste_fhir_model::r4::generated::terminology::IssueType;
9use haste_fhir_operation_error::OperationOutcomeError;
10use haste_server::{config::ServerConfig, server};
11
12#[derive(Subcommand, Debug)]
14pub(crate) enum ServerCommands {
15 Start {
17 #[arg(short, long)]
19 port: Option<u16>,
20 },
21}
22
23pub(crate) async fn run(command: &ServerCommands) -> Result<(), OperationOutcomeError> {
25 let config: ServerConfig = Figment::new()
26 .merge(Toml::file("haste.toml"))
27 .merge(Env::prefixed("HASTE_"))
28 .extract()
29 .map_err(|e| OperationOutcomeError::error(IssueType::exception(), e.to_string()))?;
30
31 match &command {
32 ServerCommands::Start { port } => {
33 server::serve(Arc::new(config), port.unwrap_or(3000)).await
34 }
35 }
36}