From 3ceaaa391c7d93a303ab40d57a455c358c3a3768 Mon Sep 17 00:00:00 2001 From: asonix Date: Wed, 28 Sep 2022 18:23:41 -0500 Subject: [PATCH] Update clap --- Cargo.lock | 34 +++----- Cargo.toml | 4 +- README.md | 165 ++++++++++++++++---------------------- src/config/commandline.rs | 102 +++++++++++------------ src/config/primitives.rs | 22 ++--- 5 files changed, 148 insertions(+), 179 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0456542..5f4347a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -474,26 +474,24 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.2.22" +version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" +checksum = "31c9484ccdc4cb8e7b117cbd0eb150c7c0f04464854e4679aeb50ef03b32d003" dependencies = [ "atty", "bitflags", "clap_derive", "clap_lex", - "indexmap", "once_cell", "strsim", "termcolor", - "textwrap", ] [[package]] name = "clap_derive" -version = "3.2.18" +version = "4.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +checksum = "ca689d7434ce44517a12a89456b2be4d1ea1cafcd8f581978c03d45f5a5c12a7" dependencies = [ "heck", "proc-macro-error", @@ -504,9 +502,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" dependencies = [ "os_str_bytes", ] @@ -1558,7 +1556,7 @@ dependencies = [ [[package]] name = "pict-rs" -version = "0.4.0-beta.1" +version = "0.4.0-beta.2" dependencies = [ "actix-form-data", "actix-rt", @@ -1683,9 +1681,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.44" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd7356a8122b6c4a24a82b278680c73357984ca2fc79a0f9fa6dea7dced7c58" +checksum = "3edcd08cf4fea98d1ae6c9ddd3b8ccb1acac7c3693d62625969a7daa04a2ae36" dependencies = [ "unicode-ident", ] @@ -2170,12 +2168,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "textwrap" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" - [[package]] name = "thiserror" version = "1.0.37" @@ -2343,9 +2335,9 @@ dependencies = [ [[package]] name = "tonic" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11cd56bdb54ef93935a6a79dbd1d91f1ebd4c64150fd61654031fd6b8b775c91" +checksum = "55b9af819e54b8f33d453655bef9b9acc171568fb49523078d0cc4e7484200ec" dependencies = [ "async-stream", "async-trait", @@ -2375,9 +2367,9 @@ dependencies = [ [[package]] name = "tonic-build" -version = "0.8.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fbcd2800e34e743b9ae795867d5f77b535d3a3be69fd731e39145719752df8c" +checksum = "48c6fd7c2581e36d63388a9e04c350c21beb7a8b059580b2e93993c526899ddc" dependencies = [ "prettyplease", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 1e772fe..c2a8b9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "pict-rs" description = "A simple image hosting service" -version = "0.4.0-beta.1" +version = "0.4.0-beta.2" authors = ["asonix "] license = "AGPL-3.0" readme = "README.md" @@ -27,7 +27,7 @@ anyhow = "1.0" async-trait = "0.1.51" awc = { version = "3.0.0", default-features = false, features = ["rustls"] } base64 = "0.13.0" -clap = { version = "3.1.6", features = ["derive"] } +clap = { version = "4.0.2", features = ["derive"] } color-eyre = "0.6" config = "0.13.0" console-subscriber = "0.1" diff --git a/README.md b/README.md index 2b1d71a..09a886b 100644 --- a/README.md +++ b/README.md @@ -9,111 +9,88 @@ _a simple image hosting service_ ## Usage ### Running ``` -pict-rs 0.4.0-beta.1 -asonix +$ pict-rs -h A simple image hosting service -USAGE: - pict-rs [OPTIONS] +Usage: pict-rs [OPTIONS] -OPTIONS: - -c, --config-file - Path to the pict-rs configuration file +Commands: + run Runs the pict-rs web server + filesystem Migrate from the provided filesystem storage + object-storage Migrate from the provided object storage + help Print this message or the help of the given subcommand(s) - --console-address - Address and port to expose tokio-console metrics - - --console-buffer-capacity - Capacity of the console-subscriber Event Buffer - - -h, --help - Print help information - - --log-format - Format of logs printed to stdout - - --log-targets - Log levels to print to stdout, respects RUST_LOG formatting - - --old-db-path - Path to the old pict-rs sled database - - --opentelemetry-service-name - Service Name to use for OpenTelemetry - - --opentelemetry-targets - Log levels to use for OpenTelemetry, respects RUST_LOG formatting - - --opentelemetry-url - URL to send OpenTelemetry metrics - - --save-to - File to save the current configuration for reproducible runs - - -V, --version - Print version information - -SUBCOMMANDS: - filesystem Migrate from the provided filesystem storage - help Print this message or the help of the given subcommand(s) - object-storage Migrate from the provided object storage - run Runs the pict-rs web server +Options: + -c, --config-file + Path to the pict-rs configuration file + --old-db-path + Path to the old pict-rs sled database + --log-format + Format of logs printed to stdout [possible values: compact, json, normal, pretty] + --log-targets + Log levels to print to stdout, respects RUST_LOG formatting + --console-address + Address and port to expose tokio-console metrics + --console-buffer-capacity + Capacity of the console-subscriber Event Buffer + --opentelemetry-url + URL to send OpenTelemetry metrics + --opentelemetry-service-name + Service Name to use for OpenTelemetry + --opentelemetry-targets + Log levels to use for OpenTelemetry, respects RUST_LOG formatting + --save-to + File to save the current configuration for reproducible runs + -h, --help + Print help information + -V, --version + Print version information ``` ``` -pict-rs-run +$ pict-rs run -h Runs the pict-rs web server -USAGE: - pict-rs run [OPTIONS] [SUBCOMMAND] +Usage: pict-rs run [OPTIONS] [COMMAND] -OPTIONS: - -a, --address
- The address and port to bind the pict-rs web server +Commands: + filesystem Run pict-rs with filesystem storage + object-storage Run pict-rs with object storage + help Print this message or the help of the given subcommand(s) - --api-key - The API KEY required to access restricted routes - - -h, --help - Print help information - - --media-cache-duration - How long, in hours, to keep media ingested through the "cached" endpoint - - --media-enable-silent-video - Whether to enable GIF and silent MP4 uploads. Full videos are unsupported - - --media-filters - Which media filters should be enabled on the `process` endpoint - - --media-format - Enforce uploaded media is transcoded to the provided format - - --media-max-area - The maximum area, in pixels, for uploaded media - - --media-max-file-size - The maximum size, in megabytes, for uploaded media - - --media-max-height - The maximum height, in pixels, for uploaded media - - --media-max-width - The maximum width, in pixels, for uploaded media - - --media-preprocess-steps - Optional pre-processing steps for uploaded media - - --media-skip-validate-imports - Whether to validate media on the "import" endpoint - - --worker-id - ID of this pict-rs node. Doesn't do much yet - -SUBCOMMANDS: - filesystem Run pict-rs with filesystem storage - help Print this message or the help of the given subcommand(s) - object-storage Run pict-rs with object storage +Options: + -a, --address
+ The address and port to bind the pict-rs web server + --api-key + The API KEY required to access restricted routes + --worker-id + ID of this pict-rs node. Doesn't do much yet + --media-preprocess-steps + Optional pre-processing steps for uploaded media + --media-skip-validate-imports + Whether to validate media on the "import" endpoint [possible values: true, false] + --media-max-width + The maximum width, in pixels, for uploaded media + --media-max-height + The maximum height, in pixels, for uploaded media + --media-max-area + The maximum area, in pixels, for uploaded media + --media-max-file-size + The maximum size, in megabytes, for uploaded media + --media-max-frame-count + The maximum number of frames allowed for uploaded GIF and MP4s + --media-enable-silent-video + Whether to enable GIF and silent MP4 uploads [possible values: true, false] + --media-enable-full-video + Whether to enable full MP4 uploads [possible values: true, false] + --media-filters + Which media filters should be enabled on the `process` endpoint + --media-format + Enforce uploaded media is transcoded to the provided format [possible values: jpeg, webp, png] + --media-cache-duration + How long, in hours, to keep media ingested through the "cached" endpoint + -h, --help + Print help information (use `--help` for more detail) ``` Try running `help` commands for more runtime configuration options diff --git a/src/config/commandline.rs b/src/config/commandline.rs index bdf752c..9177af2 100644 --- a/src/config/commandline.rs +++ b/src/config/commandline.rs @@ -333,45 +333,45 @@ struct Media { /// Run the pict-rs application #[derive(Debug, Parser)] -#[clap(author, version, about, long_about = None)] +#[command(author, version, about, long_about = None)] pub(super) struct Args { /// Path to the pict-rs configuration file - #[clap(short, long)] + #[arg(short, long)] config_file: Option, /// Path to the old pict-rs sled database - #[clap(long)] + #[arg(long)] old_db_path: Option, /// Format of logs printed to stdout - #[clap(long)] + #[arg(long)] log_format: Option, /// Log levels to print to stdout, respects RUST_LOG formatting - #[clap(long)] + #[arg(long)] log_targets: Option, /// Address and port to expose tokio-console metrics - #[clap(long)] + #[arg(long)] console_address: Option, /// Capacity of the console-subscriber Event Buffer - #[clap(long)] + #[arg(long)] console_buffer_capacity: Option, /// URL to send OpenTelemetry metrics - #[clap(long)] + #[arg(long)] opentelemetry_url: Option, /// Service Name to use for OpenTelemetry - #[clap(long)] + #[arg(long)] opentelemetry_service_name: Option, /// Log levels to use for OpenTelemetry, respects RUST_LOG formatting - #[clap(long)] + #[arg(long)] opentelemetry_targets: Option, /// File to save the current configuration for reproducible runs - #[clap(long)] + #[arg(long)] save_to: Option, - #[clap(subcommand)] + #[command(subcommand)] command: Command, } @@ -381,66 +381,66 @@ enum Command { Run(Run), /// Migrates from one provided media store to another - #[clap(flatten)] + #[command(flatten)] MigrateStore(MigrateStore), } #[derive(Debug, Parser)] struct Run { /// The address and port to bind the pict-rs web server - #[clap(short, long)] + #[arg(short, long)] address: Option, /// The API KEY required to access restricted routes - #[clap(long)] + #[arg(long)] api_key: Option, /// ID of this pict-rs node. Doesn't do much yet - #[clap(long)] + #[arg(long)] worker_id: Option, /// Optional pre-processing steps for uploaded media. /// /// All still images will be put through these steps before saving - #[clap(long)] + #[arg(long)] media_preprocess_steps: Option, /// Whether to validate media on the "import" endpoint - #[clap(long)] + #[arg(long)] media_skip_validate_imports: Option, /// The maximum width, in pixels, for uploaded media - #[clap(long)] + #[arg(long)] media_max_width: Option, /// The maximum height, in pixels, for uploaded media - #[clap(long)] + #[arg(long)] media_max_height: Option, /// The maximum area, in pixels, for uploaded media - #[clap(long)] + #[arg(long)] media_max_area: Option, /// The maximum size, in megabytes, for uploaded media - #[clap(long)] + #[arg(long)] media_max_file_size: Option, /// The maximum number of frames allowed for uploaded GIF and MP4s. - #[clap(long)] + #[arg(long)] media_max_frame_count: Option, /// Whether to enable GIF and silent MP4 uploads - #[clap(long)] + #[arg(long)] media_enable_silent_video: Option, /// Whether to enable full MP4 uploads - #[clap(long)] + #[arg(long)] media_enable_full_video: Option, /// Which media filters should be enabled on the `process` endpoint - #[clap(long)] + #[arg(long)] media_filters: Option>, /// Enforce uploaded media is transcoded to the provided format - #[clap(long)] + #[arg(long)] media_format: Option, /// How long, in hours, to keep media ingested through the "cached" endpoint - #[clap(long)] + #[arg(long)] media_cache_duration: Option, - #[clap(subcommand)] + #[command(subcommand)] store: Option, } @@ -489,60 +489,60 @@ enum MigrateStoreInner { /// Migrate pict-rs' storage from the provided filesystem storage #[derive(Debug, Parser)] struct MigrateFilesystem { - #[clap(flatten)] + #[command(flatten)] from: crate::config::primitives::Filesystem, - #[clap(subcommand)] + #[command(subcommand)] to: MigrateStoreInner, } /// Migrate pict-rs' storage to the provided filesystem storage #[derive(Debug, Parser)] struct MigrateFilesystemInner { - #[clap(flatten)] + #[command(flatten)] to: crate::config::primitives::Filesystem, - #[clap(subcommand)] + #[command(subcommand)] repo: Option, } /// Migrate pict-rs' storage from the provided object storage #[derive(Debug, Parser)] struct MigrateObjectStorage { - #[clap(flatten)] + #[command(flatten)] from: crate::config::primitives::ObjectStorage, - #[clap(subcommand)] + #[command(subcommand)] to: MigrateStoreInner, } /// Migrate pict-rs' storage to the provided object storage #[derive(Debug, Parser)] struct MigrateObjectStorageInner { - #[clap(flatten)] + #[command(flatten)] to: crate::config::primitives::ObjectStorage, - #[clap(subcommand)] + #[command(subcommand)] repo: Option, } /// Run pict-rs with the provided filesystem storage #[derive(Debug, Parser)] struct RunFilesystem { - #[clap(flatten)] + #[command(flatten)] system: Filesystem, - #[clap(subcommand)] + #[command(subcommand)] repo: Option, } /// Run pict-rs with the provided object storage #[derive(Debug, Parser)] struct RunObjectStorage { - #[clap(flatten)] + #[command(flatten)] storage: ObjectStorage, - #[clap(subcommand)] + #[command(subcommand)] repo: Option, } @@ -560,7 +560,7 @@ enum Repo { #[serde(rename_all = "snake_case")] struct Filesystem { /// The path to store uploaded media - #[clap(short, long)] + #[arg(short, long)] path: Option, } @@ -573,36 +573,36 @@ struct ObjectStorage { /// Examples: /// - `http://localhost:9000` /// - `https://s3.dualstack.eu-west-1.amazonaws.com` - #[clap(short, long)] + #[arg(short, long)] endpoint: Url, /// Determines whether to use path style or virtualhost style for accessing objects /// /// When this is true, objects will be fetched from {endpoint}/{bucket_name}/{object} /// When false, objects will be fetched from {bucket_name}.{endpoint}/{object} - #[clap(short, long)] + #[arg(short, long)] use_path_style: bool, /// The bucket in which to store media - #[clap(short, long)] + #[arg(short, long)] bucket_name: Option, /// The region the bucket is located in /// /// For minio deployments, this can just be 'minio' - #[clap(short, long)] + #[arg(short, long)] region: Option, /// The Access Key for the user accessing the bucket - #[clap(short, long)] + #[arg(short, long)] access_key: Option, /// The secret key for the user accessing the bucket - #[clap(short, long)] + #[arg(short, long)] secret_key: Option, /// The session token for accessing the bucket - #[clap(long)] + #[arg(long)] session_token: Option, } @@ -611,12 +611,12 @@ struct ObjectStorage { #[serde(rename_all = "snake_case")] struct Sled { /// The path to store the sled database - #[clap(short, long)] + #[arg(short, long)] #[serde(skip_serializing_if = "Option::is_none")] path: Option, /// The cache capacity, in bytes, allowed to sled for in-memory operations - #[clap(short, long)] + #[arg(short, long)] #[serde(skip_serializing_if = "Option::is_none")] cache_capacity: Option, } diff --git a/src/config/primitives.rs b/src/config/primitives.rs index a0e3795..531ab5d 100644 --- a/src/config/primitives.rs +++ b/src/config/primitives.rs @@ -1,5 +1,5 @@ use crate::magick::ValidInputType; -use clap::ArgEnum; +use clap::ValueEnum; use std::{fmt::Display, path::PathBuf, str::FromStr}; use tracing::Level; use url::Url; @@ -15,7 +15,7 @@ use url::Url; Hash, serde::Deserialize, serde::Serialize, - ArgEnum, + ValueEnum, )] #[serde(rename_all = "snake_case")] pub(crate) enum LogFormat { @@ -36,7 +36,7 @@ pub(crate) enum LogFormat { Hash, serde::Deserialize, serde::Serialize, - ArgEnum, + ValueEnum, )] #[serde(rename_all = "snake_case")] pub(crate) enum ImageFormat { @@ -55,7 +55,7 @@ pub(crate) struct Targets { #[serde(rename_all = "snake_case")] pub(crate) struct Filesystem { /// Path to store media - #[clap(short, long)] + #[arg(short, long)] pub(crate) path: PathBuf, } @@ -68,34 +68,34 @@ pub(crate) struct ObjectStorage { /// Examples: /// - `http://localhost:9000` /// - `https://s3.dualstack.eu-west-1.amazonaws.com` - #[clap(short, long)] + #[arg(short, long)] pub(crate) endpoint: Url, /// Determines whether to use path style or virtualhost style for accessing objects /// /// When this is true, objects will be fetched from {endpoint}/{bucket_name}/{object} /// When false, objects will be fetched from {bucket_name}.{endpoint}/{object} - #[clap(short, long)] + #[arg(short, long)] pub(crate) use_path_style: bool, /// The bucket in which to store media - #[clap(short, long)] + #[arg(short, long)] pub(crate) bucket_name: String, /// The region the bucket is located in - #[clap(short, long)] + #[arg(short, long)] pub(crate) region: String, /// The Access Key for the user accessing the bucket - #[clap(short, long)] + #[arg(short, long)] pub(crate) access_key: String, /// The secret key for the user accessing the bucket - #[clap(short, long)] + #[arg(short, long)] pub(crate) secret_key: String, /// The session token for accessing the bucket - #[clap(long)] + #[arg(long)] #[serde(skip_serializing_if = "Option::is_none")] pub(crate) session_token: Option, }