From 2654c57e25218247abbec6864b857d1d95493cac Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 8 Sep 2023 17:47:14 +0300 Subject: refactor: use current clap instead of structopt for command line Sponsored-by: author --- Cargo.lock | 188 ++++++++++++++++++++++++++++++++----------------------- Cargo.toml | 2 +- src/bin/vmadm.rs | 45 ++++++------- 3 files changed, 129 insertions(+), 106 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a6e7339..8a77f08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,54 @@ dependencies = [ "winapi", ] +[[package]] +name = "anstream" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f58811cfac344940f1a400b6e6231ce35171f614f26439e80f8c1465c5cc0c" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15c4c2c83f81532e5845a733998b6971faca23490340a418e9b72a3ec9de12ea" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58f54d10c6dfa51283a066ceab3ec1ab78d13fae00aa49243a45e4571fb79dfd" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", +] + [[package]] name = "anyhow" version = "1.0.70" @@ -52,7 +100,7 @@ dependencies = [ "bitflags", "cexpr", "clang-sys", - "clap", + "clap 2.34.0", "env_logger 0.9.3", "lazy_static", "lazycell", @@ -125,12 +173,58 @@ dependencies = [ "ansi_term", "atty", "bitflags", - "strsim", + "strsim 0.8.0", "textwrap", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a13b88d2c62ff462f88e4a121f17a82c1af05693a2f192b5c38d14de73c19f6" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bb9faaa7c2ef94b2743a21f5a29e6f0010dff4caa69ac8e9d6cf8b6fa74da08" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim 0.10.0", +] + +[[package]] +name = "clap_derive" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "directories-next" version = "2.0.0" @@ -239,12 +333,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "heck" -version = "0.3.3" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" @@ -433,30 +524,6 @@ dependencies = [ "log", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.56" @@ -570,7 +637,7 @@ checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn", ] [[package]] @@ -615,39 +682,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] -name = "structopt" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" -dependencies = [ - "clap", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" @@ -708,7 +746,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.13", + "syn", ] [[package]] @@ -717,12 +755,6 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - [[package]] name = "unicode-width" version = "0.1.10" @@ -730,16 +762,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] -name = "vec_map" -version = "0.8.2" +name = "utf8parse" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] -name = "version_check" -version = "0.9.4" +name = "vec_map" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "virt" @@ -768,6 +800,7 @@ version = "0.4.1" dependencies = [ "anyhow", "bytesize", + "clap 4.4.2", "directories-next", "home-dir", "lazy_static", @@ -778,7 +811,6 @@ dependencies = [ "serde_json", "serde_yaml", "shell-words", - "structopt", "tempfile", "thiserror", "virt", diff --git a/Cargo.toml b/Cargo.toml index bea87a3..0f7dcb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ repository = "https://gitlab.com/larswirzenius/vmadm" [dependencies] anyhow = "1" bytesize = "1" +clap = { version = "4.4.2", features = ["derive"] } directories-next = "2" home-dir = "0.1.0" lazy_static = "1.4.0" @@ -23,7 +24,6 @@ serde = { version = "1", features = ["derive"] } serde_json = "1.0.64" serde_yaml = "0.8" shell-words = "1" -structopt = "0.3" tempfile = "3.2" thiserror = "1" virt = "0.2.12" diff --git a/src/bin/vmadm.rs b/src/bin/vmadm.rs index a693b96..a10d3d9 100644 --- a/src/bin/vmadm.rs +++ b/src/bin/vmadm.rs @@ -1,8 +1,8 @@ use anyhow::Context; +use clap::Parser; use directories_next::ProjectDirs; use log::debug; use std::path::PathBuf; -use structopt::StructOpt; use vmadm::cmd; use vmadm::config::Configuration; use vmadm::progress::{MessageKind, Progress}; @@ -12,99 +12,90 @@ const QUALIFIER: &str = ""; const ORG: &str = ""; const APP: &str = "vmadm"; -#[derive(StructOpt, Debug)] +#[derive(Debug, Parser)] struct Cli { - #[structopt(subcommand)] + #[clap(subcommand)] cmd: Command, } -#[derive(StructOpt, Debug)] +#[derive(Debug, Parser)] enum Command { New { - #[structopt(flatten)] + #[clap(flatten)] common: CommonOptions, - #[structopt(parse(from_os_str))] specs: Vec, }, Recreate { - #[structopt(flatten)] + #[clap(flatten)] common: CommonOptions, - #[structopt(parse(from_os_str))] specs: Vec, }, Config { - #[structopt(flatten)] + #[clap(flatten)] common: CommonOptions, }, Spec { - #[structopt(flatten)] + #[clap(flatten)] common: CommonOptions, - #[structopt(parse(from_os_str))] spec: PathBuf, }, List { - #[structopt(flatten)] + #[clap(flatten)] common: CommonOptions, }, Delete { - #[structopt(flatten)] + #[clap(flatten)] common: CommonOptions, - #[structopt(parse(from_os_str))] specs: Vec, }, Start { - #[structopt(flatten)] + #[clap(flatten)] common: CommonOptions, - #[structopt(parse(from_os_str))] specs: Vec, }, Shutdown { - #[structopt(flatten)] + #[clap(flatten)] common: CommonOptions, - #[structopt(parse(from_os_str))] specs: Vec, }, CloudInit { - #[structopt(flatten)] + #[clap(flatten)] common: CommonOptions, - #[structopt(parse(from_os_str))] spec: PathBuf, - - #[structopt(parse(from_os_str))] dirname: PathBuf, }, } -#[derive(StructOpt, Debug)] +#[derive(Debug, Parser)] struct CommonOptions { - #[structopt(short, long, parse(from_os_str))] + #[clap(short, long)] config: Option, - #[structopt(short, long)] + #[clap(short, long)] quiet: bool, - #[structopt(short, long)] + #[clap(short, long)] verbose: bool, } fn main() -> anyhow::Result<()> { pretty_env_logger::init_custom_env("VMADM_LOG"); - let cli = Cli::from_args(); + let cli = Cli::parse(); debug!("{:#?}", cli); match cli.cmd { -- cgit v1.2.1