diff --git a/Cargo.lock b/Cargo.lock index 8e0e728..ce62001 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,34 +50,16 @@ dependencies = [ ] [[package]] -name = "argh" -version = "0.1.8" +name = "atty" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7e7e4aa7e40747e023c0761dafcb42333a9517575bbf1241747f68dd3177a62" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "argh_derive", - "argh_shared", + "hermit-abi", + "libc", + "winapi", ] -[[package]] -name = "argh_derive" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69f2bd7ff6ed6414f4e5521bd509bae46454bbd513801767ced3f21a751ab4bc" -dependencies = [ - "argh_shared", - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "argh_shared" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47253b98986dafc7a3e1cf3259194f1f47ac61abb57a57f46ec09e48d004ecda" - [[package]] name = "autocfg" version = "1.1.0" @@ -88,10 +70,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" name = "aviary-cli" version = "0.1.0" dependencies = [ - "argh", - "argh_derive", "base64", "blurhash", + "clap", "image", "iota-crypto", "itertools", @@ -193,6 +174,46 @@ dependencies = [ "generic-array", ] +[[package]] +name = "clap" +version = "3.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29e724a68d9319343bb3328c9cc2dfde263f4b3142ee1059a9980580171c954b" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "once_cell", + "strsim", + "termcolor", + "textwrap", + "unicase", +] + +[[package]] +name = "clap_derive" +version = "3.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13547f7012c01ab4a0e8f8967730ada8f9fdf419e8b6c792788f39cf4e46eefa" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "color_quant" version = "1.1.0" @@ -326,12 +347,24 @@ dependencies = [ ] [[package]] -name = "heck" -version = "0.3.3" +name = "hashbrown" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ - "unicode-segmentation", + "libc", ] [[package]] @@ -372,6 +405,16 @@ dependencies = [ "tiff", ] +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "iota-crypto" version = "0.13.0" @@ -510,6 +553,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "os_str_bytes" +version = "6.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" + [[package]] name = "percent-encoding" version = "2.1.0" @@ -540,6 +589,30 @@ dependencies = [ "universal-hash", ] +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.43" @@ -644,6 +717,12 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "2.4.1" @@ -661,6 +740,24 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "textwrap" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +dependencies = [ + "unicode-width", +] + [[package]] name = "thiserror" version = "1.0.32" @@ -713,6 +810,15 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +[[package]] +name = "unicase" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" +dependencies = [ + "version_check", +] + [[package]] name = "unicode-bidi" version = "0.3.8" @@ -735,10 +841,10 @@ dependencies = [ ] [[package]] -name = "unicode-segmentation" -version = "1.9.0" +name = "unicode-width" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" [[package]] name = "universal-hash" @@ -911,6 +1017,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 a7e7fce..d05f09d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -argh = "0.1.8" -argh_derive = "0.1.8" webp = "0.2.2" itertools = "0.10.3" blurhash = "0.1.1" @@ -30,6 +28,14 @@ version = "0.24.3" default-features = false features = ["gif", "jpeg", "ico", "png", "tiff", "webp", "bmp", "hdr"] +[dependencies.clap] +version = "3.2.12" +features = ["std", "color", "suggestions", "derive", "cargo", "unicode"] + [profile.release] lto = true codegen-units = 1 + +[[bin]] +name = "aviary" +path = "src/main.rs" diff --git a/src/main.rs b/src/main.rs index d70822c..f5c0afd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use std::io::{Read, Write, self}; use std::fs::{File, self, OpenOptions}; use std::path::Path; +use clap::Parser; use errors::AviaryUploadError; use itertools::{Itertools, Either}; use parse::{CreateArgs, Command, DownloadArgs}; @@ -37,7 +38,7 @@ fn trim_url<'a>(base_url: &str, url: &'a str) -> Option<&'a str> { } fn main() { - let args: parse::Args = argh::from_env(); + let args = parse::Args::parse(); let server_no_trailing_slash = args.server.trim_end_matches('/'); let full_server = if server_no_trailing_slash.starts_with("http") { Cow::Borrowed(server_no_trailing_slash) diff --git a/src/parse.rs b/src/parse.rs index 714b0d8..748fa52 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,68 +1,70 @@ use std::path::PathBuf; -use argh_derive::FromArgs; +use clap::{Parser, Subcommand}; -#[derive(FromArgs)] +#[derive(Clone, Debug, Parser)] +#[clap(name = "aviary")] /// Create Aviary galleries pub struct Args { - /// the null pointer server to use - #[argh(option, short = 's', default = "\"envs.sh\".to_owned()")] + /// The null pointer server to use + #[clap(long, short, default_value = "0x0.corviform.gay")] pub server: String, - #[argh(subcommand)] + #[clap(subcommand)] pub command: Command, } -#[derive(FromArgs)] -#[argh(subcommand)] +#[derive(Clone, Debug, Subcommand)] pub enum Command { Create(CreateArgs), Download(DownloadArgs), } -#[derive(FromArgs)] -#[argh(subcommand, name = "create")] -/// upload a series of images to a new gallery +#[derive(Clone, Debug, Parser)] +/// Upload a series of images to a new gallery pub struct CreateArgs { - /// the title of the gallery - #[argh(option, short = 't')] + /// The title of the gallery + #[clap(long, short)] pub title: Option, /// A list of image files to post - #[argh(positional)] - pub images: Vec, + #[clap(required = true, min_values = 1)] + pub images: Vec, } -#[derive(FromArgs)] -#[argh(subcommand, name = "download")] -/// download a gallery +#[derive(Clone, Debug, Parser)] +/// Download a gallery pub struct DownloadArgs { - #[argh(positional)] - /// the file id + /// The file id /// /// This is a short series of characters that identifies the file /// For the url: + /// /// https://0x0.st/asdj.bin#omONdEzrY6SfdBgHn/2P6yG33PeIhuj3/SGm/lDhd2U= + /// /// the file id is asdj + #[clap(required = true)] pub id: String, - #[argh(positional)] - /// the encryption key + /// The encryption key /// /// This is the text after the # sign which is the secret for decrypting the pictures. /// For the url: + /// /// https://0x0.st/asdj.bin#omONdEzrY6SfdBgHn/2P6yG33PeIhuj3/SGm/lDhd2U= + /// /// the encryption key is omONdEzrY6SfdBgHn/2P6yG33PeIhuj3/SGm/lDhd2U= + #[clap(required = true)] pub key: String, - #[argh(option, short='o')] - /// the directory to put the new files into + /// The directory to put the new files into /// /// A directory will be generated based on the name of the gallery if this is not set + #[clap(long, short)] pub output: Option, - #[argh(switch, short='f')] - /// overwrite any existing files in the output directory + /// Overwrite any existing files in the output directory + #[clap(long, short)] pub force: bool, }