atuin/src/command/server.rs

45 lines
1.1 KiB
Rust
Raw Normal View History

use tracing_subscriber::{fmt, prelude::*, EnvFilter};
2022-04-06 23:32:11 -06:00
use clap::Parser;
use eyre::{Context, Result};
2021-02-14 06:28:01 -07:00
use atuin_server::{launch, 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 {
#[tokio::main]
pub async fn run(self) -> Result<()> {
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_default_env())
.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 } => {
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
launch(settings, host, port).await
2021-04-09 05:40:21 -06:00
}
}
2021-02-14 06:28:01 -07:00
}
}