From 841ca3667e6971ef924a0c4367ec03a0f96c7a71 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 29 Sep 2022 16:28:53 +0300 Subject: allow user to specify who gets greeted Sponsored-by: author --- Cargo.toml | 1 + src/main.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b586046..eb81e2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.0.2", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index e7a11a9..d1d7e5d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,12 @@ +use clap::Parser; + fn main() { - println!("Hello, world!"); + let args = Args::parse(); + println!("hello, {}", args.whom); +} + +#[derive(Parser)] +struct Args { + #[clap(default_value = "world")] + whom: String, } -- cgit v1.2.1