Start building the basic set of command-line flags
- ID
84bf7d4- date
2024-08-19 12:20:44+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
44ead67- message
Start building the basic set of command-line flags- changed files
4 files, 87 additions, 2 deletions
Changed files
Cargo.lock (5170) → Cargo.lock (6539)
diff --git a/Cargo.lock b/Cargo.lock
index 011fee4..2a0b53c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -58,6 +58,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019"
dependencies = [
"clap_builder",
+ "clap_derive",
]
[[package]]
@@ -73,6 +74,18 @@ dependencies = [
]
[[package]]
+name = "clap_derive"
+version = "4.5.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0"
+dependencies = [
+ "heck",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "clap_lex"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -92,18 +105,59 @@ dependencies = [
]
[[package]]
+name = "heck"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
+
+[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
+name = "proc-macro2"
+version = "1.0.86"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.36"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
+name = "syn"
+version = "2.0.75"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f6af063034fc1935ede7be0122941bafa9bacb949334d090b77ca98b5817c7d9"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
+
+[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
Cargo.toml (98) → Cargo.toml (135)
diff --git a/Cargo.toml b/Cargo.toml
index 3dca501..0f686cf 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"
[dependencies]
-clap = "4"
+clap = { version = "4", features = ["derive"] }
README.md (0) → README.md (74)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..202b661
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+create-thumbnail PATH [--width=WIDTH | --height=HEIGHT] --out-dir=OUT_DIR
src/main.rs (45) → src/main.rs (633)
diff --git a/src/main.rs b/src/main.rs
index e7a11a9..4efb355 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,33 @@
+use std::path::PathBuf;
+
+use clap::{ArgGroup, Parser};
+
+#[derive(Debug, Parser)]
+#[clap(version, about)]
+#[clap(group(
+ ArgGroup::new("dimensions")
+ .required(true)
+ .args(&["height", "width"]),
+))]
+struct Cli {
+ /// Path to the image to be thumbnailed
+ path: PathBuf,
+
+ /// Path to the directory to save the thumbnail in
+ #[arg(long)]
+ out_dir: PathBuf,
+
+ /// Height of the thumbnail to create
+ #[arg(long)]
+ height: Option<usize>,
+
+ /// Width of the thumbnail to create
+ #[arg(long)]
+ width: Option<usize>,
+}
+
fn main() {
- println!("Hello, world!");
+ let cli = Cli::parse();
+
+ println!("args = {:?}", cli);
}