Skip to main content

cli_core/
startup.rs

1use server::config::set_system_config;
2
3/// Boot the server the same way the original CLI entrypoint did:
4/// install drivers, run migrations, load config. Used by both
5/// binaries so the initialization sequence stays identical.
6///
7/// # Errors
8///
9/// Returns an `anyhow::Error` if `database` conflicts with an already resolved
10/// database URL, if the boot task fails or is aborted, or if
11/// `set_system_config` fails for the optional `setopt` override.
12pub async fn start_server(
13    database: Option<String>,
14    setopt: Option<(String, String)>,
15) -> anyhow::Result<()> {
16    if let Some(db) = database {
17        server::db::use_url(db)?;
18    }
19
20    // `server::start` already returns the boot task's handle; spawning it again
21    // only added a third Result layer to unwrap.
22    server::start().await.await??;
23
24    if let Some((field, content)) = setopt {
25        set_system_config(&field, content.into()).await?;
26    }
27
28    Ok(())
29}