mirror of
https://github.com/hexedtech/codemp.git
synced 2024-11-25 08:34:47 +01:00
feat: parse CLI args in server too
This commit is contained in:
parent
a52f74d092
commit
2fde9659db
3 changed files with 24 additions and 8 deletions
|
@ -50,5 +50,5 @@ default = []
|
||||||
logs = ["dep:tracing-subscriber"]
|
logs = ["dep:tracing-subscriber"]
|
||||||
# runtime = ["dep:tokio", "dep:tokio-stream"]
|
# runtime = ["dep:tokio", "dep:tokio-stream"]
|
||||||
# serde = ["dep:serde", "dep:serde_json"]
|
# serde = ["dep:serde", "dep:serde_json"]
|
||||||
server = ["logs"]
|
server = ["logs", "dep:clap"]
|
||||||
nvim = ["logs", "dep:nvim-rs", "dep:clap", "dep:rmpv"]
|
nvim = ["logs", "dep:nvim-rs", "dep:clap", "dep:rmpv"]
|
||||||
|
|
|
@ -38,6 +38,7 @@ pub struct BufferService {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BufferService {
|
impl BufferService {
|
||||||
|
#[allow(unused)]
|
||||||
fn get_buffer(&self, path: &String) -> Result<BufferHandle, Status> {
|
fn get_buffer(&self, path: &String) -> Result<BufferHandle, Status> {
|
||||||
match self.map.read().unwrap().get(path) {
|
match self.map.read().unwrap().get(path) {
|
||||||
Some(buf) => Ok(buf.clone()),
|
Some(buf) => Ok(buf.clone()),
|
||||||
|
|
|
@ -4,25 +4,40 @@
|
||||||
//! all clients and synching everyone's cursor.
|
//! all clients and synching everyone's cursor.
|
||||||
//!
|
//!
|
||||||
|
|
||||||
mod buffer;
|
use clap::Parser;
|
||||||
|
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
use tonic::transport::Server;
|
use tonic::transport::Server;
|
||||||
|
|
||||||
|
mod buffer;
|
||||||
|
|
||||||
use crate::buffer::service::BufferService;
|
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]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
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()
|
Server::builder()
|
||||||
.add_service(BufferService::new().server())
|
.add_service(BufferService::new().server())
|
||||||
.serve(addr)
|
.serve(args.host.parse()?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in a new issue