From 31c259271d4d02a3d5b59ffb51831ba31c7432dd Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Mon, 26 Jun 2023 15:24:39 -0400 Subject: [PATCH] Use a rust crate for demo --- Cargo.lock | 110 +++++++++++++++++----------------------------------- Cargo.toml | 2 +- src/main.rs | 24 ++++++------ 3 files changed, 48 insertions(+), 88 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5318ae9..28057e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,113 +1,73 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] -name = "ansi_term" -version = "0.11.0" +name = "argh" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "ab257697eb9496bf75526f0217b5ed64636a9cfafa78b8365c71bd283fcef93e" dependencies = [ - "winapi", + "argh_derive", + "argh_shared", ] [[package]] -name = "atty" -version = "0.2.14" +name = "argh_derive" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +checksum = "b382dbd3288e053331f03399e1db106c9fb0d8562ad62cb04859ae926f324fa6" dependencies = [ - "hermit-abi", - "libc", - "winapi", + "argh_shared", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "bitflags" -version = "1.2.1" +name = "argh_shared" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "64cb94155d965e3d37ffbbe7cc5b82c3dd79dd33bd48e536f73d2cfb8d85506f" [[package]] -name = "clap" -version = "2.33.3" +name = "proc-macro2" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" dependencies = [ - "ansi_term", - "atty", - "bitflags", - "strsim", - "textwrap", - "unicode-width", - "vec_map", + "unicode-ident", ] [[package]] -name = "hermit-abi" -version = "0.1.18" +name = "quote" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ - "libc", + "proc-macro2", ] -[[package]] -name = "libc" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" - [[package]] name = "rust-nix-template" version = "0.1.0" dependencies = [ - "clap", + "argh", ] [[package]] -name = "strsim" -version = "0.8.0" +name = "syn" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "unicode-width", + "proc-macro2", + "quote", + "unicode-ident", ] [[package]] -name = "unicode-width" -version = "0.1.8" +name = "unicode-ident" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" - -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" diff --git a/Cargo.toml b/Cargo.toml index a0b6d37..9152434 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,4 +8,4 @@ version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clap = "2.33.3" +argh = "0.1.10" diff --git a/src/main.rs b/src/main.rs index 25c12be..a6f5012 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,21 @@ use argh::FromArgs; -#[derive(FromArgs)] +#[derive(FromArgs, Debug)] /// Reach new heights. -struct GoUp { - /// whether or not to jump - #[argh(switch, short = 'j')] - jump: bool, +struct Config { + /// whether to be verbose + #[argh(switch, short = 'v')] + verbose: bool, - /// how high to go + /// an optional name to green #[argh(option)] - height: usize, - - /// an optional nickname for the pilot - #[argh(option)] - pilot_nickname: Option, + name: Option, } fn main() { - let up: GoUp = argh::from_env(); + let cfg: Config = argh::from_env(); + if cfg.verbose { + println!("DEBUG {cfg:?}"); + } + println!("Hello {}!", cfg.name.unwrap_or("world".to_string())); }