From a511ca0e764824661c083e12947bee1f3d802342 Mon Sep 17 00:00:00 2001 From: Sridhar Ratnakumar Date: Sun, 23 Jul 2023 10:07:10 -0400 Subject: [PATCH] Switch to clap, to demonstrate non-rust deps --- Cargo.lock | 265 ++++++++++++++++++++++++++++++++++++++++++++++++---- Cargo.toml | 2 +- flake.nix | 120 +++++++++++++----------- src/main.rs | 19 ++-- 4 files changed, 323 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 28057e3..303b00f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,32 +3,174 @@ version = 3 [[package]] -name = "argh" -version = "0.1.10" +name = "anstream" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab257697eb9496bf75526f0217b5ed64636a9cfafa78b8365c71bd283fcef93e" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" dependencies = [ - "argh_derive", - "argh_shared", + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", ] [[package]] -name = "argh_derive" -version = "0.1.10" +name = "anstyle" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b382dbd3288e053331f03399e1db106c9fb0d8562ad62cb04859ae926f324fa6" +checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" dependencies = [ - "argh_shared", + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +dependencies = [ + "anstyle", + "windows-sys", +] + +[[package]] +name = "bitflags" +version = "2.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "clap" +version = "4.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fd304a20bff958a57f04c4e96a2e7594cc4490a0e809cbd48bb6437edaa452d" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.3.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01c6a3f08f1fe5662a35cfe393aec09c4df95f60ee93b7556505260f75eee9e1" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +dependencies = [ + "heck", "proc-macro2", "quote", "syn", ] [[package]] -name = "argh_shared" -version = "0.1.10" +name = "clap_lex" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64cb94155d965e3d37ffbbe7cc5b82c3dd79dd33bd48e536f73d2cfb8d85506f" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "linux-raw-sys" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "proc-macro2" @@ -52,14 +194,33 @@ dependencies = [ name = "rust-nix-template" version = "0.1.0" dependencies = [ - "argh", + "clap", ] [[package]] -name = "syn" -version = "1.0.109" +name = "rustix" +version = "0.38.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "2.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0" dependencies = [ "proc-macro2", "quote", @@ -71,3 +232,75 @@ name = "unicode-ident" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/Cargo.toml b/Cargo.toml index 8ff0e89..5790d17 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] -argh = "0.1.10" +clap = { version = "4.3.14", features = ["derive"] } diff --git a/flake.nix b/flake.nix index d12beaa..662c776 100644 --- a/flake.nix +++ b/flake.nix @@ -18,70 +18,76 @@ inputs.mission-control.flakeModule inputs.flake-root.flakeModule ]; - perSystem = { config, self', pkgs, lib, system, ... }: { - # Rust package - packages.default = - let - cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); - in - pkgs.rustPlatform.buildRustPackage { - inherit (cargoToml.package) name version; - src = ./.; - cargoLock.lockFile = ./Cargo.lock; - }; + perSystem = { config, self', pkgs, lib, system, ... }: - # Rust dev environment - devShells.default = pkgs.mkShell { - inputsFrom = [ - config.treefmt.build.devShell - config.mission-control.devShell - config.flake-root.devShell + let + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + nonRustDeps = [ + pkgs.libiconv ]; - shellHook = '' - # For rust-analyzer 'hover' tooltips to work. - export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} - ''; - nativeBuildInputs = with pkgs; [ - rustc - cargo - cargo-watch - rust-analyzer - ]; - }; + in + { + # Rust package + packages.default = + pkgs.rustPlatform.buildRustPackage { + inherit (cargoToml.package) name version; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + }; - # Add your auto-formatters here. - # cf. https://numtide.github.io/treefmt/ - treefmt.config = { - projectRootFile = "flake.nix"; - programs = { - nixpkgs-fmt.enable = true; - rustfmt.enable = true; - }; - }; - - # Makefile'esque but in Nix. Add your dev scripts here. - # cf. https://github.com/Platonic-Systems/mission-control - mission-control.scripts = { - fmt = { - exec = config.treefmt.build.wrapper; - description = "Auto-format project tree"; - }; - - run = { - exec = '' - cargo run "$@" + # Rust dev environment + devShells.default = pkgs.mkShell { + inputsFrom = [ + config.treefmt.build.devShell + config.mission-control.devShell + config.flake-root.devShell + ]; + shellHook = '' + # For rust-analyzer 'hover' tooltips to work. + export RUST_SRC_PATH=${pkgs.rustPlatform.rustLibSrc} ''; - description = "Run the project executable"; + buildInputs = nonRustDeps; + nativeBuildInputs = with pkgs; [ + rustc + cargo + cargo-watch + rust-analyzer + ]; }; - watch = { - exec = '' - set -x - cargo watch -x "run -- $*" - ''; - description = "Watch for changes and run the project executable"; + # Add your auto-formatters here. + # cf. https://numtide.github.io/treefmt/ + treefmt.config = { + projectRootFile = "flake.nix"; + programs = { + nixpkgs-fmt.enable = true; + rustfmt.enable = true; + }; + }; + + # Makefile'esque but in Nix. Add your dev scripts here. + # cf. https://github.com/Platonic-Systems/mission-control + mission-control.scripts = { + fmt = { + exec = config.treefmt.build.wrapper; + description = "Auto-format project tree"; + }; + + run = { + exec = '' + cargo run "$@" + ''; + description = "Run the project executable"; + }; + + watch = { + exec = '' + set -x + cargo watch -x "run -- $*" + ''; + description = "Watch for changes and run the project executable"; + }; }; }; - }; }; } diff --git a/src/main.rs b/src/main.rs index 9990f39..78591e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,22 @@ -use argh::FromArgs; +use clap::Parser; -#[derive(FromArgs, Debug)] +#[derive(Parser, Debug)] +#[clap(author = "Sridhar Ratnakumar", version, about)] /// Application configuration -struct Config { +struct Args { /// whether to be verbose - #[argh(switch, short = 'v')] + #[arg(short = 'v')] verbose: bool, /// an optional name to green - #[argh(option)] + #[arg()] name: Option, } fn main() { - let cfg: Config = argh::from_env(); - if cfg.verbose { - println!("DEBUG {cfg:?}"); + let args = Args::parse(); + if args.verbose { + println!("DEBUG {args:?}"); } - println!("Hello {}!", cfg.name.unwrap_or("world".to_string())); + println!("Hello {}!", args.name.unwrap_or("world".to_string())); }