feat: parse CLI args in server too

This commit is contained in:
əlemi 2023-04-12 04:59:33 +02:00
parent a52f74d092
commit 2fde9659db
3 changed files with 24 additions and 8 deletions

View file

@ -50,5 +50,5 @@ default = []
logs = ["dep:tracing-subscriber"]
# runtime = ["dep:tokio", "dep:tokio-stream"]
# serde = ["dep:serde", "dep:serde_json"]
server = ["logs"]
server = ["logs", "dep:clap"]
nvim = ["logs", "dep:nvim-rs", "dep:clap", "dep:rmpv"]

View file

@ -38,6 +38,7 @@ pub struct BufferService {
}
impl BufferService {
#[allow(unused)]
fn get_buffer(&self, path: &String) -> Result<BufferHandle, Status> {
match self.map.read().unwrap().get(path) {
Some(buf) => Ok(buf.clone()),

View file

@ -4,25 +4,40 @@
//! all clients and synching everyone's cursor.
//!
mod buffer;
use clap::Parser;
use tracing::info;
use tonic::transport::Server;
mod buffer;
use crate::buffer::service::BufferService;
#[derive(Parser, Debug)]
struct CliArgs {
/// address to listen on
#[arg(long, default_value = "[::1]:50051")]
host: String,
/// enable debug log level
#[arg(long, default_value_t = false)]
debug: bool,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
let args = CliArgs::parse();
let addr = "[::1]:50051".parse()?;
tracing_subscriber::fmt()
.with_writer(std::io::stdout)
.with_max_level(if args.debug { tracing::Level::DEBUG } else { tracing::Level::INFO })
.init();
info!("Starting server");
info!("starting server");
Server::builder()
.add_service(BufferService::new().server())
.serve(addr)
.serve(args.host.parse()?)
.await?;
Ok(())