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}
18
19pub(crate) async fn run(command: &ServerCommands) -> Result<(), OperationOutcomeError> {
21 let config: ServerConfig = Figment::new()
22 .merge(Toml::file("haste.toml"))
23 .merge(Env::prefixed("HASTE_"))
24 .extract()
25 .map_err(|e| OperationOutcomeError::error(IssueType::exception(), e.to_string()))?;
26
27 let port = config.port;
28
29 match &command {
30 ServerCommands::Start => server::serve(Arc::new(config), port).await,
31 }
32}