Use clap directly
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Aode (lion) 2022-05-28 11:53:46 -05:00
parent 72b4508c46
commit e2495c3c02
5 changed files with 94 additions and 76 deletions

113
Cargo.lock generated
View file

@ -450,17 +450,41 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.34.0" version = "3.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b"
dependencies = [ dependencies = [
"ansi_term",
"atty", "atty",
"bitflags", "bitflags",
"clap_derive",
"clap_lex",
"indexmap",
"lazy_static",
"strsim", "strsim",
"termcolor",
"textwrap", "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]] [[package]]
@ -823,6 +847,12 @@ dependencies = [
"unicode-segmentation", "unicode-segmentation",
] ]
[[package]]
name = "heck"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.19" version = "0.1.19"
@ -1259,6 +1289,12 @@ dependencies = [
"tonic-build", "tonic-build",
] ]
[[package]]
name = "os_str_bytes"
version = "6.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.11.2" version = "0.11.2"
@ -1337,6 +1373,7 @@ dependencies = [
"actix-web", "actix-web",
"awc", "awc",
"bcrypt", "bcrypt",
"clap",
"console-subscriber", "console-subscriber",
"dotenv", "dotenv",
"mime", "mime",
@ -1348,7 +1385,6 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"sled", "sled",
"structopt",
"thiserror", "thiserror",
"tokio", "tokio",
"tracing", "tracing",
@ -1461,7 +1497,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5" checksum = "62941722fb675d463659e49c4f3fe1fe792ff24fe5bbaa9c08cd3b98a1c354f5"
dependencies = [ dependencies = [
"bytes", "bytes",
"heck", "heck 0.3.3",
"itertools", "itertools",
"lazy_static", "lazy_static",
"log", "log",
@ -1780,33 +1816,9 @@ dependencies = [
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.8.0" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[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",
]
[[package]] [[package]]
name = "syn" name = "syn"
@ -1840,14 +1852,20 @@ dependencies = [
] ]
[[package]] [[package]]
name = "textwrap" name = "termcolor"
version = "0.11.0" version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [ 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]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.31" version = "1.0.31"
@ -2277,12 +2295,6 @@ version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]] [[package]]
name = "url" name = "url"
version = "2.2.2" version = "2.2.2"
@ -2321,12 +2333,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.4" version = "0.9.4"
@ -2436,6 +2442,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 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]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"

View file

@ -19,6 +19,7 @@ actix-rt = "2.6.0"
actix-web = { version = "4.0.0", default-features = false } actix-web = { version = "4.0.0", default-features = false }
awc = { version = "3.0.0", default-features = false } awc = { version = "3.0.0", default-features = false }
bcrypt = "0.13" bcrypt = "0.13"
clap = { version = "3.1.18", features = ["derive", "env"] }
console-subscriber = "0.1" console-subscriber = "0.1"
mime = "0.3" mime = "0.3"
minify-html = "0.8.0" minify-html = "0.8.0"
@ -28,7 +29,6 @@ qrcodegen = "1.7"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
sled = { version = "0.34.7", features = ["zstd"] } sled = { version = "0.34.7", features = ["zstd"] }
structopt = "0.3.21"
tokio = { version = "1", default-features = false, features = ["sync"] } tokio = { version = "1", default-features = false, features = ["sync"] }
thiserror = "1.0" thiserror = "1.0"
tracing = "0.1" tracing = "0.1"

View file

