2021-02-14 14:28:01 +01:00
|
|
|
use eyre::Result;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
2021-04-20 22:53:07 +02:00
|
|
|
use atuin_server::launch;
|
|
|
|
use atuin_server::settings::Settings;
|
2021-02-14 14:28:01 +01:00
|
|
|
|
|
|
|
#[derive(StructOpt)]
|
2021-02-14 16:15:26 +01:00
|
|
|
pub enum Cmd {
|
2021-04-09 13:40:21 +02:00
|
|
|
#[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>,
|
|
|
|
},
|
2021-02-14 14:28:01 +01:00
|
|
|
}
|
|
|
|
|
2021-02-14 16:15:26 +01:00
|
|
|
impl Cmd {
|
2021-04-20 18:07:11 +02:00
|
|
|
pub async fn run(&self, settings: &Settings) -> Result<()> {
|
2021-04-09 13:40:21 +02:00
|
|
|
match self {
|
|
|
|
Self::Start { host, port } => {
|
2021-04-20 22:53:07 +02:00
|
|
|
let host = host
|
|
|
|
.as_ref()
|
|
|
|
.map_or(settings.host.clone(), std::string::ToString::to_string);
|
|
|
|
let port = port.map_or(settings.port, |p| p);
|
2021-04-09 13:40:21 +02:00
|
|
|
|
2021-04-20 22:53:07 +02:00
|
|
|
launch(settings, host, port).await
|
2021-04-09 13:40:21 +02:00
|
|
|
}
|
|
|
|
}
|
2021-02-14 14:28:01 +01:00
|
|
|
}
|
|
|
|
}
|