2022-04-06 23:32:11 -06:00
|
|
|
use clap::Parser;
|
2022-04-21 03:12:56 -06:00
|
|
|
use eyre::{Context, Result};
|
2021-02-14 06:28:01 -07:00
|
|
|
|
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
|
|
|
|
2022-04-06 23:32:11 -06:00
|
|
|
#[derive(Parser)]
|
|
|
|
#[clap(infer_subcommands = true)]
|
2021-02-14 08:15:26 -07:00
|
|
|
pub enum Cmd {
|
2022-04-06 23:32:11 -06:00
|
|
|
/// Start the server
|
2021-04-09 05:40:21 -06:00
|
|
|
Start {
|
2022-04-06 23:32:11 -06:00
|
|
|
/// The host address to bind
|
2022-04-12 16:06:19 -06:00
|
|
|
#[clap(long)]
|
2021-04-09 05:40:21 -06:00
|
|
|
host: Option<String>,
|
|
|
|
|
2022-04-06 23:32:11 -06:00
|
|
|
/// The port to bind
|
|
|
|
#[clap(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 {
|
2022-04-21 03:12:56 -06:00
|
|
|
pub async fn run(self) -> Result<()> {
|
|
|
|
pretty_env_logger::init();
|
|
|
|
|
|
|
|
let settings = Settings::new().wrap_err("could not load server settings")?;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|