From e19b0a7de93cb9dfdbbcb682eb57a225a6a7fa0c Mon Sep 17 00:00:00 2001 From: SeanOMik Date: Sun, 13 Nov 2022 20:05:19 -0500 Subject: [PATCH] Update README, use port and recursive from args, add bind to args --- README.md | 17 +++++++++++++++++ src/main.rs | 16 ++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a9159f1..27e3c23 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,23 @@ # Roulette Serve a random image! +## Usage +``` +Serve a random image! + +Usage: roulette-rs [OPTIONS] [PATHS]... + +Arguments: + [PATHS]... Paths to search for images in + +Options: + -b, --bind IP to bind to when serving on [default: 0.0.0.0] + -p, --port Port to serve the http server on [default: 8080] + -r, --recursive Whether or not to recursively search for images in supplied paths + -h, --help Print help information + -V, --version Print version information +``` + --- This project is a rust rewrite of a [friend's project](https://git.seedno.de/seednode/roulette) that I did for fun. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index afdadaa..628869e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,19 +6,23 @@ use std::path::{PathBuf, Path}; use std::{io, fs}; use rand::seq::SliceRandom; -/// Struct representing CLI arguments +/// Serve a random image! #[derive(Parser, Debug)] #[command(author, version, about)] struct CliArgs { - /// Paths to search for images in. + /// Paths to search for images in paths: Vec, - /// Port to serve the http server on. + /// IP to bind to when serving on + #[arg(short, long, default_value_t = String::from("0.0.0.0"))] + bind: String, + + /// Port to serve the http server on #[arg(short, long, default_value_t = 8080)] port: u16, - /// Wether or not to recursively search for images in supplied paths - #[arg(short, long, default_value_t = true)] + /// Whether or not to recursively search for images in supplied paths + #[arg(short, long, default_value_t = false)] recursive: bool } @@ -184,7 +188,7 @@ async fn main() -> std::io::Result<()> { .app_data(web::Data::new(AppState::new(images.clone()))) .service(serve_picture) .service(chose_picture) - }).bind(("127.0.0.1", 8080))? + }).bind((args.bind, args.port))? .run() .await } \ No newline at end of file