From 1424d765f72f8d8b8ed76940d2913e8e4d32126b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Klemens=20Sch=C3=B6lhorn?= Date: Fri, 13 Jun 2025 15:24:55 +0200 Subject: [PATCH] Require specifying port on command line --- src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index fdddebe..29b945e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,16 @@ struct ApplicationState { #[tokio::main] async fn main() { - let image_path = args_os().nth(1).expect("Usage: image-gallery IMAGE_DIRECTORY"); + let args = args_os() + .skip(1) + .collect::>(); + let args = args + .windows(2) + .next() + .expect("Usage: image-gallery IMAGE_DIRECTORY PORT"); + + let image_path = &args[0]; + let port = args[1].to_string_lossy().parse::().expect("Invalid port specified"); let mut secret_key: SecretKey = [0; 64]; OsRng.fill_bytes(&mut secret_key); @@ -107,7 +116,7 @@ async fn main() { cpu_task_limit: Arc::new(Semaphore::new(4)), }); - let addr = SocketAddr::from(([0, 0, 0, 0], 9030)); + let addr = SocketAddr::from(([0, 0, 0, 0], port)); tracing::info!("listening on {}", addr); axum::Server::bind(&addr) .serve(app.into_make_service())