Update clap

This commit is contained in:
asonix 2022-09-28 18:23:41 -05:00
parent 656b0225af
commit 3ceaaa391c
5 changed files with 148 additions and 179 deletions

34
Cargo.lock generated
View file

@ -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",

View file

@ -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 <asonix@asonix.dog>"]
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"

165
README.md
View file

@ -9,111 +9,88 @@ _a simple image hosting service_
## Usage
### Running
```
pict-rs 0.4.0-beta.1
asonix <asonix@asonix.dog>
$ pict-rs -h
A simple image hosting service
USAGE:
pict-rs [OPTIONS] <SUBCOMMAND>
Usage: pict-rs [OPTIONS] <COMMAND>
OPTIONS:
-c, --config-file <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 <CONSOLE_ADDRESS>
Address and port to expose tokio-console metrics
--console-buffer-capacity <CONSOLE_BUFFER_CAPACITY>
Capacity of the console-subscriber Event Buffer
-h, --help
Print help information
--log-format <LOG_FORMAT>
Format of logs printed to stdout
--log-targets <LOG_TARGETS>
Log levels to print to stdout, respects RUST_LOG formatting
--old-db-path <OLD_DB_PATH>
Path to the old pict-rs sled database
--opentelemetry-service-name <OPENTELEMETRY_SERVICE_NAME>
Service Name to use for OpenTelemetry
--opentelemetry-targets <OPENTELEMETRY_TARGETS>
Log levels to use for OpenTelemetry, respects RUST_LOG formatting
--opentelemetry-url <OPENTELEMETRY_URL>
URL to send OpenTelemetry metrics
--save-to <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 <CONFIG_FILE>
Path to the pict-rs configuration file
--old-db-path <OLD_DB_PATH>
Path to the old pict-rs sled database
--log-format <LOG_FORMAT>
Format of logs printed to stdout [possible values: compact, json, normal, pretty]
--log-targets <LOG_TARGETS>
Log levels to print to stdout, respects RUST_LOG formatting
--console-address <CONSOLE_ADDRESS>
Address and port to expose tokio-console metrics
--console-buffer-capacity <CONSOLE_BUFFER_CAPACITY>
Capacity of the console-subscriber Event Buffer
--opentelemetry-url <OPENTELEMETRY_URL>
URL to send OpenTelemetry metrics
--opentelemetry-service-name <OPENTELEMETRY_SERVICE_NAME>
Service Name to use for OpenTelemetry
--opentelemetry-targets <OPENTELEMETRY_TARGETS>
Log levels to use for OpenTelemetry, respects RUST_LOG formatting
--save-to <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 <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 <API_KEY>
The API KEY required to access restricted routes
-h, --help
Print help information
--media-cache-duration <MEDIA_CACHE_DURATION>
How long, in hours, to keep media ingested through the "cached" endpoint
--media-enable-silent-video <MEDIA_ENABLE_SILENT_VIDEO>
Whether to enable GIF and silent MP4 uploads. Full videos are unsupported
--media-filters <MEDIA_FILTERS>
Which media filters should be enabled on the `process` endpoint
--media-format <MEDIA_FORMAT>
Enforce uploaded media is transcoded to the provided format
--media-max-area <MEDIA_MAX_AREA>
The maximum area, in pixels, for uploaded media
--media-max-file-size <MEDIA_MAX_FILE_SIZE>
The maximum size, in megabytes, for uploaded media
--media-max-height <MEDIA_MAX_HEIGHT>
The maximum height, in pixels, for uploaded media
--media-max-width <MEDIA_MAX_WIDTH>
The maximum width, in pixels, for uploaded media
--media-preprocess-steps <MEDIA_PREPROCESS_STEPS>
Optional pre-processing steps for uploaded media
--media-skip-validate-imports <MEDIA_SKIP_VALIDATE_IMPORTS>
Whether to validate media on the "import" endpoint
--worker-id <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 <ADDRESS>
The address and port to bind the pict-rs web server
--api-key <API_KEY>
The API KEY required to access restricted routes
--worker-id <WORKER_ID>
ID of this pict-rs node. Doesn't do much yet
--media-preprocess-steps <MEDIA_PREPROCESS_STEPS>
Optional pre-processing steps for uploaded media
--media-skip-validate-imports <MEDIA_SKIP_VALIDATE_IMPORTS>
Whether to validate media on the "import" endpoint [possible values: true, false]
--media-max-width <MEDIA_MAX_WIDTH>
The maximum width, in pixels, for uploaded media
--media-max-height <MEDIA_MAX_HEIGHT>
The maximum height, in pixels, for uploaded media
--media-max-area <MEDIA_MAX_AREA>
The maximum area, in pixels, for uploaded media
--media-max-file-size <MEDIA_MAX_FILE_SIZE>
The maximum size, in megabytes, for uploaded media
--media-max-frame-count <MEDIA_MAX_FRAME_COUNT>
The maximum number of frames allowed for uploaded GIF and MP4s
--media-enable-silent-video <MEDIA_ENABLE_SILENT_VIDEO>
Whether to enable GIF and silent MP4 uploads [possible values: true, false]
--media-enable-full-video <MEDIA_ENABLE_FULL_VIDEO>
Whether to enable full MP4 uploads [possible values: true, false]
--media-filters <MEDIA_FILTERS>
Which media filters should be enabled on the `process` endpoint
--media-format <MEDIA_FORMAT>
Enforce uploaded media is transcoded to the provided format [possible values: jpeg, webp, png]
--media-cache-duration <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

View file

@ -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<PathBuf>,
/// Path to the old pict-rs sled database
#[clap(long)]
#[arg(long)]
old_db_path: Option<PathBuf>,
/// Format of logs printed to stdout
#[clap(long)]
#[arg(long)]
log_format: Option<LogFormat>,
/// Log levels to print to stdout, respects RUST_LOG formatting
#[clap(long)]
#[arg(long)]
log_targets: Option<Targets>,
/// Address and port to expose tokio-console metrics
#[clap(long)]
#[arg(long)]
console_address: Option<SocketAddr>,
/// Capacity of the console-subscriber Event Buffer
#[clap(long)]
#[arg(long)]
console_buffer_capacity: Option<usize>,
/// URL to send OpenTelemetry metrics
#[clap(long)]
#[arg(long)]
opentelemetry_url: Option<Url>,
/// Service Name to use for OpenTelemetry
#[clap(long)]
#[arg(long)]
opentelemetry_service_name: Option<String>,
/// Log levels to use for OpenTelemetry, respects RUST_LOG formatting
#[clap(long)]
#[arg(long)]
opentelemetry_targets: Option<Targets>,
/// File to save the current configuration for reproducible runs
#[clap(long)]
#[arg(long)]
save_to: Option<PathBuf>,
#[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<SocketAddr>,
/// The API KEY required to access restricted routes
#[clap(long)]
#[arg(long)]
api_key: Option<String>,
/// ID of this pict-rs node. Doesn't do much yet
#[clap(long)]
#[arg(long)]
worker_id: Option<String>,
/// 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<String>,
/// Whether to validate media on the "import" endpoint
#[clap(long)]
#[arg(long)]
media_skip_validate_imports: Option<bool>,
/// The maximum width, in pixels, for uploaded media
#[clap(long)]
#[arg(long)]
media_max_width: Option<usize>,
/// The maximum height, in pixels, for uploaded media
#[clap(long)]
#[arg(long)]
media_max_height: Option<usize>,
/// The maximum area, in pixels, for uploaded media
#[clap(long)]
#[arg(long)]
media_max_area: Option<usize>,
/// The maximum size, in megabytes, for uploaded media
#[clap(long)]
#[arg(long)]
media_max_file_size: Option<usize>,
/// The maximum number of frames allowed for uploaded GIF and MP4s.
#[clap(long)]
#[arg(long)]
media_max_frame_count: Option<usize>,
/// Whether to enable GIF and silent MP4 uploads
#[clap(long)]
#[arg(long)]
media_enable_silent_video: Option<bool>,
/// Whether to enable full MP4 uploads
#[clap(long)]
#[arg(long)]
media_enable_full_video: Option<bool>,
/// Which media filters should be enabled on the `process` endpoint
#[clap(long)]
#[arg(long)]
media_filters: Option<Vec<String>>,
/// Enforce uploaded media is transcoded to the provided format
#[clap(long)]
#[arg(long)]
media_format: Option<ImageFormat>,
/// How long, in hours, to keep media ingested through the "cached" endpoint
#[clap(long)]
#[arg(long)]
media_cache_duration: Option<i64>,
#[clap(subcommand)]
#[command(subcommand)]
store: Option<RunStore>,
}
@ -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<Repo>,
}
/// 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<Repo>,
}
/// 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<Repo>,
}
/// 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<Repo>,
}
@ -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<PathBuf>,
}
@ -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<String>,
/// The region the bucket is located in
///
/// For minio deployments, this can just be 'minio'
#[clap(short, long)]
#[arg(short, long)]
region: Option<String>,
/// The Access Key for the user accessing the bucket
#[clap(short, long)]
#[arg(short, long)]
access_key: Option<String>,
/// The secret key for the user accessing the bucket
#[clap(short, long)]
#[arg(short, long)]
secret_key: Option<String>,
/// The session token for accessing the bucket
#[clap(long)]
#[arg(long)]
session_token: Option<String>,
}
@ -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<PathBuf>,
/// 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<u64>,
}

View file

@ -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<String>,
}