1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::sync::Arc;

use hermes_runtime::types::runtime::HermesRuntime;
use oneline_eyre::eyre::eyre;

use crate::application::log::{enable_ansi, install_logger};
use crate::application::Application;
use crate::{output, Result};

pub fn boot<A>() -> Result<()>
where
    A: Application,
{
    oneline_eyre::install()?;

    let app = A::parse_from_env();

    let with_color = enable_ansi();
    let with_json = app.json_output();
    install_logger(with_color, with_json);

    output::set_json(with_json);

    let rt = tokio::runtime::Builder::new_multi_thread()
        .enable_all()
        .build()
        .map_err(|e| eyre!("failed to initialized tokio runtime: {e}"))?;

    let rt = HermesRuntime::new(Arc::new(rt));

    rt.runtime.block_on(run(rt.clone(), app))?;

    Ok(())
}

pub async fn run<A>(rt: HermesRuntime, app: A) -> Result<()>
where
    A: Application,
{
    let output = app.run(rt).await?;
    output.print();
    Ok(())
}