aboutsummaryrefslogtreecommitdiffstats
path: root/src/command/server.rs
blob: 2fcf23d6d7d360fa2cabfb7a9c7b1e0205863914 (plain) (blame)
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
use eyre::Result;
use structopt::StructOpt;

use atuin_server::launch;
use atuin_server::settings::Settings;

#[derive(StructOpt)]
pub enum Cmd {
    #[structopt(
        about="starts the server",
        aliases=&["s", "st", "sta", "star"],
    )]
    Start {
        #[structopt(about = "specify the host address to bind", long, short)]
        host: Option<String>,

        #[structopt(about = "specify the port to bind", long, short)]
        port: Option<u16>,
    },
}

impl Cmd {
    pub async fn run(&self, settings: &Settings) -> Result<()> {
        match self {
            Self::Start { host, port } => {
                let host = host
                    .as_ref()
                    .map_or(settings.host.clone(), std::string::ToString::to_string);
                let port = port.map_or(settings.port, |p| p);

                launch(settings, host, port).await
            }
        }
    }
}