From 81e2982bbb052d4eced74118becc39a92a79a37d Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Mon, 3 Jan 2022 10:37:03 -0800 Subject: [PATCH] Migrate to clap 0.3 --- Cargo.lock | 213 +++++++++++++++++------------------ Cargo.toml | 5 +- default.nix | 2 +- src/cli.rs | 39 ++++--- src/command/apply.rs | 38 +++---- src/command/apply_local.rs | 26 ++--- src/command/build.rs | 10 +- src/command/eval.rs | 18 +-- src/command/exec.rs | 20 ++-- src/command/nix_info.rs | 8 +- src/command/test_progress.rs | 8 +- src/command/upload_keys.rs | 10 +- src/troubleshooter.rs | 6 +- src/util.rs | 6 +- 14 files changed, 204 insertions(+), 205 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55632b3..4af675c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,15 +21,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -dependencies = [ - "winapi", -] - [[package]] name = "async-stream" version = "0.3.2" @@ -53,9 +44,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.51" +version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" +checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3" dependencies = [ "proc-macro2", "quote", @@ -93,9 +84,9 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "cc" -version = "1.0.71" +version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" [[package]] name = "cfg-if" @@ -105,17 +96,26 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "2.33.3" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "d17bf219fcd37199b9a29e00ba65dfb8cd5b2688b7297ec14ff829c40ac50ca9" dependencies = [ - "ansi_term", "atty", "bitflags", + "indexmap", + "os_str_bytes", "strsim", + "termcolor", "textwrap", - "unicode-width", - "vec_map", +] + +[[package]] +name = "clap_complete" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60d123fbea4c5d9799cffd44051e2125c880efd23b3b7c529baf3ea5508c8736" +dependencies = [ + "clap", ] [[package]] @@ -138,6 +138,7 @@ dependencies = [ "async-trait", "atty", "clap", + "clap_complete", "clicolors-control", "console 0.13.0", "const_format", @@ -258,9 +259,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" +checksum = "28560757fe2bb34e79f907794bb6b22ae8b0e5c669b638a1132f2592b19035b4" dependencies = [ "futures-channel", "futures-core", @@ -273,9 +274,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b" dependencies = [ "futures-core", "futures-sink", @@ -283,15 +284,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" +checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" [[package]] name = "futures-executor" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" +checksum = "29d6d2ff5bb10fb95c85b8ce46538a2e5f5e7fdc755623a7d4529ab8a4ed9d2a" dependencies = [ "futures-core", "futures-task", @@ -300,18 +301,16 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" +checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2" [[package]] name = "futures-macro" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" +checksum = "6dbd947adfffb0efc70599b3ddcf7b5597bb5fa9e245eb99f62b3a5f7bb8bd3c" dependencies = [ - "autocfg", - "proc-macro-hack", "proc-macro2", "quote", "syn", @@ -319,23 +318,22 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" +checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508" [[package]] name = "futures-task" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" +checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72" [[package]] name = "futures-util" -version = "0.3.17" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164" dependencies = [ - "autocfg", "futures-channel", "futures-core", "futures-io", @@ -345,8 +343,6 @@ dependencies = [ "memchr", "pin-project-lite", "pin-utils", - "proc-macro-hack", - "proc-macro-nested", "slab", ] @@ -367,6 +363,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -410,6 +412,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed" +[[package]] +name = "indexmap" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "indicatif" version = "0.17.0-beta.1" @@ -423,18 +435,18 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.1" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" dependencies = [ "either", ] [[package]] name = "itoa" -version = "0.4.8" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "lazy_static" @@ -444,9 +456,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.105" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "869d572136620d55835903746bcb5cdc54cb2851fd0aeec53220b4bb65ef3013" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "log" @@ -508,9 +520,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.13.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ "hermit-abi", "libc", @@ -524,9 +536,18 @@ checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" [[package]] name = "once_cell" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + +[[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 = "percent-encoding" @@ -536,9 +557,9 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project-lite" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" +checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" [[package]] name = "pin-utils" @@ -548,9 +569,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "ppv-lite86" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "proc-macro-error" @@ -576,23 +597,11 @@ dependencies = [ "version_check", ] -[[package]] -name = "proc-macro-hack" -version = "0.5.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" - -[[package]] -name = "proc-macro-nested" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" - [[package]] name = "proc-macro2" -version = "1.0.32" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" dependencies = [ "unicode-xid", ] @@ -614,9 +623,9 @@ checksum = "a411616b47dce3139c0169c89899ba5ea3534e545ab4d0c1d3956460fe781bae" [[package]] name = "quote" -version = "1.0.10" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" dependencies = [ "proc-macro2", ] @@ -698,24 +707,24 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.5" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" [[package]] name = "serde" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" dependencies = [ "proc-macro2", "quote", @@ -724,9 +733,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.68" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8" +checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" dependencies = [ "itoa", "ryu", @@ -777,15 +786,15 @@ 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.81" +version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" +checksum = "ecb2e6da8ee5eb9a61068762a32fa9619cc591ceb055b3687f4cd4051ec2e06b" dependencies = [ "proc-macro2", "quote", @@ -794,9 +803,9 @@ dependencies = [ [[package]] name = "sys-info" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5cfbd84f86389198ade41b439f72a5b1b3a8ba728e61cd589e1720d0df44c39" +checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c" dependencies = [ "cc", "libc", @@ -837,12 +846,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.11.0" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] +checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" [[package]] name = "thiserror" @@ -866,9 +872,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7" +checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2" dependencies = [ "tinyvec_macros", ] @@ -881,11 +887,10 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.12.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2c2416fdedca8443ae44b4527de1ea633af61d8f7169ffa6e72c5b53d24efcc" +checksum = "fbbf1c778ec206785635ce8ad57fe52b3009ae9e0c9f574a728f3049d3e55838" dependencies = [ - "autocfg", "bytes", "libc", "memchr", @@ -900,9 +905,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.5.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2dd85aeaba7b68df939bd357c6afb36c87951be9e80bf9c859f2fc3e9fca0fd" +checksum = "b557f72f448c511a979e2564e55d74e6c4432fc96ff4f6241bc6bded342643b7" dependencies = [ "proc-macro2", "quote", @@ -911,9 +916,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.7" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b2f3f698253f03119ac0102beaa64f67a67e08074d03a22d18784104543727f" +checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" dependencies = [ "futures-core", "pin-project-lite", @@ -1031,17 +1036,11 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad9680608df133af2c1ddd5eaf1ddce91d60d61b6bc51494ef326458365a470a" -[[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" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasi" diff --git a/Cargo.toml b/Cargo.toml index 87a5ac5..cc78ed4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,8 @@ edition = "2018" ansi-to-html = "0.1.0" async-trait = "0.1.42" atty = "0.2" -clap = "2.33.3" +clap = "3.0.0" +clap_complete = "3.0.0" clicolors-control = "1" console = "0.13.0" const_format = "0.2.22" @@ -27,7 +28,7 @@ regex = "1" serde = { version = "1.0.118", features = ["derive"] } serde_json = "1.0" shell-escape = "0.1.5" -sys-info = "0.7.0" +sys-info = "0.9.0" snafu = "0.6.10" tempfile = "3.1.0" tokio-test = "0.4.0" diff --git a/default.nix b/default.nix index eceddc2..1e15597 100644 --- a/default.nix +++ b/default.nix @@ -17,7 +17,7 @@ in rustPlatform.buildRustPackage rec { src = lib.cleanSource ./.; }; - cargoSha256 = "sha256-YE+0jsdkzRaiUhPC71WBe/KcYERNy7nME26+ejrPRlc="; + cargoSha256 = "sha256-bSlDE2UkCO4jdTHnvaMdRHMl7HLSIYVpDBMiojmBv7Q="; nativeBuildInputs = [ installShellFiles ]; diff --git a/src/cli.rs b/src/cli.rs index e80f530..c6d8364 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,7 +2,8 @@ use std::env; -use clap::{App, AppSettings, Arg, ArgMatches, SubCommand}; +use clap::{App, AppSettings, Arg, ArgMatches, ColorChoice}; +use clap_complete::Shell; use const_format::concatcp; use env_logger::fmt::WriteStyle; use lazy_static::lazy_static; @@ -85,7 +86,7 @@ macro_rules! handle_command { }; } -pub fn build_cli(include_internal: bool) -> App<'static, 'static> { +pub fn build_cli(include_internal: bool) -> App<'static> { let version = env!("CARGO_PKG_VERSION"); let mut app = App::new("Colmena") .bin_name("colmena") @@ -93,14 +94,13 @@ pub fn build_cli(include_internal: bool) -> App<'static, 'static> { .author("Zhaofeng Li ") .about("NixOS deployment tool") .long_about(LONG_ABOUT.as_str()) - .global_setting(AppSettings::ColoredHelp) .setting(AppSettings::ArgRequiredElseHelp) - .arg(Arg::with_name("config") - .short("f") + .arg(Arg::new("config") + .short('f') .long("config") .value_name("CONFIG") .help("Path to a Hive expression, a flake.nix, or a Nix Flake URI") - .long_help(&CONFIG_HELP) + .long_help(Some(CONFIG_HELP.as_str())) .display_order(HELP_ORDER_FIRST) // The default value is a lie (sort of)! @@ -111,13 +111,13 @@ pub fn build_cli(include_internal: bool) -> App<'static, 'static> { // is explicitly supplied by the user (occurrences_of > 0). .default_value("hive.nix") .global(true)) - .arg(Arg::with_name("show-trace") + .arg(Arg::new("show-trace") .long("show-trace") .help("Show debug information for Nix commands") .long_help("Passes --show-trace to Nix commands") .global(true) .takes_value(false)) - .arg(Arg::with_name("color") + .arg(Arg::new("color") .long("color") .help("When to colorize the output") .long_help(r#"When to colorize the output. By default, Colmena enables colorized output when the terminal supports it. @@ -131,15 +131,16 @@ It's also possible to specify the preference using environment variables. See ) { +fn gen_completions(args: &ArgMatches) { let mut app = build_cli(false); - let shell: clap::Shell = args.value_of("shell").unwrap() - .parse().unwrap(); + let shell = args.value_of_t::("shell").unwrap(); - app.gen_completions_to("colmena", shell, &mut std::io::stdout()); + clap_complete::generate(shell, &mut app, "colmena", &mut std::io::stdout()); } fn gen_help_markdown() { @@ -226,8 +226,7 @@ fn gen_help_markdown() { let mut command = { let c = command - .setting(AppSettings::ColoredHelp) - .setting(AppSettings::ColorAlways); + .color(ColorChoice::Always); if full_command != "colmena" { c.bin_name(&full_command) diff --git a/src/command/apply.rs b/src/command/apply.rs index b3b5142..6ff1514 100644 --- a/src/command/apply.rs +++ b/src/command/apply.rs @@ -1,7 +1,7 @@ use std::env; use std::path::PathBuf; -use clap::{Arg, App, SubCommand, ArgMatches, ArgSettings}; +use clap::{Arg, App, ArgMatches, ArgSettings}; use crate::nix::deployment::{ Deployment, @@ -14,9 +14,9 @@ use crate::progress::SimpleProgressOutput; use crate::nix::{NixError, NodeFilter}; use crate::util; -pub fn register_deploy_args<'a, 'b>(command: App<'a, 'b>) -> App<'a, 'b> { +pub fn register_deploy_args<'a>(command: App<'a>) -> App<'a> { command - .arg(Arg::with_name("eval-node-limit") + .arg(Arg::new("eval-node-limit") .long("eval-node-limit") .value_name("LIMIT") .help("Evaluation node limit") @@ -38,8 +38,8 @@ Set to 0 to disable the limit. Err(_) => Err(String::from("The value must be a valid number")), } })) - .arg(Arg::with_name("parallel") - .short("p") + .arg(Arg::new("parallel") + .short('p') .long("parallel") .value_name("LIMIT") .help("Deploy parallelism limit") @@ -55,7 +55,7 @@ Set to 0 to disable parallemism limit. Err(_) => Err(String::from("The value must be a valid number")), } })) - .arg(Arg::with_name("keep-result") + .arg(Arg::new("keep-result") .long("keep-result") .help("Create GC roots for built profiles") .long_help(r#"Create GC roots for built profiles. @@ -64,13 +64,13 @@ The built system profiles will be added as GC roots so that they will not be rem The links will be created under .gcroots in the directory the Hive configuration is located. "#) .takes_value(false)) - .arg(Arg::with_name("verbose") - .short("v") + .arg(Arg::new("verbose") + .short('v') .long("verbose") .help("Be verbose") .long_help("Deactivates the progress spinner and prints every line of output.") .takes_value(false)) - .arg(Arg::with_name("no-keys") + .arg(Arg::new("no-keys") .long("no-keys") .help("Do not upload keys") .long_help(r#"Do not upload secret keys set in `deployment.keys`. @@ -79,17 +79,17 @@ By default, Colmena will upload keys set in `deployment.keys` before deploying t To upload keys without building or deploying the rest of the configuration, use `colmena upload-keys`. "#) .takes_value(false)) - .arg(Arg::with_name("no-substitutes") + .arg(Arg::new("no-substitutes") .long("no-substitutes") .help("Do not use substitutes") .long_help("Disables the use of substituters when copying closures to the remote host.") .takes_value(false)) - .arg(Arg::with_name("no-gzip") + .arg(Arg::new("no-gzip") .long("no-gzip") .help("Do not use gzip") .long_help("Disables the use of gzip when copying closures to the remote host.") .takes_value(false)) - .arg(Arg::with_name("build-on-target") + .arg(Arg::new("build-on-target") .long("build-on-target") .help("Build the system profiles on the target nodes") .long_help(r#"Build the system profiles on the target nodes themselves. @@ -99,11 +99,11 @@ This overrides per-node perferences set in `deployment.buildOnTarget`. To temporarily disable remote build on all nodes, use `--no-build-on-target`. "#) .takes_value(false)) - .arg(Arg::with_name("no-build-on-target") + .arg(Arg::new("no-build-on-target") .long("no-build-on-target") - .set(ArgSettings::Hidden) + .setting(ArgSettings::Hidden) .takes_value(false)) - .arg(Arg::with_name("force-replace-unknown-profiles") + .arg(Arg::new("force-replace-unknown-profiles") .long("force-replace-unknown-profiles") .help("Ignore all targeted nodes deployment.replaceUnknownProfiles setting") .long_help(r#"If `deployment.replaceUnknownProfiles` is set for a target, using this switch @@ -111,10 +111,10 @@ will treat deployment.replaceUnknownProfiles as though it was set true and perfo .takes_value(false)) } -pub fn subcommand() -> App<'static, 'static> { - let command = SubCommand::with_name("apply") +pub fn subcommand() -> App<'static> { + let command = App::new("apply") .about("Apply configurations on remote machines") - .arg(Arg::with_name("goal") + .arg(Arg::new("goal") .help("Deployment goal") .long_help("Same as the targets for switch-to-configuration.\n\"push\" means only copying the closures to remote nodes.") .default_value("switch") @@ -126,7 +126,7 @@ pub fn subcommand() -> App<'static, 'static> { util::register_selector_args(command) } -pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) -> Result<(), NixError> { +pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(), NixError> { let hive = util::hive_from_args(local_args).await?; let ssh_config = env::var("SSH_CONFIG_FILE") diff --git a/src/command/apply_local.rs b/src/command/apply_local.rs index 1286e85..70c1f58 100644 --- a/src/command/apply_local.rs +++ b/src/command/apply_local.rs @@ -1,7 +1,7 @@ use std::env; use std::collections::HashMap; -use clap::{Arg, App, SubCommand, ArgMatches}; +use clap::{Arg, App, ArgMatches}; use tokio::fs; use tokio::process::Command; @@ -15,31 +15,31 @@ use crate::nix::{NixError, NodeName, host}; use crate::progress::SimpleProgressOutput; use crate::util; -pub fn subcommand() -> App<'static, 'static> { - SubCommand::with_name("apply-local") +pub fn subcommand() -> App<'static> { + App::new("apply-local") .about("Apply configurations on the local machine") - .arg(Arg::with_name("goal") + .arg(Arg::new("goal") .help("Deployment goal") .long_help("Same as the targets for switch-to-configuration.\n\"push\" is noop in apply-local.") .default_value("switch") .index(1) .possible_values(&["push", "switch", "boot", "test", "dry-activate", "keys"])) - .arg(Arg::with_name("sudo") + .arg(Arg::new("sudo") .long("sudo") .help("Attempt to escalate privileges if not run as root")) - .arg(Arg::with_name("sudo-command") + .arg(Arg::new("sudo-command") .long("sudo-command") .value_name("COMMAND") .help("Command to use to escalate privileges") .default_value("sudo") .takes_value(true)) - .arg(Arg::with_name("verbose") - .short("v") + .arg(Arg::new("verbose") + .short('v') .long("verbose") .help("Be verbose") .long_help("Deactivates the progress spinner and prints every line of output.") .takes_value(false)) - .arg(Arg::with_name("no-keys") + .arg(Arg::new("no-keys") .long("no-keys") .help("Do not deploy keys") .long_help(r#"Do not deploy secret keys set in `deployment.keys`. @@ -47,17 +47,17 @@ pub fn subcommand() -> App<'static, 'static> { By default, Colmena will deploy keys set in `deployment.keys` before activating the profile on this host. "#) .takes_value(false)) - .arg(Arg::with_name("node") + .arg(Arg::new("node") .long("node") .help("Override the node name to use") .takes_value(true)) - .arg(Arg::with_name("we-are-launched-by-sudo") + .arg(Arg::new("we-are-launched-by-sudo") .long("we-are-launched-by-sudo") - .hidden(true) + .hide(true) .takes_value(false)) } -pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) -> Result<(), NixError> { +pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(), NixError> { // Sanity check: Are we running NixOS? if let Ok(os_release) = fs::read_to_string("/etc/os-release").await { if !os_release.contains("ID=nixos\n") { diff --git a/src/command/build.rs b/src/command/build.rs index 14906de..c97ca71 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -1,18 +1,18 @@ -use clap::{Arg, App, SubCommand}; +use clap::{Arg, App}; use crate::util; use super::apply; pub use super::apply::run; -pub fn subcommand() -> App<'static, 'static> { - let command = SubCommand::with_name("build") +pub fn subcommand() -> App<'static> { + let command = App::new("build") .about("Build the configuration but not push to remote machines") .long_about(r#"Build the configuration but not push to remote machines This subcommand behaves as if you invoked `apply` with the `build` goal."#) - .arg(Arg::with_name("goal") - .hidden(true) + .arg(Arg::new("goal") + .hide(true) .default_value("build") .possible_values(&["build"]) .takes_value(true)); diff --git a/src/command/eval.rs b/src/command/eval.rs index 0eb05d7..859d7dc 100644 --- a/src/command/eval.rs +++ b/src/command/eval.rs @@ -1,12 +1,12 @@ use std::path::PathBuf; -use clap::{Arg, App, AppSettings, SubCommand, ArgMatches}; +use clap::{Arg, App, AppSettings, ArgMatches}; use crate::util; use crate::nix::NixError; -pub fn subcommand() -> App<'static, 'static> { - SubCommand::with_name("eval") +pub fn subcommand() -> App<'static> { + App::new("eval") .about("Evaluate expressions using the complete configuration") .long_about(r#"Evaluate expressions using the complete configuration @@ -16,29 +16,29 @@ For example, to retrieve the configuration of one node, you may write something { nodes, ... }: nodes.node-a.config.networking.hostName "#) - .arg(Arg::with_name("expression_file") + .arg(Arg::new("expression_file") .index(1) .value_name("FILE") .help("The .nix file containing the expression") .takes_value(true)) - .arg(Arg::with_name("expression") - .short("E") + .arg(Arg::new("expression") + .short('E') .value_name("EXPRESSION") .help("The Nix expression") .takes_value(true)) - .arg(Arg::with_name("instantiate") + .arg(Arg::new("instantiate") .long("instantiate") .help("Actually instantiate the expression") .takes_value(false)) } -pub fn deprecated_alias() -> App<'static, 'static> { +pub fn deprecated_alias() -> App<'static> { subcommand() .name("introspect") .setting(AppSettings::Hidden) } -pub async fn run(global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) -> Result<(), NixError> { +pub async fn run(global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(), NixError> { if let Some("introspect") = global_args.subcommand_name() { log::warn!("`colmena introspect` has been renamed to `colmena eval`. Please update your scripts."); } diff --git a/src/command/exec.rs b/src/command/exec.rs index f91e411..80427d5 100644 --- a/src/command/exec.rs +++ b/src/command/exec.rs @@ -2,7 +2,7 @@ use std::env; use std::path::PathBuf; use std::sync::Arc; -use clap::{Arg, App, AppSettings, SubCommand, ArgMatches}; +use clap::{Arg, App, AppSettings, ArgMatches}; use futures::future::join_all; use tokio::sync::Semaphore; @@ -11,12 +11,12 @@ use crate::job::{JobMonitor, JobState, JobType}; use crate::progress::SimpleProgressOutput; use crate::util; -pub fn subcommand() -> App<'static, 'static> { - let command = SubCommand::with_name("exec") +pub fn subcommand() -> App<'static> { + let command = App::new("exec") .about("Run a command on remote machines") .setting(AppSettings::TrailingVarArg) - .arg(Arg::with_name("parallel") - .short("p") + .arg(Arg::new("parallel") + .short('p') .long("parallel") .value_name("LIMIT") .help("Deploy parallelism limit") @@ -32,18 +32,18 @@ In `colmena exec`, the parallelism limit is disabled (0) by default. Err(_) => Err(String::from("The value must be a valid number")), } })) - .arg(Arg::with_name("verbose") - .short("v") + .arg(Arg::new("verbose") + .short('v') .long("verbose") .help("Be verbose") .long_help("Deactivates the progress spinner and prints every line of output.") .takes_value(false)) - .arg(Arg::with_name("command") + .arg(Arg::new("command") .value_name("COMMAND") .last(true) .help("Command") .required(true) - .multiple(true) + .multiple_occurrences(true) .long_help(r#"Command to run It's recommended to use -- to separate Colmena options from the command to run. For example: @@ -54,7 +54,7 @@ It's recommended to use -- to separate Colmena options from the command to run. util::register_selector_args(command) } -pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) -> Result<(), NixError> { +pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(), NixError> { let hive = util::hive_from_args(local_args).await?; let ssh_config = env::var("SSH_CONFIG_FILE") .ok().map(PathBuf::from); diff --git a/src/command/nix_info.rs b/src/command/nix_info.rs index 4e7c98b..bffb600 100644 --- a/src/command/nix_info.rs +++ b/src/command/nix_info.rs @@ -1,13 +1,13 @@ -use clap::{App, SubCommand, ArgMatches}; +use clap::{App, ArgMatches}; use crate::nix::{NixCheck, NixError}; -pub fn subcommand() -> App<'static, 'static> { - SubCommand::with_name("nix-info") +pub fn subcommand() -> App<'static> { + App::new("nix-info") .about("Show information about the current Nix installation") } -pub async fn run(_global_args: &ArgMatches<'_>, _local_args: &ArgMatches<'_>) -> Result<(), NixError> { +pub async fn run(_global_args: &ArgMatches, _local_args: &ArgMatches) -> Result<(), NixError> { let check = NixCheck::detect().await; check.print_version_info(); check.print_flakes_info(false); diff --git a/src/command/test_progress.rs b/src/command/test_progress.rs index e4c765b..8ed29be 100644 --- a/src/command/test_progress.rs +++ b/src/command/test_progress.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use clap::{App, AppSettings, SubCommand, ArgMatches}; +use clap::{App, AppSettings, ArgMatches}; use tokio::time; use crate::job::{JobMonitor, JobType}; @@ -13,13 +13,13 @@ macro_rules! node { } } -pub fn subcommand() -> App<'static, 'static> { - SubCommand::with_name("test-progress") +pub fn subcommand() -> App<'static> { + App::new("test-progress") .about("Run progress spinner tests") .setting(AppSettings::Hidden) } -pub async fn run(_global_args: &ArgMatches<'_>, _local_args: &ArgMatches<'_>) -> Result<(), NixError> { +pub async fn run(_global_args: &ArgMatches, _local_args: &ArgMatches) -> Result<(), NixError> { let mut output = SpinnerOutput::new(); let (monitor, meta) = JobMonitor::new(output.get_sender()); diff --git a/src/command/upload_keys.rs b/src/command/upload_keys.rs index 5d17b38..f75012e 100644 --- a/src/command/upload_keys.rs +++ b/src/command/upload_keys.rs @@ -1,18 +1,18 @@ -use clap::{Arg, App, SubCommand}; +use clap::{Arg, App}; use crate::util; use super::apply; pub use super::apply::run; -pub fn subcommand() -> App<'static, 'static> { - let command = SubCommand::with_name("upload-keys") +pub fn subcommand() -> App<'static> { + let command = App::new("upload-keys") .about("Upload keys to remote hosts") .long_about(r#"Upload keys to remote hosts This subcommand behaves as if you invoked `apply` with the pseudo `keys` goal."#) - .arg(Arg::with_name("goal") - .hidden(true) + .arg(Arg::new("goal") + .hide(true) .default_value("keys") .possible_values(&["keys"]) .takes_value(true)); diff --git a/src/troubleshooter.rs b/src/troubleshooter.rs index cdfa4f7..2bc92c2 100644 --- a/src/troubleshooter.rs +++ b/src/troubleshooter.rs @@ -10,8 +10,8 @@ use clap::ArgMatches; use crate::nix::NixError; /// Runs a closure and tries to troubleshoot if it returns an error. -pub async fn run_wrapped<'a, F, U, T>(global_args: &'a ArgMatches<'a>, local_args: &'a ArgMatches<'a>, f: U) -> T - where U: FnOnce(&'a ArgMatches<'a>, &'a ArgMatches<'a>) -> F, +pub async fn run_wrapped<'a, F, U, T>(global_args: &'a ArgMatches, local_args: &'a ArgMatches, f: U) -> T + where U: FnOnce(&'a ArgMatches, &'a ArgMatches) -> F, F: Future>, { match f(global_args, local_args).await { @@ -30,7 +30,7 @@ pub async fn run_wrapped<'a, F, U, T>(global_args: &'a ArgMatches<'a>, local_arg } } -fn troubleshoot(global_args: &ArgMatches<'_>, _local_args: &ArgMatches<'_>, error: &NixError) -> Result<(), NixError> { +fn troubleshoot(global_args: &ArgMatches, _local_args: &ArgMatches, error: &NixError) -> Result<(), NixError> { if let NixError::NoFlakesSupport = error { // People following the tutorial might put hive.nix directly // in their Colmena checkout, and encounter NoFlakesSupport diff --git a/src/util.rs b/src/util.rs index 2c54dc2..d25448b 100644 --- a/src/util.rs +++ b/src/util.rs @@ -81,7 +81,7 @@ impl CommandExecution { } } -pub async fn hive_from_args(args: &ArgMatches<'_>) -> NixResult { +pub async fn hive_from_args(args: &ArgMatches) -> NixResult { let path = match args.occurrences_of("config") { 0 => { // traverse upwards until we find hive.nix @@ -157,9 +157,9 @@ pub async fn hive_from_args(args: &ArgMatches<'_>) -> NixResult { Ok(hive) } -pub fn register_selector_args<'a, 'b>(command: App<'a, 'b>) -> App<'a, 'b> { +pub fn register_selector_args<'a>(command: App<'a>) -> App<'a> { command - .arg(Arg::with_name("on") + .arg(Arg::new("on") .long("on") .value_name("NODES") .help("Node selector")