atuin/src/command/server.rs

36 lines
913 B
Rust
Raw Normal View History

2021-02-14 14:28:01 +01:00
use eyre::Result;
use structopt::StructOpt;
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 {
pub async fn run(&self, settings: &Settings) -> Result<()> {
2021-04-09 13:40:21 +02:00
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);
2021-04-09 13:40:21 +02:00
launch(settings, host, port).await
2021-04-09 13:40:21 +02:00
}
}
2021-02-14 14:28:01 +01:00
}
}