From e2495c3c02481ee2e87f01149859c4e740f2006d Mon Sep 17 00:00:00 2001 From: "Aode (lion)" Date: Sat, 28 May 2022 11:53:46 -0500 Subject: [PATCH] Use clap directly --- Cargo.lock | 113 +++++++++++++++++++++++++++++----------------------- Cargo.toml | 2 +- README.md | 35 ++++++++-------- src/lib.rs | 16 ++++---- src/main.rs | 4 +- 5 files changed, 94 insertions(+), 76 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f16803..836eac3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -450,17 +450,41 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "3.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" dependencies = [ - "ansi_term", "atty", "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "lazy_static", "strsim", + "termcolor", "textwrap", - "unicode-width", - "vec_map", +] + +[[package]] +name = "clap_derive" +version = "3.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" +dependencies = [ + "heck 0.4.0", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +dependencies = [ + "os_str_bytes", ] [[package]] @@ -823,6 +847,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1259,6 +1289,12 @@ dependencies = [ "tonic-build", ] +[[package]] +name = "os_str_bytes" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" + [[package]] name = "parking_lot" version = "0.11.2" @@ -1337,6 +1373,7 @@ dependencies = [ "actix-web", "awc", "bcrypt", + "clap", "console-subscriber", "dotenv", "mime", @@ -1348,7 +1385,6 @@ dependencies = [ "serde", "serde_json", "sled", - "structopt", "thiserror", "tokio", "tracing", @@ -1461,7 +1497,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" dependencies = [ "bytes", - "heck", + "heck 0.3.3", "itertools", "lazy_static", "log", @@ -1780,33 +1816,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - -[[package]] -name = "structopt" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" -dependencies = [ - "clap", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" @@ -1840,14 +1852,20 @@ dependencies = [ ] [[package]] -name = "textwrap" -version = "0.11.0" +name = "termcolor" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ - "unicode-width", + "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" + [[package]] name = "thiserror" version = "1.0.31" @@ -2277,12 +2295,6 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" -[[package]] -name = "unicode-width" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" - [[package]] name = "url" version = "2.2.2" @@ -2321,12 +2333,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.4" @@ -2436,6 +2442,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 3ecd481..bd39868 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ actix-rt = "2.6.0" actix-web = { version = "4.0.0", default-features = false } awc = { version = "3.0.0", default-features = false } bcrypt = "0.13" +clap = { version = "3.1.18", features = ["derive", "env"] } console-subscriber = "0.1" mime = "0.3" minify-html = "0.8.0" @@ -28,7 +29,6 @@ qrcodegen = "1.7" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" sled = { version = "0.34.7", features = ["zstd"] } -structopt = "0.3.21" tokio = { version = "1", default-features = false, features = ["sync"] } thiserror = "1.0" tracing = "0.1" diff --git a/README.md b/README.md index 5177e3a..c9e7966 100644 --- a/README.md +++ b/README.md @@ -4,33 +4,36 @@ _a simple image aggregator for pict-rs_ ## Usage ### Running ``` -pict-rs-aggregator 0.1.32 +pict-rs-aggregator USAGE: pict-rs-aggregator [OPTIONS] -FLAGS: - -h, --help Prints help information - -V, --version Prints version information - OPTIONS: - -a, --addr - The address and port the server binds to [env: PICTRS_AGGREGATOR_ADDR=] [default: 0.0.0.0:8082] + -a, --addr + The address and port the server binds to [env: PICTRS_AGGREGATOR_ADDR=] [default: + 0.0.0.0:8082] - -c, --console-event-buffer-size + -c, --console-event-buffer-size The number of events to buffer in console. When unset, console is disabled [env: PICTRS_AGGREGATOR_CONSOLE_EVENT_BUFFER_SIZE=] - -d, --database-path - The path to the database [env: PICTRS_AGGREGATOR_DATABASE=] [default: sled/db-0-34] - -o, --opentelemetry-url + -d, --database-path + The path to the database [env: PICTRS_AGGREGATOR_DATABASE=] [default: sled/db-0-34] + + -h, --help + Print help information + + -o, --opentelemetry-url URL for the OpenTelemetry Colletor [env: PICTRS_AGGREGATOR_OPENTELEMETRY_URL=] - -s, --sled-cache-capacity - The amount of RAM, in bytes, that sled is allowed to consume. Increasing this value can improve performance - [env: PICTRS_AGGREGATOR_SLED_CACHE_CAPACITY=] [default: 67108864] - -u, --upstream - The url of the upstream pict-rs server [env: PICTRS_AGGREGATOR_UPSTREAM=] [default: http://localhost:8080] + -s, --sled-cache-capacity + The amount of RAM, in bytes, that sled is allowed to consume. Increasing this value can + improve performance [env: PICTRS_AGGREGATOR_SLED_CACHE_CAPACITY=] [default: 67108864] + + -u, --upstream + The url of the upstream pict-rs server [env: PICTRS_AGGREGATOR_UPSTREAM=] [default: + http://localhost:8080] ``` #### Examples diff --git a/src/lib.rs b/src/lib.rs index c20bdf6..1b0a5c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ use actix_web::{ web, HttpRequest, HttpResponse, HttpResponseBuilder, ResponseError, }; use awc::Client; +use clap::Parser; use sled::Db; use std::{ io::Cursor, @@ -16,7 +17,6 @@ use std::{ path::{Path, PathBuf}, time::SystemTime, }; -use structopt::StructOpt; use tracing_error::SpanTrace; use url::Url; use uuid::Uuid; @@ -34,9 +34,9 @@ mod ui; use self::{connection::Connection, middleware::ValidToken, store::Store}; -#[derive(Clone, Debug, StructOpt)] +#[derive(Clone, Debug, Parser)] pub struct Config { - #[structopt( + #[clap( short, long, env = "PICTRS_AGGREGATOR_ADDR", @@ -45,7 +45,7 @@ pub struct Config { )] addr: SocketAddr, - #[structopt( + #[clap( short, long, env = "PICTRS_AGGREGATOR_UPSTREAM", @@ -54,7 +54,7 @@ pub struct Config { )] upstream: Url, - #[structopt( + #[clap( short, long, env = "PICTRS_AGGREGATOR_DATABASE", @@ -63,7 +63,7 @@ pub struct Config { )] database_path: PathBuf, - #[structopt( + #[clap( short, long, env = "PICTRS_AGGREGATOR_SLED_CACHE_CAPACITY", @@ -72,7 +72,7 @@ pub struct Config { )] sled_cache_capacity: u64, - #[structopt( + #[clap( short, long, env = "PICTRS_AGGREGATOR_CONSOLE_EVENT_BUFFER_SIZE", @@ -80,7 +80,7 @@ pub struct Config { )] console_event_buffer_size: Option, - #[structopt( + #[clap( short, long, env = "PICTRS_AGGREGATOR_OPENTELEMETRY_URL", diff --git a/src/main.rs b/src/main.rs index a9d0314..2bffaf8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use actix_web::{App, HttpServer}; use awc::Client; +use clap::Parser; use console_subscriber::ConsoleLayer; use opentelemetry::{ sdk::{propagation::TraceContextPropagator, Resource}, @@ -7,7 +8,6 @@ use opentelemetry::{ }; use opentelemetry_otlp::WithExportConfig; use std::time::Duration; -use structopt::StructOpt; use tracing::subscriber::set_global_default; use tracing_actix_web::TracingLogger; use tracing_awc::Tracing; @@ -21,7 +21,7 @@ use url::Url; #[actix_rt::main] async fn main() -> Result<(), Box> { - let config = pict_rs_aggregator::Config::from_args(); + let config = pict_rs_aggregator::Config::parse(); init_logger( config.opentelemetry_url(),