diff --git a/Cargo.lock b/Cargo.lock index 63d1b4d..63f8673 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -894,6 +894,7 @@ name = "images" version = "0.1.0" dependencies = [ "actix-web", + "clap", "lazy_static", "mime", "rand", diff --git a/images/Cargo.toml b/images/Cargo.toml index 15a5ab9..4307761 100644 --- a/images/Cargo.toml +++ b/images/Cargo.toml @@ -14,3 +14,4 @@ scraper = "0.17.1" lazy_static = "1.4.0" rand = "0.8.5" serde_json = "1.0.104" +clap = { version = "4.3.21", features = ["derive"] } diff --git a/images/src/main.rs b/images/src/main.rs index 252cde0..9c2ccc1 100644 --- a/images/src/main.rs +++ b/images/src/main.rs @@ -1,10 +1,20 @@ use utils::error::Result; use actix_web::{get, http::header, web, App, HttpResponse, HttpServer, Responder}; +use clap::Parser; use rand::seq::SliceRandom; pub const BING: &str = "https://www.bing.com/images/search"; +/// An API for fetching images of a query, sourced from Microsoft Bing. +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + /// The port at which to run. + #[arg(short, long, default_value_t=3002)] + port: u16, +} + async fn get_images(query: &str) -> reqwest::Result> { use lazy_static::lazy_static; use scraper::{Html, Selector}; @@ -70,7 +80,7 @@ async fn main() -> std::io::Result<()> { .service(route_query_random) .service(route_query_index) }) - .bind(("127.0.0.1", 3002))? + .bind(("127.0.0.1", Args::parse().port))? .run() .await }