diff --git a/src/api.rs b/src/api.rs index a39d52b..7de3e45 100644 --- a/src/api.rs +++ b/src/api.rs @@ -111,16 +111,15 @@ pub async fn start_worker( port: u16, tx: mpsc::Sender<(Call, oneshot::Sender>)>, ) -> Result<()> { - tokio::task::spawn( - HttpServer::new(move || { - App::new() - .service(authenticate) - .service(register) - .app_data(web::Data::new(ApiState { tx: tx.clone() })) - }) - .bind(("127.0.0.1", port))? - .run(), - ); - info!("HTTP server started"); + info!("HTTP server starting on port {} ...", port); + let _ = HttpServer::new(move || { + App::new() + .service(authenticate) + .service(register) + .app_data(web::Data::new(ApiState { tx: tx.clone() })) + }) + .bind(("127.0.0.1", port))? + .run() + .await; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 90d4b00..8eb02d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,15 +17,15 @@ struct Args { dir: Option, /// Start in daemon / server mode - #[arg(short = 'D', long)] - daemon: bool, + #[arg(short = 'D', long, value_name = "PORT")] + daemon: Option, /// List all accounts #[arg(short, long)] list: bool, - /// Delete one or multiple account(s) - #[arg(short, long, use_value_delimiter = true, value_delimiter = ',')] + /// Delete one or multiple (comma seperated) accounts + #[arg(short, long = "delete", use_value_delimiter = true, value_delimiter = ',', value_name = "USER(S)")] deletions: Option>, } @@ -35,7 +35,7 @@ async fn main() -> Result<()> { let args = Args::parse(); if args.deletions == None && - !args.daemon && + args.daemon == None && !args.list { return Err(anyhow::Error::msg("Nothing to do. run `baseauth --help` for a list of commands")); } @@ -75,9 +75,8 @@ async fn main() -> Result<()> { } } - if args.daemon { - api::start_worker(8080, tx).await?; - loop {} + if let Some(port) = args.daemon { + api::start_worker(port, tx).await?; } Ok(())