diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/clap_builder | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/clap_builder')
25 files changed, 527 insertions, 738 deletions
diff --git a/vendor/clap_builder/.cargo-checksum.json b/vendor/clap_builder/.cargo-checksum.json index 49edd85e7..715fae273 100644 --- a/vendor/clap_builder/.cargo-checksum.json +++ b/vendor/clap_builder/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"4b3e166dee65d81470b5f5cdeecef99a31f264f56432fb311b450999b5fb40f4","LICENSE-APACHE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","LICENSE-MIT":"0d687e1f07b58fe68bda74668ff6326125e5e5efa184cce755cd84ac535b7058","README.md":"60b99346464866941b21928d3c4699fd6a3ca85a541da7577f60bc691b7afef8","src/builder/action.rs":"c68eff7584e63c94f0ba496613b46658c6001156b791bd9cda56a8d153f1a315","src/builder/app_settings.rs":"cd415ef9eb8f7b810b0aad53049d9e8c92ea4036d45862ce3d3e701ef613a36c","src/builder/arg.rs":"5f382f7f49e80f8d20c173916aeffe72b9d03a3a97e2378536f320bc81f32ade","src/builder/arg_group.rs":"82a6e9afeea1792a4ca99baa3b0d3235eb012b037cc19333ed9b03a13bb66f30","src/builder/arg_predicate.rs":"4fe55fdd0441acb1577f28188c86f920df4863f451a7dcad8e050dbb6e1e7516","src/builder/arg_settings.rs":"7361b61da218c4fbe96a33a9a9b59e627f77921c45ed8a0280798920a17b6c40","src/builder/command.rs":"c284805777f941c6624cd95f5550d2f8b1aca5fcef8832a3f34a72a907438aa4","src/builder/debug_asserts.rs":"37eb93326b9edc3050bdf1fc013167c42f56a49ba4937244a2fd882417a34c8f","src/builder/ext.rs":"736cfb56f765cbe23301ebcad83fbe3edfc778954edc4747ccf7c23104d85638","src/builder/mod.rs":"5be61d8febaf052f8997edfa88c97d02f271234e2efa672cf686786cf4b93720","src/builder/os_str.rs":"2b635e4fa8ecc42ad1d964a8b2f0fe17aa57d976c163d3bf77f213de254d844f","src/builder/possible_value.rs":"7a5de55be6a6c6d0d4d19781de6dd8dbf744fdca142273f52f8e956c89a255cb","src/builder/range.rs":"bdaa3da849b74dc42a6b6ace87870329d34632e93fa9905a45b2fe86f549220a","src/builder/resettable.rs":"c4cd481051ec361529817ebae73b4dd307b0a4a3b88a3ddcecb8dd45b05db431","src/builder/str.rs":"e51a1e5c18364c9132d1c7df113e6a462265e40f767087fa9664bfcd5f5d91b4","src/builder/styled_str.rs":"52e7811859e826c5249c6bd873fc45876f9ff7ac533a561dfe0143eb5aac58eb","src/builder/tests.rs":"565f5efd38c6596e55fa1c077a11cc07be94ca201527963d27fd42ddce6dbbe8","src/builder/value_hint.rs":"4f5a577d4f935fc7557fbfb2c706a7dc13b8c43a2ca6a437948c5260ce113d9f","src/builder/value_parser.rs":"e6937b33bc0feb3be576ec0c7bc9baa2dc10c952be7bcb810142da288defbe2d","src/derive.rs":"201404c128c92ce59d6c88931ba789e389508334852b758ae620aa3e2ccf930c","src/error/context.rs":"156d2611a349ce826378476c9dcb3242a01ad834a095baad096a10cc2f73e1ed","src/error/format.rs":"87a2926d6226ef74c76e0e1ca1efa0ebaeb52fc661b1f96b45b329a47dabbf7d","src/error/kind.rs":"29603c64b8cea7886498afc3f7e7c489505c9820c5159e99d153d57fdafe95ec","src/error/mod.rs":"8d840a5b8ed175a3a30c5321041e3d32a0a071b306999a8c19c6584e165e6899","src/lib.rs":"9295447fadf8a95dfcffa93bf5824c5235d8b3449cd5d1463d88b291f40972f6","src/macros.rs":"b110161fae025e597c7fafafd936174c0de4a21b1cbc13b0774827bb37ae3500","src/mkeymap.rs":"473eb25f9bf0017ade3a93e4cf6d27da4e3f5b4b64767a090cadbb56b9483957","src/output/fmt.rs":"17d7c95bae851fd0ffb7d3ea4c3c1830963c8b863aa8e4e296e3d824a1da18dc","src/output/help.rs":"1eea985c582395431ae5a8de6c1fcc4ca76317f61144ef46c6d530fda330ea7a","src/output/help_template.rs":"b231e3d21a9545175e5d943dd40b10e63e061dc14f9863aac735bcba9323b314","src/output/mod.rs":"74ea52be8981c30d10fda3f6c80cf51aafb15700de99aa73bc94700bca25ae11","src/output/textwrap/core.rs":"d9d1af1cd031963b85611993849cd7a532e2ebb4ba05f55ae1f2fb8738899a88","src/output/textwrap/mod.rs":"95e9f51bc98630634ae8b8a5f553efbdba05cb9cdb01d394aa293afb5d90803f","src/output/textwrap/word_separators.rs":"0bb065943ae639117a3813ff38587421a0eed24f2bcf92854657383d4b7bbfce","src/output/textwrap/wrap_algorithms.rs":"6c347cbba8e20d7ebcb85631318e1e51e9ac4e31fcb812ce5a5c9153eea0bc93","src/output/usage.rs":"0158fea0bddeb0562aeabb8ba24362982da826e78237c05db705a29725649a8b","src/parser/arg_matcher.rs":"be2b8fc5442f46c423e1cb6418d1f3be84e273c226a4f09fe5493a3c6331bc84","src/parser/error.rs":"7def6f001ad6dfd262d71149c6e4f3845a6f7bf246a92edc6d872e3ca4e2ae01","src/parser/features/mod.rs":"6ed075e97af56bff22f22ed1ee83ff6479360e05f9d3661a3145f822c242b694","src/parser/features/suggestions.rs":"832b62f927f9f4ffb95abdcef09c8b675045aab0b5471bae484e5d07f18f7621","src/parser/matches/arg_matches.rs":"c26f804b7375ab133917dfe8893d5710ab510da24a2ffa6946253c84c1ba4eb4","src/parser/matches/matched_arg.rs":"8533197ac8f1a1a218844c34923beabd0ed0d28447b03bd9d4d199cc7ff251d0","src/parser/matches/mod.rs":"5578335f4b9103cc4060546621e5664d5e92c43848ec48c2d95a4b045373de1f","src/parser/matches/value_source.rs":"ecb9e09db06579489daa9cbcf351381041dff7c5e2956fb96052b70b9360955b","src/parser/mod.rs":"34d689dac5d878790e5c29872f59ccec000ceab737ddaa642054cb464e26edb8","src/parser/parser.rs":"60756b65a24e3e793c00ec22de2303a9ecf38150dc9ff61f3d527e89dadd4a91","src/parser/validator.rs":"954924b2a124d5d5753832ff2d494cf2372d2d5117c6c7f2898e896a8fc5856c","src/util/any_value.rs":"4706ddf9dc19e45b3a679a68851a3f9c45690e22775548edf217dddde723de97","src/util/color.rs":"3195f2f83d0f319f17d3f155453c0e102ad145616b51c9bbde9472e318ee0c6f","src/util/flat_map.rs":"89e6471d099485f943ed7331626db6fddd75598f2c98623a13f262ff1a08b509","src/util/flat_set.rs":"334f3b8a72a897fbabd68f2330a8ecc18af74492036822b2e3764d461ddf31b4","src/util/graph.rs":"f35396b6e2a427377dcbbca69b1b98737d89684a3834cfda98cbf8cc70ff9c2f","src/util/id.rs":"5f025a05e4752ef7d610d6490f4a83ab489b1e5038c1a15067c0be51caafde87","src/util/mod.rs":"010f54d58906f4ae0106f2f1a891ea80a55fd52c64b8946a6b59e20f9c502418","src/util/str_to_bool.rs":"1ce90b4939a884eeefc73392722bdfcf906e3070c4398e1557c586c10c684cd0"},"package":"84080e799e54cff944f4b4a4b0e71630b0e0443b25b985175c7dddc1a859b749"}
\ No newline at end of file +{"files":{"Cargo.toml":"dad9147ab3cb6debd20bf49fab7f302221613b0de8605365aa4d92a16730f9b6","LICENSE-APACHE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","LICENSE-MIT":"0d687e1f07b58fe68bda74668ff6326125e5e5efa184cce755cd84ac535b7058","README.md":"60b99346464866941b21928d3c4699fd6a3ca85a541da7577f60bc691b7afef8","src/builder/action.rs":"c68eff7584e63c94f0ba496613b46658c6001156b791bd9cda56a8d153f1a315","src/builder/app_settings.rs":"286f925717fa54fe9d2ed6f2f338293b7a5981fee0fe687fe706118cebf1f6f4","src/builder/arg.rs":"3084e103153c1b511ff3fe9e11b98ae8dfbf4a749707892538ddf244e7379ccf","src/builder/arg_group.rs":"82a6e9afeea1792a4ca99baa3b0d3235eb012b037cc19333ed9b03a13bb66f30","src/builder/arg_predicate.rs":"4fe55fdd0441acb1577f28188c86f920df4863f451a7dcad8e050dbb6e1e7516","src/builder/arg_settings.rs":"e8ad1bd6d36da43d7329b6cd86833d4cc63734e64119c6b950a45ded5e3aec9c","src/builder/command.rs":"44e27c4902eda449c80aeff986eb25ebf70828662e420b33940c43e1dbc0af9c","src/builder/debug_asserts.rs":"d98f70a6d6f568a6cd47c0ea5cdad0bce132370c5cd59d8602c692448e4a9fc9","src/builder/ext.rs":"736cfb56f765cbe23301ebcad83fbe3edfc778954edc4747ccf7c23104d85638","src/builder/mod.rs":"5be61d8febaf052f8997edfa88c97d02f271234e2efa672cf686786cf4b93720","src/builder/os_str.rs":"2b635e4fa8ecc42ad1d964a8b2f0fe17aa57d976c163d3bf77f213de254d844f","src/builder/possible_value.rs":"2ed44c5a353c0abab337ac0f00995066f96ff27c33098613642725991163edff","src/builder/range.rs":"bdaa3da849b74dc42a6b6ace87870329d34632e93fa9905a45b2fe86f549220a","src/builder/resettable.rs":"c4cd481051ec361529817ebae73b4dd307b0a4a3b88a3ddcecb8dd45b05db431","src/builder/str.rs":"e51a1e5c18364c9132d1c7df113e6a462265e40f767087fa9664bfcd5f5d91b4","src/builder/styled_str.rs":"52e7811859e826c5249c6bd873fc45876f9ff7ac533a561dfe0143eb5aac58eb","src/builder/tests.rs":"565f5efd38c6596e55fa1c077a11cc07be94ca201527963d27fd42ddce6dbbe8","src/builder/value_hint.rs":"66588792cddf7e3bb2912da4e0a53584169c266f9e4e6dcb990295998d158f93","src/builder/value_parser.rs":"03fc008a18f69ef1924720b3c270c03074b24c0e1952632283aa370bff955da8","src/derive.rs":"201404c128c92ce59d6c88931ba789e389508334852b758ae620aa3e2ccf930c","src/error/context.rs":"156d2611a349ce826378476c9dcb3242a01ad834a095baad096a10cc2f73e1ed","src/error/format.rs":"33903b182f9b8fde0a2ad2f5f96582ed3812d37c51a03f2c775553db8351e5e8","src/error/kind.rs":"29603c64b8cea7886498afc3f7e7c489505c9820c5159e99d153d57fdafe95ec","src/error/mod.rs":"42f1f0e1f6fd8de76bd2f6cb825a5ca083a95e53e0ecc47a6e87b9b7b150b828","src/lib.rs":"9295447fadf8a95dfcffa93bf5824c5235d8b3449cd5d1463d88b291f40972f6","src/macros.rs":"fc190536cd2b39cfe6b55a351df3f8402e81c6a6966208d1fdb36c4b48dbc72f","src/mkeymap.rs":"473eb25f9bf0017ade3a93e4cf6d27da4e3f5b4b64767a090cadbb56b9483957","src/output/fmt.rs":"17d7c95bae851fd0ffb7d3ea4c3c1830963c8b863aa8e4e296e3d824a1da18dc","src/output/help.rs":"1eea985c582395431ae5a8de6c1fcc4ca76317f61144ef46c6d530fda330ea7a","src/output/help_template.rs":"a386c31d136a17c7f26130027b2969084d88cd9eb50bcc5680586c13649d99b6","src/output/mod.rs":"74ea52be8981c30d10fda3f6c80cf51aafb15700de99aa73bc94700bca25ae11","src/output/textwrap/core.rs":"0d45b1ebe8bba3e54e8bcbfec015be626d55803a0a46aef753eb3a4be3cabab4","src/output/textwrap/mod.rs":"1bc5056701b6651a98b0eea482db5235ba3342a24a02d776ad364fec6919cecc","src/output/textwrap/word_separators.rs":"ae3af310295e707ae1aa95633f6bb078cedf8f65662a86caa9d25420f459acc1","src/output/textwrap/wrap_algorithms.rs":"a6eb1491ef5e64dbd2ef55d367e46747fcf2fb22fdb66a2b7c3cb9ba3a02d86a","src/output/usage.rs":"620e2fa7f6b30954a6ed8a9b90d1b99cdcf1e85c446c1c176430e7cbb02648d0","src/parser/arg_matcher.rs":"b6f17cfc48d18d192d6f4f45b9daf342b93d847ce7d52a3f68266c15566c3849","src/parser/error.rs":"7def6f001ad6dfd262d71149c6e4f3845a6f7bf246a92edc6d872e3ca4e2ae01","src/parser/features/mod.rs":"6ed075e97af56bff22f22ed1ee83ff6479360e05f9d3661a3145f822c242b694","src/parser/features/suggestions.rs":"832b62f927f9f4ffb95abdcef09c8b675045aab0b5471bae484e5d07f18f7621","src/parser/matches/arg_matches.rs":"8386f3d69141678074751ee26c8d7888fe320d07cc1fb6034341adb99f4eee13","src/parser/matches/matched_arg.rs":"8533197ac8f1a1a218844c34923beabd0ed0d28447b03bd9d4d199cc7ff251d0","src/parser/matches/mod.rs":"5578335f4b9103cc4060546621e5664d5e92c43848ec48c2d95a4b045373de1f","src/parser/matches/value_source.rs":"ecb9e09db06579489daa9cbcf351381041dff7c5e2956fb96052b70b9360955b","src/parser/mod.rs":"34d689dac5d878790e5c29872f59ccec000ceab737ddaa642054cb464e26edb8","src/parser/parser.rs":"126feed5249afe8939a7a7b86587fd085d92287561567ea8e218c7e925b4d6c4","src/parser/validator.rs":"107c4eaa1615c0414553862f0250e9bf4241cccb7d7ec6df4ac8784f5f850d11","src/util/any_value.rs":"f3666cf322e87daf83f1474d5449e9b526b80b835f032e4090c5e1abddf6f044","src/util/color.rs":"04cc72927ad1e7f5490e1db39b7f79b16ed613b7b81cfe0285b38ba9d0afb875","src/util/flat_map.rs":"89e6471d099485f943ed7331626db6fddd75598f2c98623a13f262ff1a08b509","src/util/flat_set.rs":"334f3b8a72a897fbabd68f2330a8ecc18af74492036822b2e3764d461ddf31b4","src/util/graph.rs":"f35396b6e2a427377dcbbca69b1b98737d89684a3834cfda98cbf8cc70ff9c2f","src/util/id.rs":"5f025a05e4752ef7d610d6490f4a83ab489b1e5038c1a15067c0be51caafde87","src/util/mod.rs":"010f54d58906f4ae0106f2f1a891ea80a55fd52c64b8946a6b59e20f9c502418","src/util/str_to_bool.rs":"1ce90b4939a884eeefc73392722bdfcf906e3070c4398e1557c586c10c684cd0"},"package":"ef137bbe35aab78bdb468ccfba75a5f4d8321ae011d34063770780545176af2d"}
\ No newline at end of file diff --git a/vendor/clap_builder/Cargo.toml b/vendor/clap_builder/Cargo.toml index 4ea79af6a..0f05ef88f 100644 --- a/vendor/clap_builder/Cargo.toml +++ b/vendor/clap_builder/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" rust-version = "1.64.0" name = "clap_builder" -version = "4.2.4" +version = "4.3.10" include = [ "build.rs", "src/**/*", @@ -37,22 +37,22 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/clap-rs/clap" [package.metadata.docs.rs] +cargo-args = [ + "-Zunstable-options", + "-Zrustdoc-scrape-examples", +] features = ["unstable-doc"] rustdoc-args = [ "--cfg", "docsrs", ] -cargo-args = [ - "-Zunstable-options", - "-Zrustdoc-scrape-examples", -] [package.metadata.playground] features = ["unstable-doc"] [package.metadata.release] -shared-version = true dependent-version = "upgrade" +shared-version = true tag-name = "v{{version}}" [lib] @@ -69,11 +69,8 @@ version = "1.0.0" version = "0.3.67" optional = true -[dependencies.bitflags] -version = "1.2.0" - [dependencies.clap_lex] -version = "0.4.0" +version = "0.5.0" [dependencies.once_cell] version = "1.12.0" @@ -108,16 +105,16 @@ version = "1.0.12" version = "1.1.0" [dev-dependencies.snapbox] -version = "0.4.10" +version = "0.4.11" [dev-dependencies.static_assertions] version = "1.1.0" [dev-dependencies.trybuild] -version = "1.0.77" +version = "1.0.80" [dev-dependencies.trycmd] -version = "0.14.15" +version = "0.14.16" features = [ "color-auto", "diff", diff --git a/vendor/clap_builder/src/builder/app_settings.rs b/vendor/clap_builder/src/builder/app_settings.rs index 7a9ff8c69..4fce4b4a2 100644 --- a/vendor/clap_builder/src/builder/app_settings.rs +++ b/vendor/clap_builder/src/builder/app_settings.rs @@ -1,21 +1,35 @@ -// Std -use std::ops::BitOr; - #[allow(unused)] use crate::Arg; #[allow(unused)] use crate::Command; -// Third party -use bitflags::bitflags; +#[derive(Default, Copy, Clone, Debug, PartialEq, Eq)] +pub(crate) struct AppFlags(u32); + +impl AppFlags { + pub(crate) fn set(&mut self, setting: AppSettings) { + self.0 |= setting.bit(); + } + + pub(crate) fn unset(&mut self, setting: AppSettings) { + self.0 &= !setting.bit(); + } + + pub(crate) fn is_set(&self, setting: AppSettings) -> bool { + self.0 & setting.bit() != 0 + } + + pub(crate) fn insert(&mut self, other: Self) { + self.0 |= other.0; + } +} -#[doc(hidden)] -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub(crate) struct AppFlags(Flags); +impl std::ops::BitOr for AppFlags { + type Output = Self; -impl Default for AppFlags { - fn default() -> Self { - AppFlags(Flags::COLOR_AUTO) + fn bitor(mut self, rhs: Self) -> Self::Output { + self.insert(rhs); + self } } @@ -26,7 +40,7 @@ impl Default for AppFlags { /// /// [`Command`]: crate::Command #[derive(Debug, PartialEq, Copy, Clone)] -#[non_exhaustive] +#[repr(u8)] pub(crate) enum AppSettings { IgnoreErrors, AllowHyphenValues, @@ -62,111 +76,8 @@ pub(crate) enum AppSettings { BinNameBuilt, } -bitflags! { - struct Flags: u64 { - const SC_NEGATE_REQS = 1; - const SC_REQUIRED = 1 << 1; - const ARG_REQUIRED_ELSE_HELP = 1 << 2; - const PROPAGATE_VERSION = 1 << 3; - const DISABLE_VERSION_FOR_SC = 1 << 4; - const WAIT_ON_ERROR = 1 << 6; - const DISABLE_VERSION_FLAG = 1 << 10; - const HIDDEN = 1 << 11; - const TRAILING_VARARG = 1 << 12; - const NO_BIN_NAME = 1 << 13; - const ALLOW_UNK_SC = 1 << 14; - const LEADING_HYPHEN = 1 << 16; - const NO_POS_VALUES = 1 << 17; - const NEXT_LINE_HELP = 1 << 18; - const DISABLE_COLORED_HELP = 1 << 20; - const COLOR_ALWAYS = 1 << 21; - const COLOR_AUTO = 1 << 22; - const COLOR_NEVER = 1 << 23; - const DONT_DELIM_TRAIL = 1 << 24; - const ALLOW_NEG_NUMS = 1 << 25; - const DISABLE_HELP_SC = 1 << 27; - const ARGS_NEGATE_SCS = 1 << 29; - const PROPAGATE_VALS_DOWN = 1 << 30; - const ALLOW_MISSING_POS = 1 << 31; - const TRAILING_VALUES = 1 << 32; - const BUILT = 1 << 33; - const BIN_NAME_BUILT = 1 << 34; - const VALID_ARG_FOUND = 1 << 35; - const INFER_SUBCOMMANDS = 1 << 36; - const CONTAINS_LAST = 1 << 37; - const ARGS_OVERRIDE_SELF = 1 << 38; - const HELP_REQUIRED = 1 << 39; - const SUBCOMMAND_PRECEDENCE_OVER_ARG = 1 << 40; - const DISABLE_HELP_FLAG = 1 << 41; - const INFER_LONG_ARGS = 1 << 43; - const IGNORE_ERRORS = 1 << 44; - const MULTICALL = 1 << 45; - const EXPAND_HELP_SUBCOMMAND_TREES = 1 << 46; - const NO_OP = 0; +impl AppSettings { + fn bit(self) -> u32 { + 1 << (self as u8) } } - -impl_settings! { AppSettings, AppFlags, - ArgRequiredElseHelp - => Flags::ARG_REQUIRED_ELSE_HELP, - SubcommandPrecedenceOverArg - => Flags::SUBCOMMAND_PRECEDENCE_OVER_ARG, - ArgsNegateSubcommands - => Flags::ARGS_NEGATE_SCS, - AllowExternalSubcommands - => Flags::ALLOW_UNK_SC, - AllowHyphenValues - => Flags::LEADING_HYPHEN, - AllowNegativeNumbers - => Flags::ALLOW_NEG_NUMS, - AllowMissingPositional - => Flags::ALLOW_MISSING_POS, - ColorAlways - => Flags::COLOR_ALWAYS, - ColorAuto - => Flags::COLOR_AUTO, - ColorNever - => Flags::COLOR_NEVER, - DontDelimitTrailingValues - => Flags::DONT_DELIM_TRAIL, - DisableColoredHelp - => Flags::DISABLE_COLORED_HELP, - DisableHelpSubcommand - => Flags::DISABLE_HELP_SC, - DisableHelpFlag - => Flags::DISABLE_HELP_FLAG, - DisableVersionFlag - => Flags::DISABLE_VERSION_FLAG, - PropagateVersion - => Flags::PROPAGATE_VERSION, - HidePossibleValues - => Flags::NO_POS_VALUES, - HelpExpected - => Flags::HELP_REQUIRED, - Hidden - => Flags::HIDDEN, - Multicall - => Flags::MULTICALL, - NoBinaryName - => Flags::NO_BIN_NAME, - SubcommandsNegateReqs - => Flags::SC_NEGATE_REQS, - SubcommandRequired - => Flags::SC_REQUIRED, - TrailingVarArg - => Flags::TRAILING_VARARG, - NextLineHelp - => Flags::NEXT_LINE_HELP, - IgnoreErrors - => Flags::IGNORE_ERRORS, - Built - => Flags::BUILT, - BinNameBuilt - => Flags::BIN_NAME_BUILT, - InferSubcommands - => Flags::INFER_SUBCOMMANDS, - AllArgsOverrideSelf - => Flags::ARGS_OVERRIDE_SELF, - InferLongArgs - => Flags::INFER_LONG_ARGS -} diff --git a/vendor/clap_builder/src/builder/arg.rs b/vendor/clap_builder/src/builder/arg.rs index ce7e02d87..5bfea9ad4 100644 --- a/vendor/clap_builder/src/builder/arg.rs +++ b/vendor/clap_builder/src/builder/arg.rs @@ -858,21 +858,15 @@ impl Arg { #[inline] #[must_use] - pub(crate) fn setting<F>(mut self, setting: F) -> Self - where - F: Into<ArgFlags>, - { - self.settings.insert(setting.into()); + pub(crate) fn setting(mut self, setting: ArgSettings) -> Self { + self.settings.set(setting); self } #[inline] #[must_use] - pub(crate) fn unset_setting<F>(mut self, setting: F) -> Self - where - F: Into<ArgFlags>, - { - self.settings.remove(setting.into()); + pub(crate) fn unset_setting(mut self, setting: ArgSettings) -> Self { + self.settings.unset(setting); self } } @@ -1656,8 +1650,6 @@ impl Arg { /// at runtime, nor were the conditions met for `Arg::default_value_if`, the `Arg::default_value` /// will be applied. /// - /// **NOTE:** This implicitly sets [`Arg::action(ArgAction::Set)`]. - /// /// # Examples /// /// First we use the default value without providing any value at runtime. @@ -2177,12 +2169,15 @@ impl Arg { /// Allows custom ordering of args within the help message. /// - /// Args with a lower value will be displayed first in the help message. This is helpful when - /// one would like to emphasise frequently used args, or prioritize those towards the top of - /// the list. Args with duplicate display orders will be displayed in the order they are - /// defined. + /// `Arg`s with a lower value will be displayed first in the help message. + /// Those with the same display order will be sorted. + /// + /// `Arg`s are automatically assigned a display order based on the order they are added to the + /// [`Command`][crate::Command]. + /// Overriding this is helpful when the order arguments are added in isn't the same as the + /// display order, whether in one-off cases or to automatically sort arguments. /// - /// **NOTE:** The default is 999 for all arguments. + /// To change, see [`Command::next_display_order`][crate::Command::next_display_order]. /// /// **NOTE:** This setting is ignored for [positional arguments] which are always displayed in /// [index] order. @@ -2194,22 +2189,23 @@ impl Arg { /// # use clap_builder as clap; /// # use clap::{Command, Arg, ArgAction}; /// let m = Command::new("prog") - /// .arg(Arg::new("a") // Typically args are grouped alphabetically by name. - /// // Args without a display_order have a value of 999 and are - /// // displayed alphabetically with all other 999 valued args. - /// .long("long-option") - /// .short('o') + /// .arg(Arg::new("boat") + /// .short('b') + /// .long("boat") /// .action(ArgAction::Set) + /// .display_order(0) // Sort /// .help("Some help and text")) - /// .arg(Arg::new("b") - /// .long("other-option") - /// .short('O') + /// .arg(Arg::new("airplane") + /// .short('a') + /// .long("airplane") /// .action(ArgAction::Set) - /// .display_order(1) // In order to force this arg to appear *first* - /// // all we have to do is give it a value lower than 999. - /// // Any other args with a value of 1 will be displayed - /// // alphabetically with this one...then 2 values, then 3, etc. + /// .display_order(0) // Sort /// .help("I should be first!")) + /// .arg(Arg::new("custom-help") + /// .short('?') + /// .action(ArgAction::Help) + /// .display_order(100) // Don't sort + /// .help("Alt help")) /// .get_matches_from(vec![ /// "prog", "--help" /// ]); @@ -2224,10 +2220,10 @@ impl Arg { /// Usage: cust-ord [OPTIONS] /// /// Options: - /// -h, --help Print help information - /// -V, --version Print version information - /// -O, --other-option <b> I should be first! - /// -o, --long-option <a> Some help and text + /// -a, --airplane <airplane> I should be first! + /// -b, --boat <boar> Some help and text + /// -h, --help Print help information + /// -? Alt help /// ``` /// [positional arguments]: Arg::index() /// [index]: Arg::index() @@ -2738,8 +2734,6 @@ impl Arg { /// and `Arg::default_value_if`, and the user **did not** provide this arg at runtime, nor were /// the conditions met for `Arg::default_value_if`, the `Arg::default_value` will be applied. /// - /// **NOTE:** This implicitly sets [`Arg::action(ArgAction::Set)`]. - /// /// # Examples /// /// First we use the default value only if another arg is present at runtime. @@ -4107,7 +4101,7 @@ impl Arg { /// let value_parser = cmd.get_arguments() /// .find(|a| a.get_id() == "port").unwrap() /// .get_value_parser(); - /// println!("{:?}", value_parser); + /// println!("{value_parser:?}"); /// ``` pub fn get_value_parser(&self) -> &super::ValueParser { if let Some(value_parser) = self.value_parser.as_ref() { @@ -4793,15 +4787,4 @@ mod test { assert_eq!(p.to_string(), "<file1> <file2>"); } - - #[test] - fn positional_display_val_names_req() { - let mut p = Arg::new("pos") - .index(1) - .required(true) - .value_names(["file1", "file2"]); - p._build(); - - assert_eq!(p.to_string(), "<file1> <file2>"); - } } diff --git a/vendor/clap_builder/src/builder/arg_settings.rs b/vendor/clap_builder/src/builder/arg_settings.rs index b8bc069c5..fd4750404 100644 --- a/vendor/clap_builder/src/builder/arg_settings.rs +++ b/vendor/clap_builder/src/builder/arg_settings.rs @@ -1,18 +1,33 @@ -// Std -use std::ops::BitOr; - -// Third party -use bitflags::bitflags; - #[allow(unused)] use crate::Arg; -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub(crate) struct ArgFlags(Flags); +#[derive(Default, Copy, Clone, Debug, PartialEq, Eq)] +pub(crate) struct ArgFlags(u32); + +impl ArgFlags { + pub(crate) fn set(&mut self, setting: ArgSettings) { + self.0 |= setting.bit(); + } + + pub(crate) fn unset(&mut self, setting: ArgSettings) { + self.0 &= !setting.bit(); + } + + pub(crate) fn is_set(&self, setting: ArgSettings) -> bool { + self.0 & setting.bit() != 0 + } -impl Default for ArgFlags { - fn default() -> Self { - Self::empty() + pub(crate) fn insert(&mut self, other: Self) { + self.0 |= other.0; + } +} + +impl std::ops::BitOr for ArgFlags { + type Output = Self; + + fn bitor(mut self, rhs: Self) -> Self::Output { + self.insert(rhs); + self } } @@ -25,7 +40,7 @@ impl Default for ArgFlags { /// [`Arg::unset_setting`]: crate::Arg::unset_setting() /// [`Arg::is_set`]: crate::Arg::is_set() #[derive(Debug, PartialEq, Copy, Clone)] -#[non_exhaustive] +#[repr(u8)] pub(crate) enum ArgSettings { Required, Global, @@ -48,54 +63,12 @@ pub(crate) enum ArgSettings { Exclusive, } -bitflags! { - struct Flags: u32 { - const REQUIRED = 1; - const GLOBAL = 1 << 3; - const HIDDEN = 1 << 4; - const TRAILING_VARARG = 1 << 5; - const ALLOW_NEG_NUMS = 1 << 6; - const NEXT_LINE_HELP = 1 << 7; - const DELIM_NOT_SET = 1 << 10; - const HIDE_POS_VALS = 1 << 11; - const ALLOW_TAC_VALS = 1 << 12; - const REQUIRE_EQUALS = 1 << 13; - const LAST = 1 << 14; - const HIDE_DEFAULT_VAL = 1 << 15; - const CASE_INSENSITIVE = 1 << 16; - #[cfg(feature = "env")] - const HIDE_ENV_VALS = 1 << 17; - const HIDDEN_SHORT_H = 1 << 18; - const HIDDEN_LONG_H = 1 << 19; - #[cfg(feature = "env")] - const HIDE_ENV = 1 << 21; - const EXCLUSIVE = 1 << 23; - const NO_OP = 0; +impl ArgSettings { + fn bit(self) -> u32 { + 1 << (self as u8) } } -impl_settings! { ArgSettings, ArgFlags, - Required => Flags::REQUIRED, - Global => Flags::GLOBAL, - Hidden => Flags::HIDDEN, - NextLineHelp => Flags::NEXT_LINE_HELP, - HidePossibleValues => Flags::HIDE_POS_VALS, - AllowHyphenValues => Flags::ALLOW_TAC_VALS, - AllowNegativeNumbers => Flags::ALLOW_NEG_NUMS, - RequireEquals => Flags::REQUIRE_EQUALS, - Last => Flags::LAST, - TrailingVarArg => Flags::TRAILING_VARARG, - IgnoreCase => Flags::CASE_INSENSITIVE, - #[cfg(feature = "env")] - HideEnv => Flags::HIDE_ENV, - #[cfg(feature = "env")] - HideEnvValues => Flags::HIDE_ENV_VALS, - HideDefaultValue => Flags::HIDE_DEFAULT_VAL, - HiddenShortHelp => Flags::HIDDEN_SHORT_H, - HiddenLongHelp => Flags::HIDDEN_LONG_H, - Exclusive => Flags::EXCLUSIVE -} - #[cfg(test)] mod test { use super::*; @@ -115,31 +88,4 @@ mod test { let m = m.unset_setting(ArgSettings::Required); assert!(!m.is_required_set(), "{m:#?}"); } - - #[test] - fn setting_bitor() { - let m = Arg::new("setting_bitor") - .setting(ArgSettings::Required | ArgSettings::Hidden | ArgSettings::Last); - - assert!(m.is_required_set()); - assert!(m.is_hide_set()); - assert!(m.is_last_set()); - } - - #[test] - fn unset_setting_bitor() { - let m = Arg::new("unset_setting_bitor") - .setting(ArgSettings::Required) - .setting(ArgSettings::Hidden) - .setting(ArgSettings::Last); - - assert!(m.is_required_set()); - assert!(m.is_hide_set()); - assert!(m.is_last_set()); - - let m = m.unset_setting(ArgSettings::Required | ArgSettings::Hidden | ArgSettings::Last); - assert!(!m.is_required_set(), "{m:#?}"); - assert!(!m.is_hide_set(), "{m:#?}"); - assert!(!m.is_last_set(), "{m:#?}"); - } } diff --git a/vendor/clap_builder/src/builder/command.rs b/vendor/clap_builder/src/builder/command.rs index 799623581..2c5eb1989 100644 --- a/vendor/clap_builder/src/builder/command.rs +++ b/vendor/clap_builder/src/builder/command.rs @@ -105,6 +105,7 @@ pub struct Command { subcommand_heading: Option<Str>, external_value_parser: Option<super::ValueParser>, long_help_exists: bool, + deferred: Option<fn(Command) -> Command>, app_ext: Extensions, } @@ -209,8 +210,6 @@ impl Command { /// Allows one to mutate an [`Arg`] after it's been added to a [`Command`]. /// - /// This can be useful for modifying the auto-generated help or version arguments. - /// /// # Panics /// /// If the argument is undefined @@ -430,6 +429,30 @@ impl Command { self } + /// Delay initialization for parts of the `Command` + /// + /// This is useful for large applications to delay definitions of subcommands until they are + /// being invoked. + /// + /// # Examples + /// + /// ```rust + /// # use clap_builder as clap; + /// # use clap::{Command, arg}; + /// Command::new("myprog") + /// .subcommand(Command::new("config") + /// .about("Controls configuration features") + /// .defer(|cmd| { + /// cmd.arg(arg!(<config> "Required configuration file to use")) + /// }) + /// ) + /// # ; + /// ``` + pub fn defer(mut self, deferred: fn(Command) -> Command) -> Self { + self.deferred = Some(deferred); + self + } + /// Catch problems earlier in the development cycle. /// /// Most error states are handled as asserts under the assumption they are programming mistake @@ -686,10 +709,7 @@ impl Command { if let Some(command) = argv0.file_stem().and_then(|f| f.to_str()) { // Stop borrowing command so we can get another mut ref to it. let command = command.to_owned(); - debug!( - "Command::try_get_matches_from_mut: Parsed command {} from argv", - command - ); + debug!("Command::try_get_matches_from_mut: Parsed command {command} from argv"); debug!("Command::try_get_matches_from_mut: Reinserting command into arguments so subcommand parser matches it"); raw_args.insert(&cursor, [&command]); @@ -791,7 +811,7 @@ impl Command { /// let mut cmd = Command::new("myprog"); /// let mut out = io::stdout(); /// let help = cmd.render_help(); - /// println!("{}", help); + /// println!("{help}"); /// ``` /// [`io::Write`]: std::io::Write /// [`-h` (short)]: Arg::help() @@ -818,7 +838,7 @@ impl Command { /// let mut cmd = Command::new("myprog"); /// let mut out = io::stdout(); /// let help = cmd.render_long_help(); - /// println!("{}", help); + /// println!("{help}"); /// ``` /// [`io::Write`]: std::io::Write /// [`-h` (short)]: Arg::help() @@ -986,7 +1006,7 @@ impl Command { /// /// let r = cmd.try_get_matches_from(vec!["cmd", "-c", "file", "-f", "-x"]); /// - /// assert!(r.is_ok(), "unexpected error: {:?}", r); + /// assert!(r.is_ok(), "unexpected error: {r:?}"); /// let m = r.unwrap(); /// assert_eq!(m.get_one::<String>("config").unwrap(), "file"); /// assert!(m.get_flag("f")); @@ -1265,6 +1285,8 @@ impl Command { /// Disables the `help` [`subcommand`]. /// + /// **NOTE:** This choice is propagated to all child subcommands. + /// /// # Examples /// /// ```rust @@ -1885,21 +1907,15 @@ impl Command { #[inline] #[must_use] - pub(crate) fn setting<F>(mut self, setting: F) -> Self - where - F: Into<AppFlags>, - { - self.settings.insert(setting.into()); + pub(crate) fn setting(mut self, setting: AppSettings) -> Self { + self.settings.set(setting); self } #[inline] #[must_use] - pub(crate) fn unset_setting<F>(mut self, setting: F) -> Self - where - F: Into<AppFlags>, - { - self.settings.remove(setting.into()); + pub(crate) fn unset_setting(mut self, setting: AppSettings) -> Self { + self.settings.unset(setting); self } @@ -2576,13 +2592,13 @@ impl Command { /// Set the placement of this subcommand within the help. /// - /// Subcommands with a lower value will be displayed first in the help message. Subcommands - /// with duplicate display orders will be displayed in order they are defined. - /// - /// This is helpful when one would like to emphasize frequently used subcommands, or prioritize - /// those towards the top of the list. + /// Subcommands with a lower value will be displayed first in the help message. + /// Those with the same display order will be sorted. /// - /// **NOTE:** The default is 999 for all subcommands. + /// `Command`s are automatically assigned a display order based on the order they are added to + /// their parent [`Command`]. + /// Overriding this is helpful when the order commands are added in isn't the same as the + /// display order, whether in one-off cases or to automatically sort commands. /// /// # Examples /// @@ -2591,17 +2607,11 @@ impl Command { /// # use clap_builder as clap; /// # use clap::{Command, }; /// let m = Command::new("cust-ord") - /// .subcommand(Command::new("alpha") // typically subcommands are grouped - /// // alphabetically by name. Subcommands - /// // without a display_order have a value of - /// // 999 and are displayed alphabetically with - /// // all other 999 subcommands - /// .about("Some help and text")) /// .subcommand(Command::new("beta") - /// .display_order(1) // In order to force this subcommand to appear *first* - /// // all we have to do is give it a value lower than 999. - /// // Any other subcommands with a value of 1 will be displayed - /// // alphabetically with this one...then 2 values, then 3, etc. + /// .display_order(0) // Sort + /// .about("Some help and text")) + /// .subcommand(Command::new("alpha") + /// .display_order(0) // Sort /// .about("I should be first!")) /// .get_matches_from(vec![ /// "cust-ord", "--help" @@ -2617,8 +2627,9 @@ impl Command { /// Usage: cust-ord [OPTIONS] /// /// Commands: - /// beta I should be first! - /// alpha Some help and text + /// alpha I should be first! + /// beta Some help and text + /// help Print help for the subcommand(s) /// /// Options: /// -h, --help Print help @@ -3697,7 +3708,7 @@ impl Command { /// let cmd = clap::Command::new("raw") /// .external_subcommand_value_parser(clap::value_parser!(String)); /// let value_parser = cmd.get_external_subcommand_value_parser(); - /// println!("{:?}", value_parser); + /// println!("{value_parser:?}"); /// ``` pub fn get_external_subcommand_value_parser(&self) -> Option<&super::ValueParser> { if !self.is_allow_external_subcommands_set() { @@ -3793,8 +3804,8 @@ impl Command { // do the real parsing let mut parser = Parser::new(self); if let Err(error) = parser.get_matches_with(&mut matcher, raw_args, args_cursor) { - if self.is_set(AppSettings::IgnoreErrors) { - debug!("Command::_do_parse: ignoring error: {}", error); + if self.is_set(AppSettings::IgnoreErrors) && error.use_stderr() { + debug!("Command::_do_parse: ignoring error: {error}"); } else { return Err(error); } @@ -3827,30 +3838,30 @@ impl Command { pub(crate) fn _build_self(&mut self, expand_help_tree: bool) { debug!("Command::_build: name={:?}", self.get_name()); if !self.settings.is_set(AppSettings::Built) { + if let Some(deferred) = self.deferred.take() { + *self = (deferred)(std::mem::take(self)); + } + // Make sure all the globally set flags apply to us as well self.settings = self.settings | self.g_settings; if self.is_multicall_set() { - self.settings.insert(AppSettings::SubcommandRequired.into()); - self.settings.insert(AppSettings::DisableHelpFlag.into()); - self.settings.insert(AppSettings::DisableVersionFlag.into()); + self.settings.set(AppSettings::SubcommandRequired); + self.settings.set(AppSettings::DisableHelpFlag); + self.settings.set(AppSettings::DisableVersionFlag); } if !cfg!(feature = "help") && self.get_override_help().is_none() { - self.settings.insert(AppSettings::DisableHelpFlag.into()); - self.settings - .insert(AppSettings::DisableHelpSubcommand.into()); + self.settings.set(AppSettings::DisableHelpFlag); + self.settings.set(AppSettings::DisableHelpSubcommand); } if self.is_set(AppSettings::ArgsNegateSubcommands) { - self.settings - .insert(AppSettings::SubcommandsNegateReqs.into()); + self.settings.set(AppSettings::SubcommandsNegateReqs); } if self.external_value_parser.is_some() { - self.settings - .insert(AppSettings::AllowExternalSubcommands.into()); + self.settings.set(AppSettings::AllowExternalSubcommands); } if !self.has_subcommands() { - self.settings - .insert(AppSettings::DisableHelpSubcommand.into()); + self.settings.set(AppSettings::DisableHelpSubcommand); } self._propagate(); @@ -3903,14 +3914,13 @@ impl Command { let is_allow_negative_numbers_set = self.is_allow_negative_numbers_set(); for arg in self.args.args_mut() { if is_allow_hyphen_values_set && arg.is_takes_value_set() { - arg.settings.insert(ArgSettings::AllowHyphenValues.into()); + arg.settings.set(ArgSettings::AllowHyphenValues); } if is_allow_negative_numbers_set && arg.is_takes_value_set() { - arg.settings - .insert(ArgSettings::AllowNegativeNumbers.into()); + arg.settings.set(ArgSettings::AllowNegativeNumbers); } if is_trailing_var_arg_set && arg.get_index() == Some(highest_idx) { - arg.settings.insert(ArgSettings::TrailingVarArg.into()); + arg.settings.set(ArgSettings::TrailingVarArg); } } } @@ -4033,7 +4043,7 @@ impl Command { } .to_owned(); - for mut sc in &mut self.subcommands { + for sc in &mut self.subcommands { debug!("Command::_build_bin_names:iter: bin_name set..."); if sc.usage_name.is_none() { @@ -4438,7 +4448,7 @@ impl Command { /// Iterate through the groups this arg is member of. pub(crate) fn groups_for_arg<'a>(&'a self, arg: &Id) -> impl Iterator<Item = Id> + 'a { - debug!("Command::groups_for_arg: id={:?}", arg); + debug!("Command::groups_for_arg: id={arg:?}"); let arg = arg.clone(); self.groups .iter() @@ -4478,7 +4488,7 @@ impl Command { } pub(crate) fn unroll_args_in_group(&self, group: &Id) -> Vec<Id> { - debug!("Command::unroll_args_in_group: group={:?}", group); + debug!("Command::unroll_args_in_group: group={group:?}"); let mut g_vec = vec![group]; let mut args = vec![]; @@ -4491,7 +4501,7 @@ impl Command { .args .iter() { - debug!("Command::unroll_args_in_group:iter: entity={:?}", n); + debug!("Command::unroll_args_in_group:iter: entity={n:?}"); if !args.contains(n) { if self.find(n).is_some() { debug!("Command::unroll_args_in_group:iter: this is an arg"); @@ -4655,6 +4665,7 @@ impl Default for Command { subcommand_heading: Default::default(), external_value_parser: Default::default(), long_help_exists: false, + deferred: None, app_ext: Default::default(), } } diff --git a/vendor/clap_builder/src/builder/debug_asserts.rs b/vendor/clap_builder/src/builder/debug_asserts.rs index 7a7fd6ae1..ef970cdaa 100644 --- a/vendor/clap_builder/src/builder/debug_asserts.rs +++ b/vendor/clap_builder/src/builder/debug_asserts.rs @@ -300,6 +300,28 @@ pub(crate) fn assert_app(cmd: &Command) { arg ); } + + for arg in &group.requires { + // Args listed inside groups should exist + assert!( + cmd.id_exists(arg), + "Command {}: Argument group '{}' requires non-existent '{}' id", + cmd.get_name(), + group.get_id(), + arg + ); + } + + for arg in &group.conflicts { + // Args listed inside groups should exist + assert!( + cmd.id_exists(arg), + "Command {}: Argument group '{}' conflicts with non-existent '{}' id", + cmd.get_name(), + group.get_id(), + arg + ); + } } // Conflicts between flags and subcommands @@ -460,7 +482,7 @@ fn assert_app_flags(cmd: &Command) { )+ if !s.is_empty() { - panic!("{}", s) + panic!("{s}") } } }; @@ -564,9 +586,8 @@ fn _verify_positionals(cmd: &Command) -> bool { || last.is_last_set(); assert!( ok, - "When using a positional argument with `.num_args(1..)` that is *not the \ - last* positional argument, the last positional argument (i.e. the one \ - with the highest index) *must* have .required(true) or .last(true) set." + "Positional argument `{last}` *must* have `required(true)` or `last(true)` set \ + because a prior positional argument (`{second_to_last}`) has `num_args(1..)`" ); // We make sure if the second to last is Multiple the last is ArgSettings::Last @@ -582,6 +603,7 @@ fn _verify_positionals(cmd: &Command) -> bool { .get_positionals() .filter(|p| { p.is_multiple_values_set() + && p.get_value_terminator().is_none() && !p.get_num_args().expect(INTERNAL_ERROR_MSG).is_fixed() }) .count(); diff --git a/vendor/clap_builder/src/builder/possible_value.rs b/vendor/clap_builder/src/builder/possible_value.rs index b0282e593..de7e543fe 100644 --- a/vendor/clap_builder/src/builder/possible_value.rs +++ b/vendor/clap_builder/src/builder/possible_value.rs @@ -162,18 +162,6 @@ impl PossibleValue { self.help.as_ref() } - /// Get the help specified for this argument, if any and the argument - /// value is not hidden - #[inline] - #[cfg(feature = "help")] - pub(crate) fn get_visible_help(&self) -> Option<&StyledStr> { - if !self.hide { - self.get_help() - } else { - None - } - } - /// Report if [`PossibleValue::hide`] is set #[inline] pub fn is_hide_set(&self) -> bool { diff --git a/vendor/clap_builder/src/builder/value_hint.rs b/vendor/clap_builder/src/builder/value_hint.rs index ee286b194..38fa862c1 100644 --- a/vendor/clap_builder/src/builder/value_hint.rs +++ b/vendor/clap_builder/src/builder/value_hint.rs @@ -24,11 +24,12 @@ use std::str::FromStr; /// /// [^1]: fish completions currently only support named arguments (e.g. -o or --opt), not /// positional arguments. -#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)] +#[derive(Debug, Default, PartialEq, Eq, Hash, Copy, Clone)] #[non_exhaustive] pub enum ValueHint { /// Default value if hint is not specified. Follows shell default behavior, which is usually /// auto-completing filenames. + #[default] Unknown, /// None of the hints below apply. Disables shell completion for this argument. Other, @@ -66,12 +67,6 @@ pub enum ValueHint { EmailAddress, } -impl Default for ValueHint { - fn default() -> Self { - ValueHint::Unknown - } -} - impl FromStr for ValueHint { type Err = String; fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> { diff --git a/vendor/clap_builder/src/builder/value_parser.rs b/vendor/clap_builder/src/builder/value_parser.rs index 24631ce7c..4b0955789 100644 --- a/vendor/clap_builder/src/builder/value_parser.rs +++ b/vendor/clap_builder/src/builder/value_parser.rs @@ -1162,7 +1162,7 @@ impl<E: crate::ValueEnum + Clone + Send + Sync + 'static> Default for EnumValueP pub struct PossibleValuesParser(Vec<super::PossibleValue>); impl PossibleValuesParser { - /// Verify the value is from an enumerated set pf [`PossibleValue`][crate::builder::PossibleValue]. + /// Verify the value is from an enumerated set of [`PossibleValue`][crate::builder::PossibleValue]. pub fn new(values: impl Into<PossibleValuesParser>) -> Self { values.into() } @@ -2382,17 +2382,17 @@ pub mod via_prelude { /// # use clap::ColorChoice; /// // Built-in types /// let parser = clap::value_parser!(String); -/// assert_eq!(format!("{:?}", parser), "ValueParser::string"); +/// assert_eq!(format!("{parser:?}"), "ValueParser::string"); /// let parser = clap::value_parser!(std::ffi::OsString); -/// assert_eq!(format!("{:?}", parser), "ValueParser::os_string"); +/// assert_eq!(format!("{parser:?}"), "ValueParser::os_string"); /// let parser = clap::value_parser!(std::path::PathBuf); -/// assert_eq!(format!("{:?}", parser), "ValueParser::path_buf"); +/// assert_eq!(format!("{parser:?}"), "ValueParser::path_buf"); /// clap::value_parser!(u16).range(3000..); /// clap::value_parser!(u64).range(3000..); /// /// // FromStr types /// let parser = clap::value_parser!(usize); -/// assert_eq!(format!("{:?}", parser), "_AnonymousValueParser(ValueParser::other(usize))"); +/// assert_eq!(format!("{parser:?}"), "_AnonymousValueParser(ValueParser::other(usize))"); /// /// // ValueEnum types /// clap::value_parser!(ColorChoice); diff --git a/vendor/clap_builder/src/error/format.rs b/vendor/clap_builder/src/error/format.rs index b5f0c1264..49e617d07 100644 --- a/vendor/clap_builder/src/error/format.rs +++ b/vendor/clap_builder/src/error/format.rs @@ -38,7 +38,7 @@ impl ErrorFormatter for KindFormatter { if let Some(msg) = error.kind().as_str() { styled.push_str(msg); } else if let Some(source) = error.inner.source.as_ref() { - let _ = write!(styled, "{}", source); + let _ = write!(styled, "{source}"); } else { styled.push_str("unknown cause"); } @@ -68,7 +68,7 @@ impl ErrorFormatter for RichFormatter { if let Some(msg) = error.kind().as_str() { styled.push_str(msg); } else if let Some(source) = error.inner.source.as_ref() { - let _ = write!(styled, "{}", source); + let _ = write!(styled, "{source}"); } else { styled.push_str("unknown cause"); } @@ -236,31 +236,9 @@ fn write_dynamic_context( ); } - let possible_values = error.get(ContextKind::ValidValue); - if let Some(ContextValue::Strings(possible_values)) = possible_values { - if !possible_values.is_empty() { - let _ = write!(styled, "\n{TAB}[possible values: "); - if let Some((last, elements)) = possible_values.split_last() { - for v in elements { - let _ = write!( - styled, - "{}{}{}, ", - valid.render(), - Escape(v), - valid.render_reset() - ); - } - let _ = write!( - styled, - "{}{}{}", - valid.render(), - Escape(last), - valid.render_reset() - ); - } - styled.push_str("]"); - } - } + let values = error.get(ContextKind::ValidValue); + write_values_list("possible values", styled, valid, values); + true } else { false @@ -306,32 +284,8 @@ fn write_dynamic_context( invalid.render(), invalid.render_reset() ); - - let possible_values = error.get(ContextKind::ValidSubcommand); - if let Some(ContextValue::Strings(possible_values)) = possible_values { - if !possible_values.is_empty() { - let _ = write!(styled, "\n{TAB}[subcommands: "); - if let Some((last, elements)) = possible_values.split_last() { - for v in elements { - let _ = write!( - styled, - "{}{}{}, ", - valid.render(), - Escape(v), - valid.render_reset() - ); - } - let _ = write!( - styled, - "{}{}{}", - valid.render(), - Escape(last), - valid.render_reset() - ); - } - styled.push_str("]"); - } - } + let values = error.get(ContextKind::ValidSubcommand); + write_values_list("subcommands", styled, valid, values); true } else { @@ -403,7 +357,7 @@ fn write_dynamic_context( literal.render_reset(), ); if let Some(source) = error.inner.source.as_deref() { - let _ = write!(styled, ": {}", source); + let _ = write!(styled, ": {source}"); } true } else { @@ -458,6 +412,32 @@ fn write_dynamic_context( } } +#[cfg(feature = "error-context")] +fn write_values_list( + list_name: &'static str, + styled: &mut StyledStr, + valid: &anstyle::Style, + possible_values: Option<&ContextValue>, +) { + use std::fmt::Write as _; + if let Some(ContextValue::Strings(possible_values)) = possible_values { + if !possible_values.is_empty() { + let _ = write!(styled, "\n{TAB}[{list_name}: "); + + let style = valid.render(); + let reset = valid.render_reset(); + for (idx, val) in possible_values.iter().enumerate() { + if idx > 0 { + styled.push_str(", "); + } + let _ = write!(styled, "{style}{}{reset}", Escape(val)); + } + + styled.push_str("]"); + } + } +} + pub(crate) fn format_error_message( message: &str, styles: &Styles, diff --git a/vendor/clap_builder/src/error/mod.rs b/vendor/clap_builder/src/error/mod.rs index cb3629669..210a1717f 100644 --- a/vendor/clap_builder/src/error/mod.rs +++ b/vendor/clap_builder/src/error/mod.rs @@ -214,21 +214,26 @@ impl<F: ErrorFormatter> Error<F> { } } + /// Returns the exit code that `.exit` will exit the process with. + /// + /// When the error's kind would print to `stderr` this returns `2`, + /// else it returns `0`. + pub fn exit_code(&self) -> i32 { + if self.use_stderr() { + USAGE_CODE + } else { + SUCCESS_CODE + } + } + /// Prints the error and exits. /// /// Depending on the error kind, this either prints to `stderr` and exits with a status of `2` /// or prints to `stdout` and exits with a status of `0`. pub fn exit(&self) -> ! { - if self.use_stderr() { - // Swallow broken pipe errors - let _ = self.print(); - - safe_exit(USAGE_CODE); - } - // Swallow broken pipe errors let _ = self.print(); - safe_exit(SUCCESS_CODE) + safe_exit(self.exit_code()) } /// Prints formatted and colored error to `stdout` or `stderr` according to its error kind @@ -275,7 +280,7 @@ impl<F: ErrorFormatter> Error<F> { /// }, /// Err(err) => { /// let err = err.render(); - /// println!("{}", err); + /// println!("{err}"); /// // do_something /// }, /// }; diff --git a/vendor/clap_builder/src/macros.rs b/vendor/clap_builder/src/macros.rs index 59135e212..945cdaaab 100644 --- a/vendor/clap_builder/src/macros.rs +++ b/vendor/clap_builder/src/macros.rs @@ -175,8 +175,7 @@ macro_rules! arg_impl { debug_assert_eq!( ident_or_char_literal.len(), 1, - "Single-letter identifier expected, got {}", - ident_or_char_literal + "Single-letter identifier expected, got {ident_or_char_literal}", ); ident_or_char_literal.chars().next().unwrap() }}; @@ -404,7 +403,7 @@ macro_rules! arg_impl { $arg.action($crate::ArgAction::Count) } action => { - panic!("Unexpected action {:?}", action) + panic!("Unexpected action {action:?}") } }; let arg = $crate::arg_impl! { @@ -532,99 +531,6 @@ macro_rules! arg { }}; } -macro_rules! impl_settings { - ($settings:ident, $flags:ident, - $( - $(#[$inner:ident $($args:tt)*])* - $setting:ident => $flag:path - ),+ - ) => { - impl $flags { - #[allow(dead_code)] - pub(crate) fn empty() -> Self { - $flags(Flags::empty()) - } - - #[allow(dead_code)] - pub(crate) fn insert(&mut self, rhs: Self) { - self.0.insert(rhs.0); - } - - #[allow(dead_code)] - pub(crate) fn remove(&mut self, rhs: Self) { - self.0.remove(rhs.0); - } - - #[allow(dead_code)] - pub(crate) fn set(&mut self, s: $settings) { - match s { - $( - $(#[$inner $($args)*])* - $settings::$setting => self.0.insert($flag), - )* - } - } - - #[allow(dead_code)] - pub(crate) fn unset(&mut self, s: $settings) { - match s { - $( - $(#[$inner $($args)*])* - $settings::$setting => self.0.remove($flag), - )* - } - } - - #[allow(dead_code)] - pub(crate) fn is_set(&self, s: $settings) -> bool { - match s { - $( - $(#[$inner $($args)*])* - $settings::$setting => self.0.contains($flag), - )* - } - } - } - - impl BitOr for $flags { - type Output = Self; - - fn bitor(mut self, rhs: Self) -> Self::Output { - self.0.insert(rhs.0); - self - } - } - - impl From<$settings> for $flags { - fn from(setting: $settings) -> Self { - let mut flags = $flags::empty(); - flags.set(setting); - flags - } - } - - impl BitOr<$settings> for $flags { - type Output = Self; - - fn bitor(mut self, rhs: $settings) -> Self::Output { - self.set(rhs); - self - } - } - - impl BitOr for $settings { - type Output = $flags; - - fn bitor(self, rhs: Self) -> Self::Output { - let mut flags = $flags::empty(); - flags.set(self); - flags.set(rhs); - flags - } - } - } -} - #[cfg(feature = "debug")] macro_rules! debug { ($($arg:tt)*) => ({ diff --git a/vendor/clap_builder/src/output/help_template.rs b/vendor/clap_builder/src/output/help_template.rs index 86a61169c..68ff58077 100644 --- a/vendor/clap_builder/src/output/help_template.rs +++ b/vendor/clap_builder/src/output/help_template.rs @@ -450,9 +450,10 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { } } } + /// Sorts arguments by length and display order and write their help to the wrapped stream. fn write_args(&mut self, args: &[&Arg], _category: &str, sort_key: ArgSortKey) { - debug!("HelpTemplate::write_args {}", _category); + debug!("HelpTemplate::write_args {_category}"); // The shortest an arg can legally be is 2 (i.e. '-x') let mut longest = 2; let mut ord_v = Vec::new(); @@ -577,8 +578,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { }; let spcs = longest + padding - self_len; debug!( - "HelpTemplate::align_to_about: positional=false arg_len={}, spaces={}", - self_len, spcs + "HelpTemplate::align_to_about: positional=false arg_len={self_len}, spaces={spcs}" ); spcs @@ -587,8 +587,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { let padding = TAB_WIDTH; let spcs = longest + padding - self_len; debug!( - "HelpTemplate::align_to_about: positional=true arg_len={}, spaces={}", - self_len, spcs + "HelpTemplate::align_to_about: positional=true arg_len={self_len}, spaces={spcs}", ); spcs @@ -612,7 +611,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { // Is help on next line, if so then indent if next_line_help { - debug!("HelpTemplate::help: Next Line...{:?}", next_line_help); + debug!("HelpTemplate::help: Next Line...{next_line_help:?}"); self.writer.push_str("\n"); self.writer.push_str(TAB); self.writer.push_str(NEXT_LINE_INDENT); @@ -654,38 +653,21 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { self.writer.push_styled(&help); if let Some(arg) = arg { const DASH_SPACE: usize = "- ".len(); - const COLON_SPACE: usize = ": ".len(); let possible_vals = arg.get_possible_values(); - if self.use_long + if !possible_vals.is_empty() && !arg.is_hide_possible_values_set() - && possible_vals.iter().any(PossibleValue::should_show_help) + && self.use_long_pv(arg) { - debug!( - "HelpTemplate::help: Found possible vals...{:?}", - possible_vals - ); + debug!("HelpTemplate::help: Found possible vals...{possible_vals:?}"); let longest = possible_vals .iter() - .filter_map(|f| f.get_visible_quoted_name().map(|name| display_width(&name))) + .filter(|f| !f.is_hide_set()) + .map(|f| display_width(f.get_name())) .max() .expect("Only called with possible value"); - let help_longest = possible_vals - .iter() - .filter_map(|f| f.get_visible_help().map(|h| h.display_width())) - .max() - .expect("Only called with possible value with help"); - // should new line - let taken = longest + spaces + DASH_SPACE; - - let possible_value_new_line = - self.term_w >= taken && self.term_w < taken + COLON_SPACE + help_longest; let spaces = spaces + TAB_WIDTH - DASH_SPACE; - let trailing_indent = if possible_value_new_line { - spaces + DASH_SPACE - } else { - spaces + longest + DASH_SPACE + COLON_SPACE - }; + let trailing_indent = spaces + DASH_SPACE; let trailing_indent = self.get_spaces(trailing_indent); if !help_is_empty { @@ -704,14 +686,9 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { if let Some(help) = pv.get_help() { debug!("HelpTemplate::help: Possible Value help"); - if possible_value_new_line { - let padding = trailing_indent.len(); - let _ = write!(self.writer, ":\n{:padding$}", ""); - } else { - // To align help messages - let padding = longest - display_width(pv.get_name()); - let _ = write!(self.writer, ": {:padding$}", ""); - } + // To align help messages + let padding = longest - display_width(pv.get_name()); + let _ = write!(self.writer, ": {:padding$}", ""); let avail_chars = if self.term_w > trailing_indent.len() { self.term_w - trailing_indent.len() @@ -760,7 +737,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { } fn spec_vals(&self, a: &Arg) -> String { - debug!("HelpTemplate::spec_vals: a={}", a); + debug!("HelpTemplate::spec_vals: a={a}"); let mut spec_vals = Vec::new(); #[cfg(feature = "env")] if let Some(ref env) = a.env { @@ -835,14 +812,8 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { } let possible_vals = a.get_possible_values(); - if !(a.is_hide_possible_values_set() - || possible_vals.is_empty() - || self.use_long && possible_vals.iter().any(PossibleValue::should_show_help)) - { - debug!( - "HelpTemplate::spec_vals: Found possible vals...{:?}", - possible_vals - ); + if !possible_vals.is_empty() && !a.is_hide_possible_values_set() && !self.use_long_pv(a) { + debug!("HelpTemplate::spec_vals: Found possible vals...{possible_vals:?}"); let pvs = possible_vals .iter() @@ -864,6 +835,14 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { use std::fmt::Write as _; let _ = write!(self.writer, "{:amount$}", ""); } + + fn use_long_pv(&self, arg: &Arg) -> bool { + self.use_long + && arg + .get_possible_values() + .iter() + .any(PossibleValue::should_show_help) + } } /// Subcommand handling @@ -910,15 +889,12 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { } ord_v.sort_by(|a, b| (a.0, &a.1).cmp(&(b.0, &b.1))); - debug!("HelpTemplate::write_subcommands longest = {}", longest); + debug!("HelpTemplate::write_subcommands longest = {longest}"); let next_line_help = self.will_subcommands_wrap(cmd.get_subcommands(), longest); - let mut first = true; - for (_, sc_str, sc) in ord_v { - if first { - first = false; - } else { + for (i, (_, sc_str, sc)) in ord_v.into_iter().enumerate() { + if 0 < i { self.writer.push_str("\n"); } self.write_subcommand(sc_str, sc, next_line_help, longest); @@ -987,7 +963,8 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { } fn subcommand_next_line_help(&self, cmd: &Command, spec_vals: &str, longest: usize) -> bool { - if self.next_line_help | self.use_long { + // Ignore `self.use_long` since subcommands are only shown as short help + if self.next_line_help { // setting_next_line true } else { diff --git a/vendor/clap_builder/src/output/textwrap/core.rs b/vendor/clap_builder/src/output/textwrap/core.rs index 25c9eb6b0..2f6004c71 100644 --- a/vendor/clap_builder/src/output/textwrap/core.rs +++ b/vendor/clap_builder/src/output/textwrap/core.rs @@ -102,7 +102,7 @@ mod tests { let desc = format!("{:?} U+{:04X}", ch, ch as u32); #[cfg(feature = "unicode")] - assert_eq!(ch.width().unwrap(), 1, "char: {}", desc); + assert_eq!(ch.width().unwrap(), 1, "char: {desc}"); #[cfg(not(feature = "unicode"))] assert_eq!(ch_width(ch), 1, "char: {desc}"); @@ -120,7 +120,7 @@ mod tests { let desc = format!("{:?} U+{:04X}", ch, ch as u32); #[cfg(feature = "unicode")] - assert!(ch.width().unwrap() <= 2, "char: {}", desc); + assert!(ch.width().unwrap() <= 2, "char: {desc}"); #[cfg(not(feature = "unicode"))] assert_eq!(ch_width(ch), 1, "char: {desc}"); diff --git a/vendor/clap_builder/src/output/textwrap/mod.rs b/vendor/clap_builder/src/output/textwrap/mod.rs index d14d3fe7f..fe8139f1a 100644 --- a/vendor/clap_builder/src/output/textwrap/mod.rs +++ b/vendor/clap_builder/src/output/textwrap/mod.rs @@ -83,7 +83,7 @@ mod test { #[test] fn leading_whitespace() { - assert_eq!(wrap(" foo bar", 6), vec![" foo", "bar"]); + assert_eq!(wrap(" foo bar", 6), vec![" foo", " bar"]); } #[test] @@ -92,7 +92,7 @@ mod test { // will be empty. This is because the string is split into // words like [" ", "foobar ", "baz"], which puts "foobar " on // the second line. We never output trailing whitespace - assert_eq!(wrap(" foobar baz", 6), vec!["", "foobar", "baz"]); + assert_eq!(wrap(" foobar baz", 6), vec!["", " foobar", " baz"]); } #[test] diff --git a/vendor/clap_builder/src/output/textwrap/word_separators.rs b/vendor/clap_builder/src/output/textwrap/word_separators.rs index ac09231d5..cb8250b60 100644 --- a/vendor/clap_builder/src/output/textwrap/word_separators.rs +++ b/vendor/clap_builder/src/output/textwrap/word_separators.rs @@ -5,14 +5,15 @@ pub(crate) fn find_words_ascii_space(line: &str) -> impl Iterator<Item = &'_ str std::iter::from_fn(move || { for (idx, ch) in char_indices.by_ref() { - if in_whitespace && ch != ' ' { + let next_whitespace = ch == ' '; + if in_whitespace && !next_whitespace { let word = &line[start..idx]; start = idx; - in_whitespace = ch == ' '; + in_whitespace = next_whitespace; return Some(word); } - in_whitespace = ch == ' '; + in_whitespace = next_whitespace; } if start < line.len() { diff --git a/vendor/clap_builder/src/output/textwrap/wrap_algorithms.rs b/vendor/clap_builder/src/output/textwrap/wrap_algorithms.rs index 019cc04ff..34b4fd2b7 100644 --- a/vendor/clap_builder/src/output/textwrap/wrap_algorithms.rs +++ b/vendor/clap_builder/src/output/textwrap/wrap_algorithms.rs @@ -1,24 +1,37 @@ use super::core::display_width; #[derive(Debug)] -pub(crate) struct LineWrapper { - line_width: usize, +pub(crate) struct LineWrapper<'w> { hard_width: usize, + line_width: usize, + carryover: Option<&'w str>, } -impl LineWrapper { +impl<'w> LineWrapper<'w> { pub(crate) fn new(hard_width: usize) -> Self { Self { - line_width: 0, hard_width, + line_width: 0, + carryover: None, } } pub(crate) fn reset(&mut self) { self.line_width = 0; + self.carryover = None; } - pub(crate) fn wrap<'w>(&mut self, mut words: Vec<&'w str>) -> Vec<&'w str> { + pub(crate) fn wrap(&mut self, mut words: Vec<&'w str>) -> Vec<&'w str> { + if self.carryover.is_none() { + if let Some(word) = words.first() { + if word.trim().is_empty() { + self.carryover = Some(*word); + } else { + self.carryover = Some(""); + } + } + } + let mut i = 0; while i < words.len() { let word = &words[i]; @@ -31,9 +44,15 @@ impl LineWrapper { let trimmed = words[last].trim_end(); words[last] = trimmed; } + + self.line_width = 0; words.insert(i, "\n"); i += 1; - self.reset(); + if let Some(carryover) = self.carryover { + words.insert(i, carryover); + self.line_width += carryover.len(); + i += 1; + } } self.line_width += word_width + trimmed_delta; diff --git a/vendor/clap_builder/src/output/usage.rs b/vendor/clap_builder/src/output/usage.rs index dd99c63c7..3f387a0d7 100644 --- a/vendor/clap_builder/src/output/usage.rs +++ b/vendor/clap_builder/src/output/usage.rs @@ -79,7 +79,7 @@ impl<'cmd> Usage<'cmd> { impl<'cmd> Usage<'cmd> { // Creates a usage string for display in help messages (i.e. not for errors) fn create_help_usage(&self, incl_reqs: bool) -> StyledStr { - debug!("Usage::create_help_usage; incl_reqs={:?}", incl_reqs); + debug!("Usage::create_help_usage; incl_reqs={incl_reqs:?}"); use std::fmt::Write as _; let literal = &self.styles.get_literal(); let placeholder = &self.styles.get_placeholder(); @@ -157,7 +157,7 @@ impl<'cmd> Usage<'cmd> { } } styled.trim(); - debug!("Usage::create_help_usage: usage={}", styled); + debug!("Usage::create_help_usage: usage={styled}"); styled } @@ -220,7 +220,7 @@ impl<'cmd> Usage<'cmd> { continue; } for grp_s in self.cmd.groups_for_arg(f.get_id()) { - debug!("Usage::needs_options_tag:iter:iter: grp_s={:?}", grp_s); + debug!("Usage::needs_options_tag:iter:iter: grp_s={grp_s:?}"); if self.cmd.get_groups().any(|g| g.id == grp_s && g.required) { debug!("Usage::needs_options_tag:iter:iter: Group is required"); continue 'outer; @@ -244,7 +244,7 @@ impl<'cmd> Usage<'cmd> { } pub(crate) fn get_args(&self, incls: &[Id], force_optional: bool) -> Vec<StyledStr> { - debug!("Usage::get_args: incls={:?}", incls,); + debug!("Usage::get_args: incls={incls:?}",); use std::fmt::Write as _; let literal = &self.styles.get_literal(); @@ -275,7 +275,7 @@ impl<'cmd> Usage<'cmd> { // by unroll_requirements_for_arg. unrolled_reqs.push(a.clone()); } - debug!("Usage::get_args: unrolled_reqs={:?}", unrolled_reqs); + debug!("Usage::get_args: unrolled_reqs={unrolled_reqs:?}"); let mut required_groups_members = FlatSet::new(); let mut required_groups = FlatSet::new(); @@ -360,7 +360,7 @@ impl<'cmd> Usage<'cmd> { ret_val.push(pos); } - debug!("Usage::get_args: ret_val={:?}", ret_val); + debug!("Usage::get_args: ret_val={ret_val:?}"); ret_val } @@ -410,10 +410,7 @@ impl<'cmd> Usage<'cmd> { // by unroll_requirements_for_arg. unrolled_reqs.push(a.clone()); } - debug!( - "Usage::get_required_usage_from: unrolled_reqs={:?}", - unrolled_reqs - ); + debug!("Usage::get_required_usage_from: unrolled_reqs={unrolled_reqs:?}"); let mut required_groups_members = FlatSet::new(); let mut required_groups = FlatSet::new(); @@ -427,10 +424,7 @@ impl<'cmd> Usage<'cmd> { .any(|arg| m.check_explicit(arg, &ArgPredicate::IsPresent)) }) .unwrap_or(false); - debug!( - "Usage::get_required_usage_from:iter:{:?} group is_present={}", - req, is_present - ); + debug!("Usage::get_required_usage_from:iter:{req:?} group is_present={is_present}"); if is_present { continue; } @@ -439,7 +433,7 @@ impl<'cmd> Usage<'cmd> { required_groups.insert(elem); required_groups_members.extend(group_members); } else { - debug_assert!(self.cmd.find(req).is_some()); + debug_assert!(self.cmd.find(req).is_some(), "`{req}` must exist"); } } @@ -454,10 +448,7 @@ impl<'cmd> Usage<'cmd> { let is_present = matcher .map(|m| m.check_explicit(req, &ArgPredicate::IsPresent)) .unwrap_or(false); - debug!( - "Usage::get_required_usage_from:iter:{:?} arg is_present={}", - req, is_present - ); + debug!("Usage::get_required_usage_from:iter:{req:?} arg is_present={is_present}"); if is_present { continue; } @@ -486,7 +477,7 @@ impl<'cmd> Usage<'cmd> { ret_val.push(pos); } - debug!("Usage::get_required_usage_from: ret_val={:?}", ret_val); + debug!("Usage::get_required_usage_from: ret_val={ret_val:?}"); ret_val } } diff --git a/vendor/clap_builder/src/parser/arg_matcher.rs b/vendor/clap_builder/src/parser/arg_matcher.rs index 124d46f5f..b8d827a5b 100644 --- a/vendor/clap_builder/src/parser/arg_matcher.rs +++ b/vendor/clap_builder/src/parser/arg_matcher.rs @@ -45,10 +45,7 @@ impl ArgMatcher { } pub(crate) fn propagate_globals(&mut self, global_arg_vec: &[Id]) { - debug!( - "ArgMatcher::get_global_values: global_arg_vec={:?}", - global_arg_vec - ); + debug!("ArgMatcher::get_global_values: global_arg_vec={global_arg_vec:?}"); let mut vals_map = FlatMap::new(); self.fill_in_global_values(global_arg_vec, &mut vals_map); } @@ -137,10 +134,7 @@ impl ArgMatcher { pub(crate) fn start_custom_arg(&mut self, arg: &Arg, source: ValueSource) { let id = arg.get_id().clone(); - debug!( - "ArgMatcher::start_custom_arg: id={:?}, source={:?}", - id, source - ); + debug!("ArgMatcher::start_custom_arg: id={id:?}, source={source:?}"); let ma = self.entry(id).or_insert(MatchedArg::new_arg(arg)); debug_assert_eq!(ma.type_id(), Some(arg.get_value_parser().type_id())); ma.set_source(source); @@ -148,10 +142,7 @@ impl ArgMatcher { } pub(crate) fn start_custom_group(&mut self, id: Id, source: ValueSource) { - debug!( - "ArgMatcher::start_custom_arg: id={:?}, source={:?}", - id, source - ); + debug!("ArgMatcher::start_custom_arg: id={id:?}, source={source:?}"); let ma = self.entry(id).or_insert(MatchedArg::new_group()); debug_assert_eq!(ma.type_id(), None); ma.set_source(source); @@ -160,7 +151,7 @@ impl ArgMatcher { pub(crate) fn start_occurrence_of_external(&mut self, cmd: &crate::Command) { let id = Id::from_static_ref(Id::EXTERNAL); - debug!("ArgMatcher::start_occurrence_of_external: id={:?}", id,); + debug!("ArgMatcher::start_occurrence_of_external: id={id:?}"); let ma = self.entry(id).or_insert(MatchedArg::new_external(cmd)); debug_assert_eq!( ma.type_id(), @@ -196,10 +187,7 @@ impl ArgMatcher { num_pending ); let expected = o.get_num_args().expect(INTERNAL_ERROR_MSG); - debug!( - "ArgMatcher::needs_more_vals: expected={}, actual={}", - expected, num_pending - ); + debug!("ArgMatcher::needs_more_vals: expected={expected}, actual={num_pending}"); expected.accepts_more(num_pending) } diff --git a/vendor/clap_builder/src/parser/matches/arg_matches.rs b/vendor/clap_builder/src/parser/matches/arg_matches.rs index da8a34783..525904291 100644 --- a/vendor/clap_builder/src/parser/matches/arg_matches.rs +++ b/vendor/clap_builder/src/parser/matches/arg_matches.rs @@ -43,7 +43,7 @@ use crate::INTERNAL_ERROR_MSG; /// // to get information about the "cfg" argument we created, such as the value supplied we use /// // various ArgMatches methods, such as [ArgMatches::get_one] /// if let Some(c) = matches.get_one::<String>("cfg") { -/// println!("Value for -c: {}", c); +/// println!("Value for -c: {c}"); /// } /// /// // The ArgMatches::get_one method returns an Option because the user may not have supplied @@ -143,10 +143,7 @@ impl ArgMatches { #[cfg_attr(debug_assertions, track_caller)] pub fn get_count(&self, id: &str) -> u8 { *self.get_one::<u8>(id).unwrap_or_else(|| { - panic!( - "arg `{}`'s `ArgAction` should be `Count` which should provide a default", - id - ) + panic!("arg `{id}`'s `ArgAction` should be `Count` which should provide a default") }) } @@ -182,8 +179,7 @@ impl ArgMatches { .get_one::<bool>(id) .unwrap_or_else(|| { panic!( - "arg `{}`'s `ArgAction` should be one of `SetTrue`, `SetFalse` which should provide a default", - id + "arg `{id}`'s `ArgAction` should be one of `SetTrue`, `SetFalse` which should provide a default" ) }) } @@ -928,7 +924,7 @@ impl ArgMatches { /// ("clone", sub_m) => {}, // clone was used /// ("push", sub_m) => {}, // push was used /// ("commit", sub_m) => {}, // commit was used - /// (name, _) => unimplemented!("{}", name), + /// (name, _) => unimplemented!("{name}"), /// } /// ``` /// @@ -1405,7 +1401,12 @@ impl<T> Iterator for Values<T> { type Item = T; fn next(&mut self) -> Option<Self::Item> { - self.iter.next() + if let Some(next) = self.iter.next() { + self.len -= 1; + Some(next) + } else { + None + } } fn size_hint(&self) -> (usize, Option<usize>) { (self.len, Some(self.len)) @@ -1414,7 +1415,12 @@ impl<T> Iterator for Values<T> { impl<T> DoubleEndedIterator for Values<T> { fn next_back(&mut self) -> Option<Self::Item> { - self.iter.next_back() + if let Some(next) = self.iter.next_back() { + self.len -= 1; + Some(next) + } else { + None + } } } @@ -1463,7 +1469,12 @@ impl<'a, T: 'a> Iterator for ValuesRef<'a, T> { type Item = &'a T; fn next(&mut self) -> Option<Self::Item> { - self.iter.next() + if let Some(next) = self.iter.next() { + self.len -= 1; + Some(next) + } else { + None + } } fn size_hint(&self) -> (usize, Option<usize>) { (self.len, Some(self.len)) @@ -1472,7 +1483,12 @@ impl<'a, T: 'a> Iterator for ValuesRef<'a, T> { impl<'a, T: 'a> DoubleEndedIterator for ValuesRef<'a, T> { fn next_back(&mut self) -> Option<Self::Item> { - self.iter.next_back() + if let Some(next) = self.iter.next_back() { + self.len -= 1; + Some(next) + } else { + None + } } } @@ -1526,7 +1542,12 @@ impl<'a> Iterator for RawValues<'a> { type Item = &'a OsStr; fn next(&mut self) -> Option<&'a OsStr> { - self.iter.next() + if let Some(next) = self.iter.next() { + self.len -= 1; + Some(next) + } else { + None + } } fn size_hint(&self) -> (usize, Option<usize>) { (self.len, Some(self.len)) @@ -1535,7 +1556,12 @@ impl<'a> Iterator for RawValues<'a> { impl<'a> DoubleEndedIterator for RawValues<'a> { fn next_back(&mut self) -> Option<&'a OsStr> { - self.iter.next_back() + if let Some(next) = self.iter.next_back() { + self.len -= 1; + Some(next) + } else { + None + } } } @@ -1570,7 +1596,12 @@ impl<'a> Iterator for GroupedValues<'a> { type Item = Vec<&'a str>; fn next(&mut self) -> Option<Self::Item> { - self.iter.next() + if let Some(next) = self.iter.next() { + self.len -= 1; + Some(next) + } else { + None + } } fn size_hint(&self) -> (usize, Option<usize>) { (self.len, Some(self.len)) @@ -1580,7 +1611,12 @@ impl<'a> Iterator for GroupedValues<'a> { #[allow(deprecated)] impl<'a> DoubleEndedIterator for GroupedValues<'a> { fn next_back(&mut self) -> Option<Self::Item> { - self.iter.next_back() + if let Some(next) = self.iter.next_back() { + self.len -= 1; + Some(next) + } else { + None + } } } @@ -1830,7 +1866,12 @@ impl<'a> Iterator for Indices<'a> { type Item = usize; fn next(&mut self) -> Option<usize> { - self.iter.next() + if let Some(next) = self.iter.next() { + self.len -= 1; + Some(next) + } else { + None + } } fn size_hint(&self) -> (usize, Option<usize>) { (self.len, Some(self.len)) @@ -1839,7 +1880,12 @@ impl<'a> Iterator for Indices<'a> { impl<'a> DoubleEndedIterator for Indices<'a> { fn next_back(&mut self) -> Option<usize> { - self.iter.next_back() + if let Some(next) = self.iter.next_back() { + self.len -= 1; + Some(next) + } else { + None + } } } @@ -1948,4 +1994,37 @@ mod tests { .len(); assert_eq!(l, 1); } + + #[test] + fn rev_iter() { + let mut matches = crate::Command::new("myprog") + .arg(crate::Arg::new("a").short('a').action(ArgAction::Append)) + .arg(crate::Arg::new("b").short('b').action(ArgAction::Append)) + .try_get_matches_from(vec!["myprog", "-a1", "-b1", "-b3"]) + .unwrap(); + + let a_index = matches + .indices_of("a") + .expect("missing aopt indices") + .collect::<Vec<_>>(); + dbg!(&a_index); + let a_value = matches + .remove_many::<String>("a") + .expect("missing aopt values"); + dbg!(&a_value); + let a = a_index.into_iter().zip(a_value).rev().collect::<Vec<_>>(); + dbg!(a); + + let b_index = matches + .indices_of("b") + .expect("missing aopt indices") + .collect::<Vec<_>>(); + dbg!(&b_index); + let b_value = matches + .remove_many::<String>("b") + .expect("missing aopt values"); + dbg!(&b_value); + let b = b_index.into_iter().zip(b_value).rev().collect::<Vec<_>>(); + dbg!(b); + } } diff --git a/vendor/clap_builder/src/parser/parser.rs b/vendor/clap_builder/src/parser/parser.rs index 723e1cd69..d2e198b28 100644 --- a/vendor/clap_builder/src/parser/parser.rs +++ b/vendor/clap_builder/src/parser/parser.rs @@ -88,7 +88,7 @@ impl<'cmd> Parser<'cmd> { { // Does the arg match a subcommand name, or any of its aliases (if defined) let sc_name = self.possible_subcommand(arg_os.to_value(), valid_arg_found); - debug!("Parser::get_matches_with: sc={:?}", sc_name); + debug!("Parser::get_matches_with: sc={sc_name:?}"); if let Some(sc_name) = sc_name { if sc_name == "help" && !self.cmd.is_disable_help_subcommand_set() { ok!(self.parse_help_subcommand(raw_args.remaining(&mut args_cursor))); @@ -120,10 +120,7 @@ impl<'cmd> Parser<'cmd> { pos_counter, &mut valid_arg_found, )); - debug!( - "Parser::get_matches_with: After parse_long_arg {:?}", - parse_result - ); + debug!("Parser::get_matches_with: After parse_long_arg {parse_result:?}"); match parse_result { ParseResult::NoArg => { unreachable!("`to_long` always has the flag specified") @@ -193,10 +190,7 @@ impl<'cmd> Parser<'cmd> { &mut valid_arg_found, )); // If it's None, we then check if one of those two AppSettings was set - debug!( - "Parser::get_matches_with: After parse_short_arg {:?}", - parse_result - ); + debug!("Parser::get_matches_with: After parse_short_arg {parse_result:?}"); match parse_result { ParseResult::NoArg => { // Is a single dash `-`, try positional. @@ -312,14 +306,8 @@ impl<'cmd> Parser<'cmd> { && is_second_to_last && !trailing_values; - debug!( - "Parser::get_matches_with: Positional counter...{}", - pos_counter - ); - debug!( - "Parser::get_matches_with: Low index multiples...{:?}", - low_index_mults - ); + debug!("Parser::get_matches_with: Positional counter...{pos_counter}"); + debug!("Parser::get_matches_with: Low index multiples...{low_index_mults:?}"); if low_index_mults || missing_pos { let skip_current = if let Some(n) = raw_args.peek(&args_cursor) { @@ -384,27 +372,27 @@ impl<'cmd> Parser<'cmd> { if matcher.pending_arg_id() != Some(arg.get_id()) || !arg.is_multiple_values_set() { ok!(self.resolve_pending(matcher)); } - if let Some(_parse_result) = self.check_terminator(arg, arg_os.to_value_os()) { - debug!( - "Parser::get_matches_with: ignoring terminator result {:?}", - _parse_result - ); - } else { - let arg_values = matcher.pending_values_mut( - arg.get_id(), - Some(Identifier::Index), - trailing_values, - ); - arg_values.push(arg_os.to_value_os().to_owned()); - } + parse_state = + if let Some(parse_result) = self.check_terminator(arg, arg_os.to_value_os()) { + debug_assert_eq!(parse_result, ParseResult::ValuesDone); + pos_counter += 1; + ParseState::ValuesDone + } else { + let arg_values = matcher.pending_values_mut( + arg.get_id(), + Some(Identifier::Index), + trailing_values, + ); + arg_values.push(arg_os.to_value_os().to_owned()); - // Only increment the positional counter if it doesn't allow multiples - if !arg.is_multiple() { - pos_counter += 1; - parse_state = ParseState::ValuesDone; - } else { - parse_state = ParseState::Pos(arg.get_id().clone()); - } + // Only increment the positional counter if it doesn't allow multiples + if !arg.is_multiple() { + pos_counter += 1; + ParseState::ValuesDone + } else { + ParseState::Pos(arg.get_id().clone()) + } + }; valid_arg_found = true; } else if let Some(external_parser) = self.cmd.get_external_subcommand_value_parser().cloned() @@ -535,7 +523,7 @@ impl<'cmd> Parser<'cmd> { arg: Result<&str, &OsStr>, valid_arg_found: bool, ) -> Option<&str> { - debug!("Parser::possible_subcommand: arg={:?}", arg); + debug!("Parser::possible_subcommand: arg={arg:?}"); let arg = some!(arg.ok()); if !(self.cmd.is_args_conflicts_with_subcommands_set() && valid_arg_found) { @@ -564,7 +552,7 @@ impl<'cmd> Parser<'cmd> { // Checks if the arg matches a long flag subcommand name, or any of its aliases (if defined) fn possible_long_flag_subcommand(&self, arg: &str) -> Option<&str> { - debug!("Parser::possible_long_flag_subcommand: arg={:?}", arg); + debug!("Parser::possible_long_flag_subcommand: arg={arg:?}"); if self.cmd.is_infer_subcommands_set() { let options = self .cmd @@ -687,10 +675,7 @@ impl<'cmd> Parser<'cmd> { } if let Err(error) = p.get_matches_with(&mut sc_matcher, raw_args, args_cursor) { if partial_parsing_enabled { - debug!( - "Parser::parse_subcommand: ignored error in subcommand {}: {:?}", - sc_name, error - ); + debug!("Parser::parse_subcommand: ignored error in subcommand {sc_name}: {error:?}"); } else { return Err(error); } @@ -741,10 +726,10 @@ impl<'cmd> Parser<'cmd> { } let arg = if let Some(arg) = self.cmd.get_keymap().get(long_arg) { - debug!("Parser::parse_long_arg: Found valid arg or flag '{}'", arg); + debug!("Parser::parse_long_arg: Found valid arg or flag '{arg}'"); Some((long_arg, arg)) } else if self.cmd.is_infer_long_args_set() { - self.cmd.get_arguments().find_map(|a| { + let mut iter = self.cmd.get_arguments().filter_map(|a| { if let Some(long) = a.get_long() { if long.starts_with(long_arg) { return Some((long, a)); @@ -753,7 +738,9 @@ impl<'cmd> Parser<'cmd> { a.aliases .iter() .find_map(|(alias, _)| alias.starts_with(long_arg).then(|| (alias.as_str(), a))) - }) + }); + + iter.next().filter(|_| iter.next().is_none()) } else { None }; @@ -770,10 +757,7 @@ impl<'cmd> Parser<'cmd> { self.parse_opt_value(ident, long_value, arg, matcher, has_eq) } else if let Some(rest) = long_value { let required = self.cmd.required_graph(); - debug!( - "Parser::parse_long_arg({:?}): Got invalid literal `{:?}`", - long_arg, rest - ); + debug!("Parser::parse_long_arg({long_arg:?}): Got invalid literal `{rest:?}`"); let mut used: Vec<Id> = matcher .arg_ids() .filter(|arg_id| { @@ -795,7 +779,7 @@ impl<'cmd> Parser<'cmd> { arg: arg.to_string(), }) } else { - debug!("Parser::parse_long_arg({:?}): Presence validated", long_arg); + debug!("Parser::parse_long_arg({long_arg:?}): Presence validated"); let trailing_idx = None; self.react( Some(ident), @@ -815,10 +799,7 @@ impl<'cmd> Parser<'cmd> { .map(|arg| arg.is_allow_hyphen_values_set() && !arg.is_last_set()) .unwrap_or_default() { - debug!( - "Parser::parse_long_args: positional at {} allows hyphens", - pos_counter - ); + debug!("Parser::parse_long_args: positional at {pos_counter} allows hyphens"); Ok(ParseResult::MaybeHyphenValue) } else { Ok(ParseResult::NoMatchingArg { @@ -836,7 +817,7 @@ impl<'cmd> Parser<'cmd> { pos_counter: usize, valid_arg_found: &mut bool, ) -> ClapResult<ParseResult> { - debug!("Parser::parse_short_arg: short_arg={:?}", short_arg); + debug!("Parser::parse_short_arg: short_arg={short_arg:?}"); #[allow(clippy::blocks_in_if_conditions)] if matches!(parse_state, ParseState::Opt(opt) | ParseState::Pos(opt) @@ -864,10 +845,7 @@ impl<'cmd> Parser<'cmd> { .clone() .any(|c| !c.map(|c| self.cmd.contains_short(c)).unwrap_or_default()) { - debug!( - "Parser::parse_short_args: positional at {} allows hyphens", - pos_counter - ); + debug!("Parser::parse_short_args: positional at {pos_counter} allows hyphens"); return Ok(ParseResult::MaybeHyphenValue); } @@ -890,7 +868,7 @@ impl<'cmd> Parser<'cmd> { }); } }; - debug!("Parser::parse_short_arg:iter:{}", c); + debug!("Parser::parse_short_arg:iter:{c}"); // Check for matching short options, and return the name if there is no trailing // concatenated value: -oval @@ -898,10 +876,7 @@ impl<'cmd> Parser<'cmd> { // Value: val if let Some(arg) = self.cmd.get_keymap().get(&c) { let ident = Identifier::Short; - debug!( - "Parser::parse_short_arg:iter:{}: Found valid opt or flag", - c - ); + debug!("Parser::parse_short_arg:iter:{c}: Found valid opt or flag"); *valid_arg_found = true; if !arg.is_takes_value_set() { let arg_values = Vec::new(); @@ -921,10 +896,7 @@ impl<'cmd> Parser<'cmd> { // // Cloning the iterator, so we rollback if it isn't there. let val = short_arg.clone().next_value_os().unwrap_or_default(); - debug!( - "Parser::parse_short_arg:iter:{}: val={:?}, short_arg={:?}", - c, val, short_arg - ); + debug!("Parser::parse_short_arg:iter:{c}: val={val:?}, short_arg={short_arg:?}"); let val = Some(val).filter(|v| !v.is_empty()); // Default to "we're expecting a value later". @@ -946,7 +918,7 @@ impl<'cmd> Parser<'cmd> { } return if let Some(sc_name) = self.cmd.find_short_subcmd(c) { - debug!("Parser::parse_short_arg:iter:{}: subcommand={}", c, sc_name); + debug!("Parser::parse_short_arg:iter:{c}: subcommand={sc_name}"); // Make sure indices get updated before reading `self.cur_idx` ok!(self.resolve_pending(matcher)); self.cur_idx.set(self.cur_idx.get() + 1); @@ -1053,7 +1025,7 @@ impl<'cmd> Parser<'cmd> { raw_vals: Vec<OsString>, matcher: &mut ArgMatcher, ) -> ClapResult<()> { - debug!("Parser::push_arg_values: {:?}", raw_vals); + debug!("Parser::push_arg_values: {raw_vals:?}"); for raw_val in raw_vals { // update the current index because each value is a distinct index to clap @@ -1262,7 +1234,7 @@ impl<'cmd> Parser<'cmd> { Some(Identifier::Index) => true, None => true, }; - debug!("Help: use_long={}", use_long); + debug!("Help: use_long={use_long}"); Err(self.help_err(use_long)) } ArgAction::Version => { @@ -1272,7 +1244,7 @@ impl<'cmd> Parser<'cmd> { Some(Identifier::Index) => true, None => true, }; - debug!("Version: use_long={}", use_long); + debug!("Version: use_long={use_long}"); Err(self.version_err(use_long)) } } @@ -1337,7 +1309,7 @@ impl<'cmd> Parser<'cmd> { fn remove_overrides(&self, arg: &Arg, matcher: &mut ArgMatcher) { debug!("Parser::remove_overrides: id={:?}", arg.id); for override_id in &arg.overrides { - debug!("Parser::remove_overrides:iter:{:?}: removing", override_id); + debug!("Parser::remove_overrides:iter:{override_id:?}: removing"); matcher.remove(override_id); } @@ -1351,7 +1323,7 @@ impl<'cmd> Parser<'cmd> { } } for overrider_id in transitive { - debug!("Parser::remove_overrides:iter:{:?}: removing", overrider_id); + debug!("Parser::remove_overrides:iter:{overrider_id:?}: removing"); matcher.remove(overrider_id); } } @@ -1364,13 +1336,13 @@ impl<'cmd> Parser<'cmd> { // Use env only if the arg was absent among command line args, // early return if this is not the case. if matcher.contains(&arg.id) { - debug!("Parser::add_env: Skipping existing arg `{}`", arg); + debug!("Parser::add_env: Skipping existing arg `{arg}`"); continue; } - debug!("Parser::add_env: Checking arg `{}`", arg); + debug!("Parser::add_env: Checking arg `{arg}`"); if let Some((_, Some(ref val))) = arg.env { - debug!("Parser::add_env: Found an opt with value={:?}", val); + debug!("Parser::add_env: Found an opt with value={val:?}"); let arg_values = vec![val.to_owned()]; let trailing_idx = None; let _ = ok!(self.react( @@ -1504,7 +1476,7 @@ impl<'cmd> Parser<'cmd> { remaining_args: &[&OsStr], trailing_values: bool, ) -> ClapError { - debug!("Parser::did_you_mean_error: arg={}", arg); + debug!("Parser::did_you_mean_error: arg={arg}"); // Didn't match a flag or option let longs = self .cmd @@ -1515,7 +1487,7 @@ impl<'cmd> Parser<'cmd> { _ => None, }) .collect::<Vec<_>>(); - debug!("Parser::did_you_mean_error: longs={:?}", longs); + debug!("Parser::did_you_mean_error: longs={longs:?}"); let did_you_mean = suggestions::did_you_mean_flag( arg, diff --git a/vendor/clap_builder/src/parser/validator.rs b/vendor/clap_builder/src/parser/validator.rs index 5c3d34643..17fb7c1e2 100644 --- a/vendor/clap_builder/src/parser/validator.rs +++ b/vendor/clap_builder/src/parser/validator.rs @@ -31,7 +31,7 @@ impl<'cmd> Validator<'cmd> { let has_subcmd = matcher.subcommand_name().is_some(); if let ParseState::Opt(a) = parse_state { - debug!("Validator::validate: needs_val_of={:?}", a); + debug!("Validator::validate: needs_val_of={a:?}"); let o = &self.cmd[&a]; let should_err = if let Some(v) = matcher.args.get(o.get_id()) { @@ -102,7 +102,7 @@ impl<'cmd> Validator<'cmd> { .filter(|(_, matched)| matched.check_explicit(&ArgPredicate::IsPresent)) .filter(|(arg_id, _)| self.cmd.find(arg_id).is_some()) { - debug!("Validator::validate_conflicts::iter: id={:?}", arg_id); + debug!("Validator::validate_conflicts::iter: id={arg_id:?}"); let conflicts = conflicts.gather_conflicts(self.cmd, arg_id); ok!(self.build_conflict_err(arg_id, &conflicts, matcher)); } @@ -130,14 +130,15 @@ impl<'cmd> Validator<'cmd> { .args() .filter(|(_, matched)| matched.check_explicit(&crate::builder::ArgPredicate::IsPresent)) .filter_map(|(id, _)| { - debug!("Validator::validate_exclusive:iter:{:?}", id); + debug!("Validator::validate_exclusive:iter:{id:?}"); self.cmd .find(id) // Find `arg`s which are exclusive but also appear with other args. .filter(|&arg| arg.is_exclusive_set() && args_count > 1) }) - // Throw an error for the first conflict found. - .try_for_each(|arg| { + .next() + .map(|arg| { + // Throw an error for the first conflict found. Err(Error::argument_conflict( self.cmd, arg.to_string(), @@ -147,6 +148,7 @@ impl<'cmd> Validator<'cmd> { .create_usage_with_title(&[]), )) }) + .unwrap_or(Ok(())) } fn build_conflict_err( @@ -159,7 +161,7 @@ impl<'cmd> Validator<'cmd> { return Ok(()); } - debug!("Validator::build_conflict_err: name={:?}", name); + debug!("Validator::build_conflict_err: name={name:?}"); let mut seen = FlatSet::new(); let conflicts = conflict_ids .iter() @@ -226,7 +228,7 @@ impl<'cmd> Validator<'cmd> { .args() .filter(|(_, matched)| matched.check_explicit(&ArgPredicate::IsPresent)) { - debug!("Validator::gather_requires:iter:{:?}", name); + debug!("Validator::gather_requires:iter:{name:?}"); if let Some(arg) = self.cmd.find(name) { let is_relevant = |(val, req_arg): &(ArgPredicate, Id)| -> Option<Id> { let required = matched.check_explicit(val); @@ -237,7 +239,7 @@ impl<'cmd> Validator<'cmd> { self.required.insert(req); } } else if let Some(g) = self.cmd.find_group(name) { - debug!("Validator::gather_requires:iter:{:?}:group", name); + debug!("Validator::gather_requires:iter:{name:?}:group"); for r in &g.requires { self.required.insert(r.clone()); } @@ -261,17 +263,14 @@ impl<'cmd> Validator<'cmd> { .map(|arg| arg.is_exclusive_set()) .unwrap_or_default() }); - debug!( - "Validator::validate_required: is_exclusive_present={}", - is_exclusive_present - ); + debug!("Validator::validate_required: is_exclusive_present={is_exclusive_present}"); for arg_or_group in self .required .iter() .filter(|r| !matcher.check_explicit(r, &ArgPredicate::IsPresent)) { - debug!("Validator::validate_required:iter:aog={:?}", arg_or_group); + debug!("Validator::validate_required:iter:aog={arg_or_group:?}"); if let Some(arg) = self.cmd.find(arg_or_group) { debug!("Validator::validate_required:iter: This is an arg"); if !is_exclusive_present && !self.is_missing_required_ok(arg, conflicts) { @@ -380,7 +379,7 @@ impl<'cmd> Validator<'cmd> { } for group_id in self.cmd.groups_for_arg(a.get_id()) { if !conflicts.gather_conflicts(self.cmd, &group_id).is_empty() { - debug!("Validator::is_missing_required_ok: true ({})", group_id); + debug!("Validator::is_missing_required_ok: true ({group_id})"); return true; } } @@ -402,7 +401,7 @@ impl<'cmd> Validator<'cmd> { matcher: &ArgMatcher, raw_req_args: Vec<Id>, ) -> ClapResult<()> { - debug!("Validator::missing_required_error; incl={:?}", raw_req_args); + debug!("Validator::missing_required_error; incl={raw_req_args:?}"); debug!( "Validator::missing_required_error: reqs={:?}", self.required @@ -429,7 +428,7 @@ impl<'cmd> Validator<'cmd> { } else if let Some(_group) = self.cmd.find_group(id) { self.cmd.format_group(id).to_string() } else { - debug_assert!(false, "id={:?} is unknown", id); + debug_assert!(false, "id={id:?} is unknown"); "".to_owned() } }) @@ -437,10 +436,7 @@ impl<'cmd> Validator<'cmd> { } }; - debug!( - "Validator::missing_required_error: req_args={:#?}", - req_args - ); + debug!("Validator::missing_required_error: req_args={req_args:#?}"); let used: Vec<Id> = matcher .args() @@ -486,7 +482,7 @@ impl Conflicts { } fn gather_conflicts(&self, cmd: &Command, arg_id: &Id) -> Vec<Id> { - debug!("Conflicts::gather_conflicts: arg={:?}", arg_id); + debug!("Conflicts::gather_conflicts: arg={arg_id:?}"); let mut conflicts = Vec::new(); let arg_id_conflicts_storage; @@ -510,7 +506,7 @@ impl Conflicts { } } - debug!("Conflicts::gather_conflicts: conflicts={:?}", conflicts); + debug!("Conflicts::gather_conflicts: conflicts={conflicts:?}"); conflicts } diff --git a/vendor/clap_builder/src/util/any_value.rs b/vendor/clap_builder/src/util/any_value.rs index dc7a3e953..6f1e3665e 100644 --- a/vendor/clap_builder/src/util/any_value.rs +++ b/vendor/clap_builder/src/util/any_value.rs @@ -69,6 +69,12 @@ impl PartialOrd for AnyValueId { } } +impl PartialEq<std::any::TypeId> for AnyValueId { + fn eq(&self, other: &std::any::TypeId) -> bool { + self.type_id == *other + } +} + impl Ord for AnyValueId { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.type_id.cmp(&other.type_id) @@ -109,4 +115,13 @@ mod test { assert_eq!(format!("{:?}", AnyValue::new(5)), "AnyValue { inner: i32 }"); } + + #[test] + fn eq_to_type_id() { + use super::*; + + let any_value_id = AnyValueId::of::<i32>(); + let type_id = std::any::TypeId::of::<i32>(); + assert_eq!(any_value_id, type_id); + } } diff --git a/vendor/clap_builder/src/util/color.rs b/vendor/clap_builder/src/util/color.rs index 7a0e837e7..d13a6df9e 100644 --- a/vendor/clap_builder/src/util/color.rs +++ b/vendor/clap_builder/src/util/color.rs @@ -64,6 +64,15 @@ pub enum ColorChoice { Never, } +impl ColorChoice { + /// Report all `possible_values` + pub fn possible_values() -> impl Iterator<Item = PossibleValue> { + Self::value_variants() + .iter() + .filter_map(ValueEnum::to_possible_value) + } +} + impl Default for ColorChoice { fn default() -> Self { Self::Auto @@ -99,11 +108,9 @@ impl ValueEnum for ColorChoice { fn to_possible_value(&self) -> Option<PossibleValue> { Some(match self { - Self::Auto => { - PossibleValue::new("auto").help("Use colored output if writing to a terminal/TTY") - } - Self::Always => PossibleValue::new("always").help("Always use colored output"), - Self::Never => PossibleValue::new("never").help("Never use colored output"), + Self::Auto => PossibleValue::new("auto"), + Self::Always => PossibleValue::new("always"), + Self::Never => PossibleValue::new("never"), }) } } |