@ -4,33 +4,36 @@ _a simple image aggregator for pict-rs_
## Usage ## Usage
### Running ### Running
``` ```
pict-rs-aggregator 0.1.32 pict-rs-aggregator
USAGE: USAGE:
pict-rs-aggregator [OPTIONS] pict-rs-aggregator [OPTIONS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS: OPTIONS:
-a, --addr <addr> -a, --addr <ADDR>
The address and port the server binds to [env: PICTRS_AGGREGATOR_ADDR=] [default: 0.0.0.0:8082] The address and port the server binds to [env: PICTRS_AGGREGATOR_ADDR=] [default:
0.0.0.0:8082]
-c, --console-event-buffer-size <console-event-buffer-size> -c, --console-event-buffer-size <CONSOLE_EVENT_BUFFER_SIZE>
The number of events to buffer in console. When unset, console is disabled [env: The number of events to buffer in console. When unset, console is disabled [env:
PICTRS_AGGREGATOR_CONSOLE_EVENT_BUFFER_SIZE=] PICTRS_AGGREGATOR_CONSOLE_EVENT_BUFFER_SIZE=]
-d, --database-path <database-path>
The path to the database [env: PICTRS_AGGREGATOR_DATABASE=] [default: sled/db-0-34]
-o, --opentelemetry-url <opentelemetry-url> -d, --database-path <DATABASE_PATH>
The path to the database [env: PICTRS_AGGREGATOR_DATABASE=] [default: sled/db-0-34]
-h, --help
Print help information
-o, --opentelemetry-url <OPENTELEMETRY_URL>
URL for the OpenTelemetry Colletor [env: PICTRS_AGGREGATOR_OPENTELEMETRY_URL=] URL for the OpenTelemetry Colletor [env: PICTRS_AGGREGATOR_OPENTELEMETRY_URL=]
-s, --sled-cache-capacity <sled-cache-capacity> -s, --sled-cache-capacity <SLED_CACHE_CAPACITY>
The amount of RAM, in bytes, that sled is allowed to consume. Increasing this value can improve performance The amount of RAM, in bytes, that sled is allowed to consume. Increasing this value can
[env: PICTRS_AGGREGATOR_SLED_CACHE_CAPACITY=] [default: 67108864] improve performance [env: PICTRS_AGGREGATOR_SLED_CACHE_CAPACITY=] [default: 67108864]
-u, --upstream <upstream>
The url of the upstream pict-rs server [env: PICTRS_AGGREGATOR_UPSTREAM=] [default: http://localhost:8080] -u, --upstream <UPSTREAM>
The url of the upstream pict-rs server [env: PICTRS_AGGREGATOR_UPSTREAM=] [default:
http://localhost:8080]
``` ```
#### Examples #### Examples

View file

@ -9,6 +9,7 @@ use actix_web::{
web, HttpRequest, HttpResponse, HttpResponseBuilder, ResponseError, web, HttpRequest, HttpResponse, HttpResponseBuilder, ResponseError,
}; };
use awc::Client; use awc::Client;
use clap::Parser;
use sled::Db; use sled::Db;
use std::{ use std::{
io::Cursor, io::Cursor,
@ -16,7 +17,6 @@ use std::{
path::{Path, PathBuf}, path::{Path, PathBuf},
time::SystemTime, time::SystemTime,
}; };
use structopt::StructOpt;
use tracing_error::SpanTrace; use tracing_error::SpanTrace;
use url::Url; use url::Url;
use uuid::Uuid; use uuid::Uuid;
@ -34,9 +34,9 @@ mod ui;
use self::{connection::Connection, middleware::ValidToken, store::Store}; use self::{connection::Connection, middleware::ValidToken, store::Store};
#[derive(Clone, Debug, StructOpt)] #[derive(Clone, Debug, Parser)]
pub struct Config { pub struct Config {
#[structopt( #[clap(
short, short,
long, long,
env = "PICTRS_AGGREGATOR_ADDR", env = "PICTRS_AGGREGATOR_ADDR",
@ -45,7 +45,7 @@ pub struct Config {
)] )]
addr: SocketAddr, addr: SocketAddr,
#[structopt( #[clap(
short, short,
long, long,
env = "PICTRS_AGGREGATOR_UPSTREAM", env = "PICTRS_AGGREGATOR_UPSTREAM",
@ -54,7 +54,7 @@ pub struct Config {
)] )]
upstream: Url, upstream: Url,
#[structopt( #[clap(
short, short,
long, long,
env = "PICTRS_AGGREGATOR_DATABASE", env = "PICTRS_AGGREGATOR_DATABASE",
@ -63,7 +63,7 @@ pub struct Config {
)] )]
database_path: PathBuf, database_path: PathBuf,
#[structopt( #[clap(
short, short,
long, long,
env = "PICTRS_AGGREGATOR_SLED_CACHE_CAPACITY", env = "PICTRS_AGGREGATOR_SLED_CACHE_CAPACITY",
@ -72,7 +72,7 @@ pub struct Config {
)] )]
sled_cache_capacity: u64, sled_cache_capacity: u64,
#[structopt( #[clap(
short, short,
long, long,
env = "PICTRS_AGGREGATOR_CONSOLE_EVENT_BUFFER_SIZE", env = "PICTRS_AGGREGATOR_CONSOLE_EVENT_BUFFER_SIZE",
@ -80,7 +80,7 @@ pub struct Config {
)] )]
console_event_buffer_size: Option<usize>, console_event_buffer_size: Option<usize>,
#[structopt( #[clap(
short, short,
long, long,
env = "PICTRS_AGGREGATOR_OPENTELEMETRY_URL", env = "PICTRS_AGGREGATOR_OPENTELEMETRY_URL",

View file

@ -1,5 +1,6 @@
use actix_web::{App, HttpServer}; use actix_web::{App, HttpServer};
use awc::Client; use awc::Client;
use clap::Parser;
use console_subscriber::ConsoleLayer; use console_subscriber::ConsoleLayer;
use opentelemetry::{ use opentelemetry::{
sdk::{propagation::TraceContextPropagator, Resource}, sdk::{propagation::TraceContextPropagator, Resource},
@ -7,7 +8,6 @@ use opentelemetry::{
}; };
use opentelemetry_otlp::WithExportConfig; use opentelemetry_otlp::WithExportConfig;
use std::time::Duration; use std::time::Duration;
use structopt::StructOpt;
use tracing::subscriber::set_global_default; use tracing::subscriber::set_global_default;
use tracing_actix_web::TracingLogger; use tracing_actix_web::TracingLogger;
use tracing_awc::Tracing; use tracing_awc::Tracing;
@ -21,7 +21,7 @@ use url::Url;
#[actix_rt::main] #[actix_rt::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = pict_rs_aggregator::Config::from_args(); let config = pict_rs_aggregator::Config::parse();
init_logger( init_logger(
config.opentelemetry_url(), config.opentelemetry_url(),