2021-02-14 06:28:01 -07:00
|
|
|
use eyre::Result;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
2021-04-20 14:53:07 -06:00
|
|
|
use atuin_server::launch;
|
|
|
|
use atuin_server::settings::Settings;
|
2021-02-14 06:28:01 -07:00
|
|
|
|
|
|
|
#[derive(StructOpt)]
|
2021-02-14 08:15:26 -07:00
|
|
|
pub enum Cmd {
|
2021-04-09 05:40:21 -06:00
|
|
|
#[structopt(
|
|
|
|
about="starts the server",
|
|
|
|
aliases=&["s", "st", "sta", "star"],
|
|
|
|
)]
|
|
|
|
Start {
|
2021-12-11 15:29:47 -07:00
|
|
|
#[structopt(help = "specify the host address to bind", long, short)]
|
2021-04-09 05:40:21 -06:00
|
|
|
host: Option<String>,
|
|
|
|
|
2021-12-11 15:29:47 -07:00
|
|
|
#[structopt(help = "specify the port to bind", long, short)]
|
2021-04-09 05:40:21 -06:00
|
|
|
port: Option<u16>,
|
|
|
|
},
|
2021-02-14 06:28:01 -07:00
|
|
|
}
|
|
|
|
|
2021-02-14 08:15:26 -07:00
|
|
|
impl Cmd {
|
2021-04-20 10:07:11 -06:00
|
|
|
pub async fn run(&self, settings: &Settings) -> Result<()> {
|
2021-04-09 05:40:21 -06:00
|
|
|
match self {
|
|
|
|
Self::Start { host, port } => {
|
2021-04-20 14:53:07 -06: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 05:40:21 -06:00
|
|
|
|
2021-04-20 14:53:07 -06:00
|
|
|
launch(settings, host, port).await
|
2021-04-09 05:40:21 -06:00
|
|
|
}
|
|
|
|
}
|
2021-02-14 06:28:01 -07:00
|
|
|
}
|
|
|
|
}
|