diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:25:56 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:25:56 +0000 |
commit | 018c4950b9406055dec02ef0fb52f132e2bb1e2c (patch) | |
tree | a835ebdf2088ef88fa681f8fad45f09922c1ae9a /vendor/clap_builder | |
parent | Adding debian version 1.75.0+dfsg1-5. (diff) | |
download | rustc-018c4950b9406055dec02ef0fb52f132e2bb1e2c.tar.xz rustc-018c4950b9406055dec02ef0fb52f132e2bb1e2c.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/clap_builder')
-rw-r--r-- | vendor/clap_builder/.cargo-checksum.json | 2 | ||||
-rw-r--r-- | vendor/clap_builder/Cargo.toml | 2 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/app_settings.rs | 1 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/arg.rs | 4 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/command.rs | 84 | ||||
-rw-r--r-- | vendor/clap_builder/src/builder/styled_str.rs | 4 | ||||
-rw-r--r-- | vendor/clap_builder/src/output/help_template.rs | 73 | ||||
-rw-r--r-- | vendor/clap_builder/src/output/usage.rs | 205 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/matches/arg_matches.rs | 4 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/parser.rs | 5 | ||||
-rw-r--r-- | vendor/clap_builder/src/parser/validator.rs | 5 |
11 files changed, 281 insertions, 108 deletions
diff --git a/vendor/clap_builder/.cargo-checksum.json b/vendor/clap_builder/.cargo-checksum.json index c19dd2b4b..eb0ed62a8 100644 --- a/vendor/clap_builder/.cargo-checksum.json +++ b/vendor/clap_builder/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"1e0275e303ef6639e44aafe136acac3c656531119a895688e9e5e23d3e9af1a1","LICENSE-APACHE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","LICENSE-MIT":"0d687e1f07b58fe68bda74668ff6326125e5e5efa184cce755cd84ac535b7058","README.md":"60b99346464866941b21928d3c4699fd6a3ca85a541da7577f60bc691b7afef8","src/builder/action.rs":"9b920d2d405825ce89a5ba3b59edc66e3b849841819e9742b19010a81584fee7","src/builder/app_settings.rs":"286f925717fa54fe9d2ed6f2f338293b7a5981fee0fe687fe706118cebf1f6f4","src/builder/arg.rs":"6d70b08ed37bfc389a4caa4a3b483cae6ed6742d6adb60ab1663cf429805ebd6","src/builder/arg_group.rs":"82a6e9afeea1792a4ca99baa3b0d3235eb012b037cc19333ed9b03a13bb66f30","src/builder/arg_predicate.rs":"4fe55fdd0441acb1577f28188c86f920df4863f451a7dcad8e050dbb6e1e7516","src/builder/arg_settings.rs":"e8ad1bd6d36da43d7329b6cd86833d4cc63734e64119c6b950a45ded5e3aec9c","src/builder/command.rs":"ec064237a6f7504eac26e0394117ea0422465e6817e718a3dc7e380403d0c304","src/builder/debug_asserts.rs":"ee0bc672dac85590102ae3189f61af2c1b202ceaa7835e3df45d89dca274cdae","src/builder/ext.rs":"736cfb56f765cbe23301ebcad83fbe3edfc778954edc4747ccf7c23104d85638","src/builder/mod.rs":"478946dd41eb4adcfd7a3e6159ad1474993fa89e9f1ec62aaf05c213d33be9d7","src/builder/os_str.rs":"8d9efc619a697e314c42bf8c320f26e7d5ca33996ea577d3f74325a8dbf43df5","src/builder/possible_value.rs":"2ed44c5a353c0abab337ac0f00995066f96ff27c33098613642725991163edff","src/builder/range.rs":"63583801f2f9daa43906bda84eb3a2ba9d6b5157745180acbc0a3284babe2d94","src/builder/resettable.rs":"c4cd481051ec361529817ebae73b4dd307b0a4a3b88a3ddcecb8dd45b05db431","src/builder/str.rs":"270f21e462fd7ebe54a3c0f3010d6b1a7f672e4135cb77f51b6188c7f8d46ca7","src/builder/styled_str.rs":"9a605e1fe93f602809645447b4560ad767292eac9a17614c8cdca697d813425e","src/builder/styling.rs":"3aac44f140d5247d27f661e328a05eae0bd8c6685c8bfc88ec703d3a21a47f50","src/builder/tests.rs":"565f5efd38c6596e55fa1c077a11cc07be94ca201527963d27fd42ddce6dbbe8","src/builder/value_hint.rs":"66588792cddf7e3bb2912da4e0a53584169c266f9e4e6dcb990295998d158f93","src/builder/value_parser.rs":"915fb8d50910711d5b704fab4c8fbcb3f1e0e2e66fef722e5806513618864477","src/derive.rs":"7e9e33ecb4c834ff1b6bcffd24358b3e2cfc946a5dc69f5ca8088f7ac4f145ce","src/error/context.rs":"156d2611a349ce826378476c9dcb3242a01ad834a095baad096a10cc2f73e1ed","src/error/format.rs":"33903b182f9b8fde0a2ad2f5f96582ed3812d37c51a03f2c775553db8351e5e8","src/error/kind.rs":"29603c64b8cea7886498afc3f7e7c489505c9820c5159e99d153d57fdafe95ec","src/error/mod.rs":"2ebe49387552c56e1b632fe647e45cbb71d590366785972758aecd04f88f9b90","src/lib.rs":"8b08b2d74ffc9c383f861ec94e41d02ea7c035081f44acd37079baeb1888e5a8","src/macros.rs":"f2c7145b2b10d36a7c2e0cc02502115be4162d2256e12328222121f4eefeb2b5","src/mkeymap.rs":"a644643a54ab1a6e353af4c746efc2c2e9e161e64fe3f3635c644748e02690d8","src/output/fmt.rs":"17d7c95bae851fd0ffb7d3ea4c3c1830963c8b863aa8e4e296e3d824a1da18dc","src/output/help.rs":"b3bb6cfffe9c1113d377f1f4951a22b6ad2ba2813dcc55a146899c808cd393d3","src/output/help_template.rs":"19e725674a92ef2a529e7583c0c139d04a420617be5e91e65341a2063b3d8a68","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":"45dcf5520f0625da75f1ceb1d749aaeb13db882f64025ea89d039a2acfd72898","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":"902f512272d9c4a0c8be7ff3e5122b088ee6fde1694a7b4cfba88f941b361a3b","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":"f177bf3182addb6d271f8a676fb145337a1e7b1eeec7adcc5b61548d11947eb6","src/parser/validator.rs":"107c4eaa1615c0414553862f0250e9bf4241cccb7d7ec6df4ac8784f5f850d11","src/util/any_value.rs":"ac88e78c520ae84edb160c121d1277ce64db3aea7199fbddfe1024d6c312f722","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":"c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663"}
\ No newline at end of file +{"files":{"Cargo.toml":"b0ec7456f97dce46b43efc268f5594d56203220b65fdb8282286b8843a32c0f6","LICENSE-APACHE":"c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4","LICENSE-MIT":"0d687e1f07b58fe68bda74668ff6326125e5e5efa184cce755cd84ac535b7058","README.md":"60b99346464866941b21928d3c4699fd6a3ca85a541da7577f60bc691b7afef8","src/builder/action.rs":"9b920d2d405825ce89a5ba3b59edc66e3b849841819e9742b19010a81584fee7","src/builder/app_settings.rs":"0ab6f9ca6d198d56547adcbeaddb2c3240df82bd79c75903d4a70b3f1f5a1b55","src/builder/arg.rs":"aed6ff41b426f62b7042706a2e595bcd77ae697e59b3cef68ae85b5473c86963","src/builder/arg_group.rs":"82a6e9afeea1792a4ca99baa3b0d3235eb012b037cc19333ed9b03a13bb66f30","src/builder/arg_predicate.rs":"4fe55fdd0441acb1577f28188c86f920df4863f451a7dcad8e050dbb6e1e7516","src/builder/arg_settings.rs":"e8ad1bd6d36da43d7329b6cd86833d4cc63734e64119c6b950a45ded5e3aec9c","src/builder/command.rs":"b32cd2892f95b8edd4508458c79f055f8aee13ee8e2297f3c14b55639e45bbb1","src/builder/debug_asserts.rs":"ee0bc672dac85590102ae3189f61af2c1b202ceaa7835e3df45d89dca274cdae","src/builder/ext.rs":"736cfb56f765cbe23301ebcad83fbe3edfc778954edc4747ccf7c23104d85638","src/builder/mod.rs":"478946dd41eb4adcfd7a3e6159ad1474993fa89e9f1ec62aaf05c213d33be9d7","src/builder/os_str.rs":"8d9efc619a697e314c42bf8c320f26e7d5ca33996ea577d3f74325a8dbf43df5","src/builder/possible_value.rs":"2ed44c5a353c0abab337ac0f00995066f96ff27c33098613642725991163edff","src/builder/range.rs":"63583801f2f9daa43906bda84eb3a2ba9d6b5157745180acbc0a3284babe2d94","src/builder/resettable.rs":"c4cd481051ec361529817ebae73b4dd307b0a4a3b88a3ddcecb8dd45b05db431","src/builder/str.rs":"270f21e462fd7ebe54a3c0f3010d6b1a7f672e4135cb77f51b6188c7f8d46ca7","src/builder/styled_str.rs":"525edf56b80603701cfca1d9f593530e662626070f403a89562322e237c61c35","src/builder/styling.rs":"3aac44f140d5247d27f661e328a05eae0bd8c6685c8bfc88ec703d3a21a47f50","src/builder/tests.rs":"565f5efd38c6596e55fa1c077a11cc07be94ca201527963d27fd42ddce6dbbe8","src/builder/value_hint.rs":"66588792cddf7e3bb2912da4e0a53584169c266f9e4e6dcb990295998d158f93","src/builder/value_parser.rs":"915fb8d50910711d5b704fab4c8fbcb3f1e0e2e66fef722e5806513618864477","src/derive.rs":"7e9e33ecb4c834ff1b6bcffd24358b3e2cfc946a5dc69f5ca8088f7ac4f145ce","src/error/context.rs":"156d2611a349ce826378476c9dcb3242a01ad834a095baad096a10cc2f73e1ed","src/error/format.rs":"33903b182f9b8fde0a2ad2f5f96582ed3812d37c51a03f2c775553db8351e5e8","src/error/kind.rs":"29603c64b8cea7886498afc3f7e7c489505c9820c5159e99d153d57fdafe95ec","src/error/mod.rs":"2ebe49387552c56e1b632fe647e45cbb71d590366785972758aecd04f88f9b90","src/lib.rs":"8b08b2d74ffc9c383f861ec94e41d02ea7c035081f44acd37079baeb1888e5a8","src/macros.rs":"f2c7145b2b10d36a7c2e0cc02502115be4162d2256e12328222121f4eefeb2b5","src/mkeymap.rs":"a644643a54ab1a6e353af4c746efc2c2e9e161e64fe3f3635c644748e02690d8","src/output/fmt.rs":"17d7c95bae851fd0ffb7d3ea4c3c1830963c8b863aa8e4e296e3d824a1da18dc","src/output/help.rs":"b3bb6cfffe9c1113d377f1f4951a22b6ad2ba2813dcc55a146899c808cd393d3","src/output/help_template.rs":"256477c3b8ff85570c5625e15e019262514fe65959140383d978c1704fee9091","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":"2c2369e62b8f9fb6de52c8f52966a44a23b3b4aab9922b27343be703e1cf5bec","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":"ef5aea99d598a6c843b8bb91d960581a5d8733ee46c03a949e34bce41c6a16e6","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":"64fe409b7db9815d11f26be00f5eb65ed08df32d271c69c5f49e5e67fc4aaa96","src/parser/validator.rs":"32b2ca71fa71fe9d41821589d5d445c8e763db747e1f0b5bce83985b0e5f89b2","src/util/any_value.rs":"ac88e78c520ae84edb160c121d1277ce64db3aea7199fbddfe1024d6c312f722","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":"a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb"}
\ No newline at end of file diff --git a/vendor/clap_builder/Cargo.toml b/vendor/clap_builder/Cargo.toml index a0d1232de..cc83f9deb 100644 --- a/vendor/clap_builder/Cargo.toml +++ b/vendor/clap_builder/Cargo.toml @@ -13,7 +13,7 @@ edition = "2021" rust-version = "1.70.0" name = "clap_builder" -version = "4.4.7" +version = "4.4.11" include = [ "build.rs", "src/**/*", diff --git a/vendor/clap_builder/src/builder/app_settings.rs b/vendor/clap_builder/src/builder/app_settings.rs index 4fce4b4a2..f9a87dadc 100644 --- a/vendor/clap_builder/src/builder/app_settings.rs +++ b/vendor/clap_builder/src/builder/app_settings.rs @@ -57,6 +57,7 @@ pub(crate) enum AppSettings { SubcommandsNegateReqs, ArgsNegateSubcommands, SubcommandPrecedenceOverArg, + FlattenHelp, ArgRequiredElseHelp, NextLineHelp, DisableColoredHelp, diff --git a/vendor/clap_builder/src/builder/arg.rs b/vendor/clap_builder/src/builder/arg.rs index 8e247c176..f83b4642c 100644 --- a/vendor/clap_builder/src/builder/arg.rs +++ b/vendor/clap_builder/src/builder/arg.rs @@ -875,7 +875,7 @@ impl Arg { impl Arg { /// Specify how to react to an argument when parsing it. /// - /// [ArgAction][crate::ArgAction] controls things like + /// [ArgAction] controls things like /// - Overwriting previous values with new ones /// - Appending new values to all previous ones /// - Counting how many times a flag occurs @@ -1260,7 +1260,7 @@ impl Arg { /// Provide the shell a hint about how to complete this argument. /// - /// See [`ValueHint`][crate::ValueHint] for more information. + /// See [`ValueHint`] for more information. /// /// **NOTE:** implicitly sets [`Arg::action(ArgAction::Set)`]. /// diff --git a/vendor/clap_builder/src/builder/command.rs b/vendor/clap_builder/src/builder/command.rs index edcbace76..6e56b1834 100644 --- a/vendor/clap_builder/src/builder/command.rs +++ b/vendor/clap_builder/src/builder/command.rs @@ -298,6 +298,45 @@ impl Command { self } + /// Allows one to mutate an [`ArgGroup`] after it's been added to a [`Command`]. + /// + /// # Panics + /// + /// If the argument is undefined + /// + /// # Examples + /// + /// ```rust + /// # use clap_builder as clap; + /// # use clap::{Command, arg, ArgGroup}; + /// + /// Command::new("foo") + /// .arg(arg!(--"set-ver" <ver> "set the version manually").required(false)) + /// .arg(arg!(--major "auto increase major")) + /// .arg(arg!(--minor "auto increase minor")) + /// .arg(arg!(--patch "auto increase patch")) + /// .group(ArgGroup::new("vers") + /// .args(["set-ver", "major", "minor","patch"]) + /// .required(true)) + /// .mut_group("vers", |a| a.required(false)); + /// ``` + #[must_use] + #[cfg_attr(debug_assertions, track_caller)] + pub fn mut_group<F>(mut self, arg_id: impl AsRef<str>, f: F) -> Self + where + F: FnOnce(ArgGroup) -> ArgGroup, + { + let id = arg_id.as_ref(); + let index = self + .groups + .iter() + .position(|g| g.get_id() == id) + .unwrap_or_else(|| panic!("Group `{id}` is undefined")); + let a = self.groups.remove(index); + + self.groups.push(f(a)); + self + } /// Allows one to mutate a [`Command`] after it's been added as a subcommand. /// /// This can be useful for modifying auto-generated arguments of nested subcommands with @@ -1070,7 +1109,7 @@ impl Command { /// Replace prior occurrences of arguments rather than error /// /// For any argument that would conflict with itself by default (e.g. - /// [`ArgAction::Set`][ArgAction::Set], it will now override itself. + /// [`ArgAction::Set`], it will now override itself. /// /// This is the equivalent to saying the `foo` arg using [`Arg::overrides_with("foo")`] for all /// defined arguments. @@ -1359,7 +1398,7 @@ impl Command { /// assert_eq!(res.unwrap_err().kind(), ErrorKind::UnknownArgument); /// ``` /// - /// You can create a custom version flag with [`ArgAction::Help`], [`ArgAction::HelpShort`], or + /// You can create a custom help flag with [`ArgAction::Help`], [`ArgAction::HelpShort`], or /// [`ArgAction::HelpLong`] /// ```rust /// # use clap_builder as clap; @@ -2049,6 +2088,21 @@ impl Command { self } + /// Flatten subcommand help into the current command's help + /// + /// This shows a summary of subcommands within the usage and help for the current command, similar to + /// `git stash --help` showing information on `push`, `pop`, etc. + /// To see more information, a user can still pass `--help` to the individual subcommands. + #[inline] + #[must_use] + pub fn flatten_help(self, yes: bool) -> Self { + if yes { + self.setting(AppSettings::FlattenHelp) + } else { + self.unset_setting(AppSettings::FlattenHelp) + } + } + /// Set the default section heading for future args. /// /// This will be used for any arg that hasn't had [`Arg::help_heading`] called. @@ -3335,6 +3389,20 @@ impl Command { self.usage_name.as_deref() } + #[inline] + #[cfg(feature = "usage")] + pub(crate) fn get_usage_name_fallback(&self) -> &str { + self.get_usage_name() + .unwrap_or_else(|| self.get_bin_name_fallback()) + } + + #[inline] + #[cfg(not(feature = "usage"))] + #[allow(dead_code)] + pub(crate) fn get_usage_name_fallback(&self) -> &str { + self.get_bin_name_fallback() + } + /// Get the name of the binary. #[inline] pub fn get_display_name(&self) -> Option<&str> { @@ -3347,6 +3415,12 @@ impl Command { self.bin_name.as_deref() } + /// Get the name of the binary. + #[inline] + pub(crate) fn get_bin_name_fallback(&self) -> &str { + self.bin_name.as_deref().unwrap_or_else(|| self.get_name()) + } + /// Set binary name. Uses `&mut self` instead of `self`. pub fn set_bin_name(&mut self, name: impl Into<String>) { self.bin_name = Some(name.into()); @@ -3410,6 +3484,12 @@ impl Command { self.long_about.as_ref() } + /// Get the custom section heading specified via [`Command::flatten_help`]. + #[inline] + pub fn is_flatten_help_set(&self) -> bool { + self.is_set(AppSettings::FlattenHelp) + } + /// Get the custom section heading specified via [`Command::next_help_heading`]. /// /// [`Command::help_heading`]: Command::help_heading() diff --git a/vendor/clap_builder/src/builder/styled_str.rs b/vendor/clap_builder/src/builder/styled_str.rs index df0f1b03b..e06ddbc9e 100644 --- a/vendor/clap_builder/src/builder/styled_str.rs +++ b/vendor/clap_builder/src/builder/styled_str.rs @@ -45,10 +45,6 @@ impl StyledStr { self.0.push_str(msg); } - pub(crate) fn trim(&mut self) { - self.0 = self.0.trim().to_owned() - } - pub(crate) fn trim_start_lines(&mut self) { if let Some(pos) = self.0.find('\n') { let (leading, help) = self.0.split_at(pos + 1); diff --git a/vendor/clap_builder/src/output/help_template.rs b/vendor/clap_builder/src/output/help_template.rs index da2e75413..9fe7211b3 100644 --- a/vendor/clap_builder/src/output/help_template.rs +++ b/vendor/clap_builder/src/output/help_template.rs @@ -393,9 +393,11 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { .filter_map(|arg| arg.get_help_heading()) .collect::<FlatSet<_>>(); + let flatten = self.cmd.is_flatten_help_set(); + let mut first = true; - if subcmds { + if subcmds && !flatten { if !first { self.writer.push_str("\n\n"); } @@ -474,6 +476,11 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { } } } + if subcmds && flatten { + let mut cmd = self.cmd.clone(); + cmd.build(); + self.write_flat_subcommands(&cmd, &mut first); + } } /// Sorts arguments by length and display order and write their help to the wrapped stream. @@ -874,6 +881,70 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { /// Subcommand handling impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> { /// Writes help for subcommands of a Parser Object to the wrapped stream. + fn write_flat_subcommands(&mut self, cmd: &Command, first: &mut bool) { + debug!( + "HelpTemplate::write_flat_subcommands, cmd={}, first={}", + cmd.get_name(), + *first + ); + use std::fmt::Write as _; + let header = &self.styles.get_header(); + + let mut ord_v = Vec::new(); + for subcommand in cmd + .get_subcommands() + .filter(|subcommand| should_show_subcommand(subcommand)) + { + ord_v.push(( + subcommand.get_display_order(), + subcommand.get_name(), + subcommand, + )); + } + ord_v.sort_by(|a, b| (a.0, &a.1).cmp(&(b.0, &b.1))); + for (_, _, subcommand) in ord_v { + if !*first { + self.writer.push_str("\n\n"); + } + *first = false; + + let heading = subcommand.get_usage_name_fallback(); + let about = subcommand + .get_about() + .or_else(|| subcommand.get_long_about()) + .unwrap_or_default(); + + let _ = write!( + self.writer, + "{}{heading}:{}\n", + header.render(), + header.render_reset() + ); + if !about.is_empty() { + let _ = write!(self.writer, "{about}\n",); + } + + let mut sub_help = HelpTemplate { + writer: self.writer, + cmd: subcommand, + styles: self.styles, + usage: self.usage, + next_line_help: self.next_line_help, + term_w: self.term_w, + use_long: self.use_long, + }; + let args = subcommand + .get_arguments() + .filter(|arg| should_show_arg(self.use_long, arg) && !arg.is_global_set()) + .collect::<Vec<_>>(); + sub_help.write_args(&args, heading, option_sort_key); + if subcommand.is_flatten_help_set() { + sub_help.write_flat_subcommands(subcommand, first); + } + } + } + + /// Writes help for subcommands of a Parser Object to the wrapped stream. fn write_subcommands(&mut self, cmd: &Command) { debug!("HelpTemplate::write_subcommands"); use std::fmt::Write as _; diff --git a/vendor/clap_builder/src/output/usage.rs b/vendor/clap_builder/src/output/usage.rs index 884a64df9..d75b704ba 100644 --- a/vendor/clap_builder/src/output/usage.rs +++ b/vendor/clap_builder/src/output/usage.rs @@ -14,6 +14,7 @@ use crate::util::FlatSet; use crate::util::Id; static DEFAULT_SUB_VALUE_NAME: &str = "COMMAND"; +const USAGE_SEP: &str = "\n "; pub(crate) struct Usage<'cmd> { cmd: &'cmd Command, @@ -39,8 +40,6 @@ impl<'cmd> Usage<'cmd> { // any subcommands have been parsed (so as to give subcommands their own usage recursively) pub(crate) fn create_usage_with_title(&self, used: &[Id]) -> Option<StyledStr> { debug!("Usage::create_usage_with_title"); - let usage = some!(self.create_usage_no_title(used)); - use std::fmt::Write as _; let mut styled = StyledStr::new(); let _ = write!( @@ -49,28 +48,49 @@ impl<'cmd> Usage<'cmd> { self.styles.get_usage().render(), self.styles.get_usage().render_reset() ); - styled.push_styled(&usage); + if self.write_usage_no_title(&mut styled, used) { + styled.trim_end(); + } else { + return None; + } + debug!("Usage::create_usage_with_title: usage={styled}"); Some(styled) } // Creates a usage string (*without title*) if one was not provided by the user manually. pub(crate) fn create_usage_no_title(&self, used: &[Id]) -> Option<StyledStr> { debug!("Usage::create_usage_no_title"); + + let mut styled = StyledStr::new(); + if self.write_usage_no_title(&mut styled, used) { + styled.trim_end(); + debug!("Usage::create_usage_no_title: usage={styled}"); + Some(styled) + } else { + None + } + } + + // Creates a usage string (*without title*) if one was not provided by the user manually. + fn write_usage_no_title(&self, styled: &mut StyledStr, used: &[Id]) -> bool { + debug!("Usage::create_usage_no_title"); if let Some(u) = self.cmd.get_override_usage() { - Some(u.clone()) + styled.push_styled(u); + true } else { #[cfg(feature = "usage")] { if used.is_empty() { - Some(self.create_help_usage(true)) + self.write_help_usage(styled); } else { - Some(self.create_smart_usage(used)) + self.write_smart_usage(styled, used); } + true } #[cfg(not(feature = "usage"))] { - None + false } } } @@ -79,43 +99,97 @@ impl<'cmd> Usage<'cmd> { #[cfg(feature = "usage")] 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:?}"); + fn write_help_usage(&self, styled: &mut StyledStr) { + debug!("Usage::write_help_usage"); + use std::fmt::Write; + + if self.cmd.has_visible_subcommands() && self.cmd.is_flatten_help_set() { + if !self.cmd.is_subcommand_required_set() + || self.cmd.is_args_conflicts_with_subcommands_set() + { + self.write_arg_usage(styled, &[], true); + styled.trim_end(); + let _ = write!(styled, "{}", USAGE_SEP); + } + let mut cmd = self.cmd.clone(); + cmd.build(); + for (i, sub) in cmd + .get_subcommands() + .filter(|c| !c.is_hide_set()) + .enumerate() + { + if i != 0 { + styled.trim_end(); + let _ = write!(styled, "{}", USAGE_SEP); + } + Usage::new(sub).write_usage_no_title(styled, &[]); + } + } else { + self.write_arg_usage(styled, &[], true); + self.write_subcommand_usage(styled); + } + } + + // Creates a context aware usage string, or "smart usage" from currently used + // args, and requirements + fn write_smart_usage(&self, styled: &mut StyledStr, used: &[Id]) { + debug!("Usage::create_smart_usage"); + use std::fmt::Write; + let placeholder = &self.styles.get_placeholder(); + + self.write_arg_usage(styled, used, true); + + if self.cmd.is_subcommand_required_set() { + let value_name = self + .cmd + .get_subcommand_value_name() + .unwrap_or(DEFAULT_SUB_VALUE_NAME); + let _ = write!( + styled, + "{}<{value_name}>{}", + placeholder.render(), + placeholder.render_reset() + ); + } + } + + fn write_arg_usage(&self, styled: &mut StyledStr, used: &[Id], incl_reqs: bool) { + debug!("Usage::write_arg_usage; incl_reqs={incl_reqs:?}"); use std::fmt::Write as _; let literal = &self.styles.get_literal(); let placeholder = &self.styles.get_placeholder(); - let mut styled = StyledStr::new(); - let name = self - .cmd - .get_usage_name() - .or_else(|| self.cmd.get_bin_name()) - .unwrap_or_else(|| self.cmd.get_name()); - if !name.is_empty() { + let bin_name = self.cmd.get_usage_name_fallback(); + if !bin_name.is_empty() { // the trim won't properly remove a leading space due to the formatting let _ = write!( styled, - "{}{name}{}", + "{}{bin_name}{} ", literal.render(), literal.render_reset() ); } - if self.needs_options_tag() { + if used.is_empty() && self.needs_options_tag() { let _ = write!( styled, - "{} [OPTIONS]{}", + "{}[OPTIONS]{} ", placeholder.render(), placeholder.render_reset() ); } - self.write_args(&[], !incl_reqs, &mut styled); + self.write_args(styled, used, !incl_reqs); + } + + fn write_subcommand_usage(&self, styled: &mut StyledStr) { + debug!("Usage::write_subcommand_usage"); + use std::fmt::Write as _; // incl_reqs is only false when this function is called recursively - if self.cmd.has_visible_subcommands() && incl_reqs - || self.cmd.is_allow_external_subcommands_set() - { + if self.cmd.has_visible_subcommands() || self.cmd.is_allow_external_subcommands_set() { + let literal = &self.styles.get_literal(); + let placeholder = &self.styles.get_placeholder(); let value_name = self .cmd .get_subcommand_value_name() @@ -123,81 +197,42 @@ impl<'cmd> Usage<'cmd> { if self.cmd.is_subcommand_negates_reqs_set() || self.cmd.is_args_conflicts_with_subcommands_set() { - let _ = write!(styled, "\n "); + styled.trim_end(); + let _ = write!(styled, "{}", USAGE_SEP); if self.cmd.is_args_conflicts_with_subcommands_set() { + let bin_name = self.cmd.get_usage_name_fallback(); // Short-circuit full usage creation since no args will be relevant let _ = write!( styled, - "{}{name}{}", + "{}{bin_name}{} ", literal.render(), literal.render_reset() ); } else { - styled.push_styled(&self.create_help_usage(false)); + self.write_arg_usage(styled, &[], false); } let _ = write!( styled, - " {}<{value_name}>{}", + "{}<{value_name}>{}", placeholder.render(), placeholder.render_reset() ); } else if self.cmd.is_subcommand_required_set() { let _ = write!( styled, - " {}<{value_name}>{}", + "{}<{value_name}>{}", placeholder.render(), placeholder.render_reset() ); } else { let _ = write!( styled, - " {}[{value_name}]{}", + "{}[{value_name}]{}", placeholder.render(), placeholder.render_reset() ); } } - styled.trim(); - debug!("Usage::create_help_usage: usage={styled}"); - styled - } - - // Creates a context aware usage string, or "smart usage" from currently used - // args, and requirements - fn create_smart_usage(&self, used: &[Id]) -> StyledStr { - debug!("Usage::create_smart_usage"); - use std::fmt::Write; - let literal = &self.styles.get_literal(); - let placeholder = &self.styles.get_placeholder(); - let mut styled = StyledStr::new(); - - let bin_name = self - .cmd - .get_usage_name() - .or_else(|| self.cmd.get_bin_name()) - .unwrap_or_else(|| self.cmd.get_name()); - let _ = write!( - styled, - "{}{bin_name}{}", - literal.render(), - literal.render_reset() - ); - - self.write_args(used, false, &mut styled); - - if self.cmd.is_subcommand_required_set() { - let value_name = self - .cmd - .get_subcommand_value_name() - .unwrap_or(DEFAULT_SUB_VALUE_NAME); - let _ = write!( - styled, - " {}<{value_name}>{}", - placeholder.render(), - placeholder.render_reset() - ); - } - styled } // Determines if we need the `[OPTIONS]` tag in the usage string @@ -251,15 +286,8 @@ impl<'cmd> Usage<'cmd> { } // Returns the required args in usage string form by fully unrolling all groups - pub(crate) fn write_args(&self, incls: &[Id], force_optional: bool, styled: &mut StyledStr) { - for required in self.get_args(incls, force_optional) { - styled.push_str(" "); - styled.push_styled(&required); - } - } - - pub(crate) fn get_args(&self, incls: &[Id], force_optional: bool) -> Vec<StyledStr> { - debug!("Usage::get_args: incls={incls:?}",); + pub(crate) fn write_args(&self, styled: &mut StyledStr, incls: &[Id], force_optional: bool) { + debug!("Usage::write_args: incls={incls:?}",); use std::fmt::Write as _; let literal = &self.styles.get_literal(); @@ -366,17 +394,20 @@ impl<'cmd> Usage<'cmd> { } } - let mut ret_val = Vec::new(); if !force_optional { - ret_val.extend(required_opts); - ret_val.extend(required_groups); + for arg in required_opts { + styled.push_styled(&arg); + styled.push_str(" "); + } + for arg in required_groups { + styled.push_styled(&arg); + styled.push_str(" "); + } } - for pos in required_positionals.into_iter().flatten() { - ret_val.push(pos); + for arg in required_positionals.into_iter().flatten() { + styled.push_styled(&arg); + styled.push_str(" "); } - - debug!("Usage::get_args: ret_val={ret_val:?}"); - ret_val } pub(crate) fn get_required_usage_from( diff --git a/vendor/clap_builder/src/parser/matches/arg_matches.rs b/vendor/clap_builder/src/parser/matches/arg_matches.rs index 8390b0b58..e80c39b45 100644 --- a/vendor/clap_builder/src/parser/matches/arg_matches.rs +++ b/vendor/clap_builder/src/parser/matches/arg_matches.rs @@ -514,7 +514,7 @@ impl ArgMatches { MatchesError::unwrap(id, self.try_contains_id(id)) } - /// Iterate over [`Arg`][crate::Arg] and [`ArgGroup`][crate::ArgGroup] [`Id`][crate::Id]s via [`ArgMatches::ids`]. + /// Iterate over [`Arg`][crate::Arg] and [`ArgGroup`][crate::ArgGroup] [`Id`]s via [`ArgMatches::ids`]. /// /// # Examples /// @@ -1325,7 +1325,7 @@ pub(crate) struct SubCommand { pub(crate) matches: ArgMatches, } -/// Iterate over [`Arg`][crate::Arg] and [`ArgGroup`][crate::ArgGroup] [`Id`][crate::Id]s via [`ArgMatches::ids`]. +/// Iterate over [`Arg`][crate::Arg] and [`ArgGroup`][crate::ArgGroup] [`Id`]s via [`ArgMatches::ids`]. /// /// # Examples /// diff --git a/vendor/clap_builder/src/parser/parser.rs b/vendor/clap_builder/src/parser/parser.rs index 4b24eb0de..93616d68a 100644 --- a/vendor/clap_builder/src/parser/parser.rs +++ b/vendor/clap_builder/src/parser/parser.rs @@ -501,10 +501,7 @@ impl<'cmd> Parser<'cmd> { self.cmd, arg_os.display().to_string(), candidates, - self.cmd - .get_bin_name() - .unwrap_or_else(|| self.cmd.get_name()) - .to_owned(), + self.cmd.get_bin_name_fallback().to_owned(), suggested_trailing_arg, Usage::new(self.cmd).create_usage_with_title(&[]), ); diff --git a/vendor/clap_builder/src/parser/validator.rs b/vendor/clap_builder/src/parser/validator.rs index 17fb7c1e2..55f4633cc 100644 --- a/vendor/clap_builder/src/parser/validator.rs +++ b/vendor/clap_builder/src/parser/validator.rs @@ -63,10 +63,7 @@ impl<'cmd> Validator<'cmd> { } } if !has_subcmd && self.cmd.is_subcommand_required_set() { - let bn = self - .cmd - .get_bin_name() - .unwrap_or_else(|| self.cmd.get_name()); + let bn = self.cmd.get_bin_name_fallback(); return Err(Error::missing_subcommand( self.cmd, bn.to_string(), |