From 8796ffbc8f2d6805a6c365b0f0892e97894acafa Mon Sep 17 00:00:00 2001 From: Chris Davison Date: Sun, 5 Mar 2023 11:51:57 +0000 Subject: [PATCH] change clap for structopt --- Cargo.lock | 134 +++++++++++++++++++++++----------------------------- Cargo.toml | 2 +- bin/main.rs | 68 +++++++++++++------------- 3 files changed, 92 insertions(+), 112 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 21b4f97..de741f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + [[package]] name = "atty" version = "0.2.14" @@ -61,39 +70,13 @@ version = "2.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ - "bitflags", - "textwrap 0.11.0", - "unicode-width", -] - -[[package]] -name = "clap" -version = "3.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5177fac1ab67102d8989464efd043c6ff44191b1557ec1ddd489b4f7e1447e77" -dependencies = [ + "ansi_term", "atty", "bitflags", - "clap_derive", - "indexmap", - "lazy_static", - "os_str_bytes", "strsim", - "termcolor", - "textwrap 0.14.2", -] - -[[package]] -name = "clap_derive" -version = "3.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01d42c94ce7c2252681b5fed4d3627cc807b13dfc033246bd05d5b252399000e" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", + "textwrap", + "unicode-width", + "vec_map", ] [[package]] @@ -104,7 +87,7 @@ checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" dependencies = [ "atty", "cast", - "clap 2.34.0", + "clap", "criterion-plot", "csv", "itertools", @@ -217,17 +200,14 @@ version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" - [[package]] name = "heck" -version = "0.4.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] [[package]] name = "hermit-abi" @@ -238,16 +218,6 @@ dependencies = [ "libc", ] -[[package]] -name = "indexmap" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" -dependencies = [ - "autocfg", - "hashbrown", -] - [[package]] name = "itertools" version = "0.10.5" @@ -345,15 +315,6 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" -[[package]] -name = "os_str_bytes" -version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" -dependencies = [ - "memchr", -] - [[package]] name = "plotters" version = "0.3.4" @@ -531,9 +492,33 @@ dependencies = [ [[package]] name = "strsim" -version = "0.10.0" +version = "0.8.0" +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 = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] [[package]] name = "syn" @@ -550,20 +535,11 @@ dependencies = [ name = "tagsearch" version = "0.37.0" dependencies = [ - "clap 3.1.2", "criterion", "glob", "lazy_static", "rayon", -] - -[[package]] -name = "termcolor" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" -dependencies = [ - "winapi-util", + "structopt", ] [[package]] @@ -575,12 +551,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "textwrap" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" - [[package]] name = "tinytemplate" version = "1.2.1" @@ -591,6 +561,12 @@ dependencies = [ "serde_json", ] +[[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" @@ -603,6 +579,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version_check" version = "0.9.3" diff --git a/Cargo.toml b/Cargo.toml index 5d92af6..ecb9983 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ path = "bin/main.rs" glob = "0.3.0" lazy_static = "1.4.0" rayon = "1.5.0" -clap = { version = "3.1.2", features = ["derive", "cargo"] } +structopt = "0.3.26" [dev-dependencies] criterion = "0.3" diff --git a/bin/main.rs b/bin/main.rs index cf6b4fe..45d0c63 100644 --- a/bin/main.rs +++ b/bin/main.rs @@ -2,85 +2,83 @@ use std::io::Write; use tagsearch::{filter::Filter, utility::*, Tag}; -use clap::{Parser, Subcommand}; +use structopt::StructOpt; -#[derive(Parser)] -#[clap(author, version, about, long_about = None)] -#[clap(propagate_version = true)] +#[derive(StructOpt,Debug)] struct Cli { - #[clap(subcommand)] + #[structopt(subcommand)] command: Commands, - #[clap(long)] + #[structopt(long)] root: Option, } -#[derive(Subcommand)] +#[derive(StructOpt,Debug)] enum Commands { /// Show files that have tags matching filter words - #[clap(aliases=&["f"])] + #[structopt(aliases=&["f"])] Files { /// Keywords to match good: Vec, - #[clap(long, require_value_delimiter(true))] + #[structopt(long, require_delimiter(true))] /// Keywords to NOT match not: Vec, /// Output in format suitable for vimgrep - #[clap(long)] + #[structopt(long)] vim: bool, /// Match ANY, not ALL, tags - #[clap(short, long)] + #[structopt(short, long)] or: bool, }, /// Show all tags from files with tags that match filter words - #[clap(aliases=&["t"])] + #[structopt(aliases=&["t"])] Tags { /// Keywords to match good: Vec, - #[clap(long, require_value_delimiter(true))] + #[structopt(long, require_delimiter(true))] /// Keywords to NOT match not: Vec, - #[clap(short, long)] + #[structopt(short, long)] /// Match ANY, not ALL, tags or: bool, /// Show how many times tag used - #[clap(short, long)] + #[structopt(short, long)] count: bool, /// Output in long format (tree-like) - #[clap(short, long)] + #[structopt(short, long)] long: bool, /// Stop 'tree' output in long list - #[clap(short, long)] + #[structopt(short, long)] no_tree: bool, }, /// Show tags from specific files - #[clap(aliases=&["ft"])] + #[structopt(aliases=&["ft"])] FileTags { /// Show how many times tag used - #[clap(short, long)] + #[structopt(short, long)] count: bool, /// Output in long format (tree-like) - #[clap(short, long)] + #[structopt(short, long)] long: bool, /// Stop 'tree' output in long list - #[clap(short, long)] + #[structopt(short, long)] no_tree: bool, /// Files to extract tags from files: Vec, }, /// Show files without tags - #[clap(aliases=&["u"])] + #[structopt(aliases=&["u"])] Untagged { /// Output in format suitable for vimgrep - #[clap(long)] + #[structopt(long)] vim: bool, }, /// Show tags that may be typos/slight differences - #[clap(aliases=&["similar", "related", "s"])] + #[structopt(aliases=&["similar", "related", "s"])] SimilarTags, } fn try_main() -> Result<(), std::io::Error> { - let cli = Cli::parse(); + let cli = Cli::from_args(); let files = match get_files(cli.root) { Ok(files) => files, Err(e) => { @@ -89,10 +87,10 @@ fn try_main() -> Result<(), std::io::Error> { } }; - match &cli.command { + match cli.command { Commands::Files { good, not, vim, or } => { - let f = Filter::new(good.as_slice(), not.as_slice(), *or); - display_files_matching_query(f, &files, *vim) + let f = Filter::new(good.as_slice(), not.as_slice(), or); + display_files_matching_query(f, &files, vim) } Commands::Tags { good, @@ -102,11 +100,11 @@ fn try_main() -> Result<(), std::io::Error> { long, no_tree, } => { - let f = Filter::new(good.as_slice(), not.as_slice(), *or); - if *count { + let f = Filter::new(good.as_slice(), not.as_slice(), or); + if count { display_tag_count(f, &files) } else { - display_tags(f, &files, *long, *no_tree) + display_tags(f, &files, long, no_tree) } } Commands::FileTags { @@ -116,13 +114,13 @@ fn try_main() -> Result<(), std::io::Error> { files, } => { let f: Filter = Default::default(); - if *count { - display_tag_count(f, files) + if count { + display_tag_count(f, &files) } else { - display_tags(f, files, *long, *no_tree) + display_tags(f, &files, long, no_tree) } } - Commands::Untagged { vim } => display_untagged(&files, *vim), + Commands::Untagged { vim } => display_untagged(&files, vim), Commands::SimilarTags => display_similar_tags(&files), } }