From 53884933dd7f56764d4a26e5d6f4d76fc403aa9f Mon Sep 17 00:00:00 2001 From: Jeff Bencin Date: Sun, 23 Oct 2022 14:35:12 -0400 Subject: [PATCH 1/2] Update Clap and switch to declarative interface for generating argument parser --- Cargo.lock | 355 +++++++++++++++++++++++++++++++------------------ Cargo.toml | 4 +- README.md | 39 +++--- src/main.rs | 137 ++++++++----------- src/manager.rs | 33 ++--- 5 files changed, 319 insertions(+), 249 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c9587e8..491614a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,28 +1,39 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] -name = "aho-corasick" -version = "0.7.13" +name = "addr2line" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043164d8ba5c4c3035fec9bbee8647c0261d788f3474306f93bb65901cae0e86" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" dependencies = [ - "memchr", + "gimli", ] [[package]] -name = "ansi_term" -version = "0.11.0" +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ - "winapi", + "memchr", ] [[package]] name = "anyhow" -version = "1.0.32" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b" +checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" +dependencies = [ + "backtrace", +] [[package]] name = "atty" @@ -37,15 +48,30 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.0" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" +checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cargo-cvm" @@ -74,32 +100,54 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.58" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" dependencies = [ "jobserver", ] [[package]] name = "cfg-if" -version = "0.1.10" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "2.33.2" +version = "4.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10040cdf04294b565d9e0319955430099ec3813a64c952b86a41200ad714ae48" +checksum = "335867764ed2de42325fafe6d18b8af74ba97ee0c590fa016f157535b42ab04b" dependencies = [ - "ansi_term", "atty", "bitflags", + "clap_derive", + "clap_lex", + "once_cell", "strsim", - "textwrap", - "unicode-width", - "vec_map", + "termcolor", +] + +[[package]] +name = "clap_derive" +version = "4.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a1b0f6422af32d5da0c58e2703320f379216ee70198241c84173a8c5ac28f3" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +dependencies = [ + "os_str_bytes", ] [[package]] @@ -115,11 +163,26 @@ dependencies = [ "termcolor", ] +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "gimli" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" + [[package]] name = "git2" -version = "0.13.8" +version = "0.13.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ac22e49b7d886b6802c66662b12609452248b1bc9e87d6d83ecea3db96f557" +checksum = "f29229cc1b24c0e6062f6e742aa3e256492a5323365e5ed3413599f8a5eff7d6" dependencies = [ "bitflags", "libc", @@ -130,11 +193,17 @@ dependencies = [ "url", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" -version = "0.1.15" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -150,41 +219,34 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" dependencies = [ - "matches", "unicode-bidi", "unicode-normalization", ] [[package]] name = "jobserver" -version = "0.1.21" +version = "0.1.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" +checksum = "068b1ee6743e4d11fb9c6a1e6064b3693a1b600e7f5f5988047d98b3dc9fb90b" dependencies = [ "libc", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" -version = "0.2.74" +version = "0.2.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2f02823cf78b754822df5f7f268fb59822e7296276d3e069d8e8cb26a14bd10" +checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c" [[package]] name = "libgit2-sys" -version = "0.12.9+1.0.1" +version = "0.12.26+1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b33bf3d9d4c45b48ae1ea7c334be69994624dc0a69f833d5d9f7605f24b552b" +checksum = "19e1c899248e606fbfe68dcb31d8b0176ebab833b103824af31bddf4b7457494" dependencies = [ "cc", "libc", @@ -196,9 +258,9 @@ dependencies = [ [[package]] name = "libssh2-sys" -version = "0.2.18" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eafa907407504b0e683786d4aba47acf250f114d37357d56608333fd167dd0fc" +checksum = "b094a36eb4b8b8c8a7b4b8ae43b2944502be3e59cd87687595cf6b0a71b3f4ca" dependencies = [ "cc", "libc", @@ -210,9 +272,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.0.25" +version = "1.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" +checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" dependencies = [ "cc", "libc", @@ -222,36 +284,54 @@ dependencies = [ [[package]] name = "log" -version = "0.4.11" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] [[package]] -name = "matches" -version = "0.1.8" +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "miniz_oxide" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" +dependencies = [ + "adler", +] + +[[package]] +name = "object" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" +dependencies = [ + "memchr", +] [[package]] -name = "memchr" -version = "2.3.3" +name = "once_cell" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "openssl-probe" -version = "0.1.2" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.58" +version = "0.9.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a842db4709b604f0fe5d1170ae3565899be2ad3d9cbc72dedc789ac0511f78de" +checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" dependencies = [ "autocfg", "cc", @@ -260,25 +340,55 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "os_str_bytes" +version = "6.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" + [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pkg-config" -version = "0.3.18" +version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" + +[[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", + "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.19" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -289,45 +399,50 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.7" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] [[package]] name = "regex" -version = "1.3.9" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" dependencies = [ "aho-corasick", "memchr", "regex-syntax", - "thread_local", ] [[package]] name = "regex-syntax" -version = "0.6.18" +version = "0.6.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" + +[[package]] +name = "rustc-demangle" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" [[package]] name = "serde" -version = "1.0.114" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" +checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.114" +version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" +checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" dependencies = [ "proc-macro2", "quote", @@ -336,115 +451,97 @@ dependencies = [ [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.38" +version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e69abc24912995b3038597a7a593be5053eb0fb44f3cc5beec0deb421790c1f4" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] name = "termcolor" -version = "1.1.0" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ "winapi-util", ] [[package]] -name = "textwrap" -version = "0.11.0" +name = "tinyvec" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" dependencies = [ - "unicode-width", + "tinyvec_macros", ] [[package]] -name = "thread_local" -version = "1.0.1" +name = "tinyvec_macros" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "tinyvec" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "toml" -version = "0.5.6" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" dependencies = [ "serde", ] [[package]] name = "unicode-bidi" -version = "0.3.4" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -dependencies = [ - "matches", -] +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-normalization" -version = "0.1.13" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fb19cf769fa8c6a80a162df694621ebeb4dafb606470b2b2fce0be40a98a977" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-width" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" - -[[package]] -name = "unicode-xid" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" - [[package]] name = "url" -version = "2.1.1" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" dependencies = [ + "form_urlencoded", "idna", - "matches", "percent-encoding", ] [[package]] name = "vcpkg" -version = "0.2.10" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6454029bf181f092ad1b853286f23e2c507d8e8194d01d92da4a55c274a5508c" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] -name = "vec_map" -version = "0.8.2" +name = "version_check" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "winapi" diff --git a/Cargo.toml b/Cargo.toml index 118e11b..37451f9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,9 +15,9 @@ name = "cargo-cvm" path = "src/main.rs" [dependencies] -anyhow = "1.0.32" +anyhow = { version = "1.0.66", features = ["backtrace"] } cargo_toml = "0.8.1" -clap = "2.33.2" +clap = { version = "4.0.18", features = ["derive"] } toml = "0.5.6" serde = { version = "1.0.114", features = ["derive"] } log = "0.4.11" diff --git a/README.md b/README.md index f9e644b..5cd5200 100644 --- a/README.md +++ b/README.md @@ -25,29 +25,22 @@ cargo cvm --help ``` ``` -cargo-cvm-cvm - -USAGE: - cargo-cvm cvm [FLAGS] [OPTIONS] - -FLAGS: - -x, --check Panic if the versions are out-of-date - -c, --commit git commit updated version(s), otherwise will only add the files to git. Can only be used with - --fix or --force flags - -f, --fix Automatically fix the version if it is outdated. By default, this will bump the minor version, - unless otherwise specified by the --semver option - -F, --force Force a version bump. Can use be used with --semver option to determine version type - -h, --help Prints help information - -V, --version Prints version information - -w, --warn Warn if the versions are out-of-date - -OPTIONS: - -b, --branch Which branch to compare to the current. Will attempt to find the version in the target - branch and check if the version has been bumped or not. - -r, --remote Determine which remote to use for the target branch. Defaults to `origin`. - -s, --semver Type of Semantic Versioning; i.e. `minor`, `major`, or `patch`. Defaults to `minor` - -k, --ssh-key Provide the path to your ssh private key for authenticating against remote git hosts. - Defaults to $HOME/.ssh/id_rsa +Rust Crate Version Manager (CVM) + +Usage: cargo-cvm [OPTIONS] + +Options: + -s, --semver Type of Semantic Versioning [default: minor] [possible values: minor, major, patch] + -b, --branch Which branch to compare to the current. Will attempt to find the version in the target branch and check if the version has been bumped or not [default: master] + -r, --remote Determine which remote to use for the target branch [default: origin] + -k, --ssh-key Provide the path to your ssh private key for authenticating against remote git hosts. Defaults to $HOME/.ssh/id_rsa + -f, --fix Automatically fix the version if it is outdated. By default, this will bump the minor version, unless otherwise specified by the --semver option + -F, --force Force a version bump. Can use be used with --semver option to determine version type + -x, --check Panic if the versions are out-of-date + -w, --warn Warn if the versions are out-of-date + -c, --commit git commit updated version(s), otherwise will only add the files to git. Can only be used with --fix or --force flags + -h, --help Print help information + -V, --version Print version information ``` ## Version Check diff --git a/src/main.rs b/src/main.rs index a5ba504..c1690b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,87 +1,64 @@ mod manager; use anyhow::Error; -use clap::{crate_authors, crate_description, crate_version, App, Arg, SubCommand}; -use manager::Manager; +use clap::Parser; +use manager::{Manager, SemVer}; -fn main() -> Result<(), Error> { - env_logger::init(); +/// Rust Crate Version Manage (CVM) +#[derive(Parser, Default)] +#[command(about, author, version)] +pub struct Args { + /// Type of Semantic Versioning + #[arg(short, long, value_enum, default_value_t)] + pub semver: SemVer, + + /// Which branch to compare to the current. Will attempt to find the version in the target branch and check if the version has been bumped or not + #[arg(short, long, default_value_t = String::from("master"))] + pub branch: String, + + /// Determine which remote to use for the target branch + #[arg(short, long, default_value_t = String::from("origin"))] + pub remote: String, + + /// Provide the path to your ssh private key for authenticating against remote git hosts. Defaults to $HOME/.ssh/id_rsa + #[arg(short = 'k', long = "ssh-key")] + pub ssh_key_path: Option, + + /// Automatically fix the version if it is outdated. By default, this will bump the minor version, unless otherwise specified by the --semver option + #[arg(short, long)] + pub fix: bool, - if let Some(args) = App::new("Rust Crate Version Manage (CVM)") - .version(crate_version!()) - .author(crate_authors!()) - .about(crate_description!()) - .subcommand( - SubCommand::with_name("cvm") - .arg( - Arg::with_name("semver") - .short("s") - .long("semver") - .help("Type of Semantic Versioning; i.e. `minor`, `major`, or `patch`. Defaults to `minor`") - .takes_value(true), - ) - .arg( - Arg::with_name("branch") - .short("b") - .long("branch") - .help("Which branch to compare to the current. Will attempt to find the version in the target branch and check if the version has been bumped or not.") - .takes_value(true), - ) - .arg( - Arg::with_name("remote") - .short("r") - .long("remote") - .help("Determine which remote to use for the target branch. Defaults to `origin`.") - .takes_value(true), - ) - .arg( - Arg::with_name("ssh-key") - .short("k") - .long("ssh-key") - .help("Provide the path to your ssh private key for authenticating against remote git hosts. Defaults to $HOME/.ssh/id_rsa") - .takes_value(true), - ) - .arg( - Arg::with_name("fix") - .short("f") - .long("fix") - .takes_value(false) - .help("Automatically fix the version if it is outdated. By default, this will bump the minor version, unless otherwise specified by the --semver option")) - .arg( - Arg::with_name("force") - .short("F") - .long("force") - .takes_value(false) - .help("Force a version bump. Can use be used with --semver option to determine version type"), - ) - .arg( - Arg::with_name("check") - .short("x") - .long("check") - .takes_value(false) - .help("Panic if the versions are out-of-date"), - ) - .arg( - Arg::with_name("warn") - .short("w") - .long("warn") - .takes_value(false) - .help("Warn if the versions are out-of-date"), - ) - .arg( - Arg::with_name("commit") - .short("c") - .long("commit") - .takes_value(false) - .help("git commit updated version(s), otherwise will only add the files to git. Can only be used with --fix or --force flags"), - ), - ) - .get_matches() - .subcommand_matches("cvm") - { - let manager = Manager::new(args)?; - manager.check_workspaces()?; - }; + /// Force a version bump. Can use be used with --semver option to determine version type + #[arg(short = 'F', long)] + pub force: bool, - Ok(()) + /// Panic if the versions are out-of-date + #[arg(short = 'x', long)] + pub check: bool, + + /// Warn if the versions are out-of-date + #[arg(short, long)] + pub warn: bool, + + /// git commit updated version(s), otherwise will only add the files to git. Can only be used with --fix or --force flags + #[arg(short, long)] + pub commit: bool, } + +fn main() -> Result<(), Error> { + env_logger::init(); + + // Filter out `cvm` subcommand when used from Cargo + let args = std::env::args() + .enumerate() + .filter_map(|(i, arg)| { + if i == 1 && arg == "cvm" { + None + } else { + Some(arg) + } + }); + let args = Args::parse_from(args); + let manager = Manager::new(args)?; + manager.check_workspaces() +} \ No newline at end of file diff --git a/src/manager.rs b/src/manager.rs index cb4efc8..cee3af6 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -1,6 +1,6 @@ use anyhow::Error; use cargo_toml::Manifest; -use clap::ArgMatches; +use clap::ValueEnum; use git2::{BranchType, Repository, Tree}; use std::cmp::Ordering; use std::convert::TryInto; @@ -9,6 +9,8 @@ use std::fs::{remove_file, File}; use std::io::Write; use std::path::PathBuf; +use crate::Args; + #[derive(Debug, Clone, Eq)] pub struct Version { major: u8, @@ -68,8 +70,9 @@ impl Version { } } } -#[derive(Debug, Clone)] +#[derive(Debug, Default, Clone, ValueEnum)] pub enum SemVer { + #[default] Minor, Major, Patch, @@ -155,25 +158,25 @@ pub struct Manager { } impl Manager { - pub fn new(args: &ArgMatches) -> Result { + // Consumes `args` + // TODO: Merge `Args` and `Manager` into single struct? + pub fn new(args: Args) -> Result { let dir = std::env::current_dir()?; let repo = Repository::discover(dir.clone())?; let ssh_key_path = format!("{}/.ssh/id_rsa", std::env::var("HOME")?); Ok(Self { - semver: args.value_of("semver").unwrap_or("minor").try_into()?, - check: args.is_present("check"), - fix: args.is_present("fix"), - warn: args.is_present("warn"), - force: args.is_present("force"), - commit: args.is_present("commit"), - target_branch: args.value_of("branch").unwrap_or("master").to_string(), - target_remote: args.value_of("remote").unwrap_or("origin").to_string(), + semver: args.semver, + check: args.check, + fix: args.fix, + warn: args.warn, + force: args.force, + commit: args.commit, + target_branch: args.branch, + target_remote: args.remote, workspaces: Self::get_cargo_workspaces(dir)?, - ssh_key_path: args - .value_of("ssh-key") - .unwrap_or(&ssh_key_path) - .to_string(), + ssh_key_path: args.ssh_key_path + .unwrap_or(ssh_key_path), repo, }) } From 77e0202b2460f7c74f5a45eea2664b4f5eb7f079 Mon Sep 17 00:00:00 2001 From: Jeff Bencin Date: Sun, 23 Oct 2022 15:14:34 -0400 Subject: [PATCH 2/2] Fix clippy warnings and CI errors --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/manager.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 491614a..d9aa181 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,7 +75,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "cargo-cvm" -version = "0.5.9" +version = "0.5.10" dependencies = [ "anyhow", "cargo_toml", diff --git a/Cargo.toml b/Cargo.toml index 37451f9..d037e6b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-cvm" -version = "0.5.9" +version = "0.5.10" edition = "2018" authors = ["Fluvio Contributors "] description = "Rust Crate Version Manager (CVM)" diff --git a/src/manager.rs b/src/manager.rs index cee3af6..573b223 100644 --- a/src/manager.rs +++ b/src/manager.rs @@ -403,7 +403,7 @@ impl Manager { let mut cargo_toml = workspace; cargo_toml.push("Cargo.toml"); let config: Manifest = toml::from_str(&read_to_string(&cargo_toml)?)?; - Ok(config.try_into()?) + config.try_into() } pub fn is_version_outdated( @@ -517,7 +517,7 @@ mod tests { let dir = std::env::current_dir()?; - assert_eq!(mgr.is_version_outdated(dir)?.is_some(), false); + assert!(mgr.is_version_outdated(dir)?.is_some()); Ok(()) }