From ec62690741fcaa23d458c3b31c309b6dad6019db Mon Sep 17 00:00:00 2001 From: "afaqramazanova996@gmail.com" Date: Fri, 13 Dec 2024 12:48:24 -0500 Subject: [PATCH] adding clap --- multiplication2/Cargo.lock | 56 ++++++++++++++++++++++++++++++++++++- multiplication2/Cargo.toml | 3 +- multiplication2/src/main.rs | 19 ++++++++++--- 3 files changed, 72 insertions(+), 6 deletions(-) diff --git a/multiplication2/Cargo.lock b/multiplication2/Cargo.lock index 2aa66d1..f6fc10c 100644 --- a/multiplication2/Cargo.lock +++ b/multiplication2/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "anstream" @@ -67,6 +67,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", + "clap_derive", ] [[package]] @@ -81,6 +82,18 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_derive" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "clap_lex" version = "0.7.2" @@ -93,6 +106,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" +[[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" @@ -113,6 +132,24 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" +[[package]] +name = "proc-macro2" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + [[package]] name = "shlex" version = "1.3.0" @@ -153,6 +190,23 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +[[package]] +name = "syn" +version = "2.0.90" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" + [[package]] name = "utf8parse" version = "0.2.2" diff --git a/multiplication2/Cargo.toml b/multiplication2/Cargo.toml index ea8239c..b42f4e1 100644 --- a/multiplication2/Cargo.toml +++ b/multiplication2/Cargo.toml @@ -4,5 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] -clap = "4.5.20" +clap = { version = "4.0", features = ["derive"] } sqlite = "0.36.1" + diff --git a/multiplication2/src/main.rs b/multiplication2/src/main.rs index c4a8799..5099d6a 100644 --- a/multiplication2/src/main.rs +++ b/multiplication2/src/main.rs @@ -1,8 +1,19 @@ +use clap::Parser; use multiplication2::multiplication; +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + a: i32, + b: i32, +} + fn main() { - let a = 5; - let b = 15; - let result = multiplication(&a, &b); - println!("The multiplication of {} and {} is {}", a, b, result); + let args = Args::parse(); + + let result = multiplication(&args.a, &args.b); + println!( + "The multiplication of {} and {} is {}", + args.a, args.b, result + ); }