Repository: clap-rs/clap
Pull request #4912 (2023-05-17 21:34:36)

fix(assert): Clarify last assertion
An incremental improvement for #4911.

<!--
Thanks for helping out!

Please link the appropriate issue from your PR.

If you don't have an issue, we'd recommend starting with one first so the PR can focus on the
implementation (unless its an obvious bug or documentation fix that will have
little conversation).
-->



Patch:
diff --git a/clap_builder/src/builder/debug_asserts.rs b/clap_builder/src/builder/debug_asserts.rs
index c01662e1..83b1dea8 100644
--- a/clap_builder/src/builder/debug_asserts.rs
+++ b/clap_builder/src/builder/debug_asserts.rs
@@ -586,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
diff --git a/clap_builder/src/builder/value_parser.rs b/clap_builder/src/builder/value_parser.rs
index 4b095578..461309ab 100644
--- a/clap_builder/src/builder/value_parser.rs
+++ b/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 of [`PossibleValue`][crate::builder::PossibleValue].
+    /// Verify the value is from an enumerated set pf [`PossibleValue`][crate::builder::PossibleValue].
     pub fn new(values: impl Into<PossibleValuesParser>) -> Self {
         values.into()
     }
diff --git a/clap_complete/src/generator/mod.rs b/clap_complete/src/generator/mod.rs
index a371f68a..c6e5c5ec 100644
--- a/clap_complete/src/generator/mod.rs
+++ b/clap_complete/src/generator/mod.rs
@@ -162,32 +162,6 @@ pub trait Generator {
 ///
 /// **NOTE:** Please look at the individual [shells][crate::shells]
 /// to see the name of the files generated.
-///
-/// Using [`ValueEnum::value_variants()`][clap::ValueEnum::value_variants] you can easily loop over
-/// all the supported shell variants to generate all the completions at once too.
-///
-/// ```ignore
-/// use clap::ValueEnum;
-/// use clap_complete::{generate_to, Shell};
-/// use std::env;
-/// use std::io::Error;
-///
-/// include!("src/cli.rs");
-///
-/// fn main() -> Result<(), Error> {
-///     let outdir = match env::var_os("OUT_DIR") {
-///         None => return Ok(()),
-///         Some(outdir) => outdir,
-///     };
-///
-///     let mut cmd = build_cli();
-///     for &shell in Shell::value_variants() {
-///         generate_to(shell, &mut cmd, "myapp", outdir)?;
-///     }
-///
-///     Ok(())
-/// }
-/// ```
 pub fn generate_to<G, S, T>(
     gen: G,
     cmd: &mut Command,


Test patch:
diff --git a/tests/builder/multiple_values.rs b/tests/builder/multiple_values.rs
index 702e8667..78dc5491 100644
--- a/tests/builder/multiple_values.rs
+++ b/tests/builder/multiple_values.rs
@@ -1082,10 +1082,8 @@ fn req_delimiter_complex() {
 // This tests a programmer error and will only succeed with debug_assertions
 #[cfg(debug_assertions)]
 #[test]
-#[should_panic = "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."]
+#[should_panic = "Positional argument `[target]` *must* have `required(true)` or `last(true)` set \
+because a prior positional argument (`<files>...`) has `num_args(1..)`"]
 fn low_index_positional_not_required() {
     let _ = Command::new("lip")
         .arg(