atuin/src/command/server.rs

38 lines
950 B
Rust
Raw Normal View History

2021-02-14 06:28:01 -07:00
use eyre::Result;
use structopt::StructOpt;
2021-02-14 08:15:26 -07:00
use crate::remote::server;
use crate::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 {
#[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 06:28:01 -07:00
}
2021-02-14 08:15:26 -07:00
impl Cmd {
pub fn run(&self, settings: &Settings) -> Result<()> {
2021-04-09 05:40:21 -06:00
match self {
Self::Start { host, port } => {
let host = host.as_ref().map_or(
settings.remote.host.clone(),
std::string::ToString::to_string,
);
let port = port.map_or(settings.remote.port, |p| p);
server::launch(settings, host, port);
}
}
2021-02-14 06:28:01 -07:00
Ok(())
}
}