nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: clap-rs/clap
Pull request #4302 (2022-09-30 16:25:19)

fix(error): Improve errors when groups are involved
These were found wh8le working on #3165


Patch:
diff --git a/src/parser/validator.rs b/src/parser/validator.rs
index 7379b20f..8b6e46c6 100644
--- a/src/parser/validator.rs
+++ b/src/parser/validator.rs
@@ -193,7 +193,7 @@ impl<'cmd> Validator<'cmd> {
             .filter(|arg_id| matcher.check_explicit(arg_id, &ArgPredicate::IsPresent))
             .filter(|n| {
                 // Filter out the args we don't want to specify.
-                self.cmd.find(n).map_or(true, |a| !a.is_hide_set())
+                self.cmd.find(n).map_or(false, |a| !a.is_hide_set())
             })
             .filter(|key| !conflicting_keys.contains(key))
             .cloned()
@@ -438,7 +438,7 @@ impl<'cmd> Validator<'cmd> {
             .filter(|arg_id| matcher.check_explicit(arg_id, &ArgPredicate::IsPresent))
             .filter(|n| {
                 // Filter out the args we don't want to specify.
-                self.cmd.find(n).map_or(true, |a| !a.is_hide_set())
+                self.cmd.find(n).map_or(false, |a| !a.is_hide_set())
             })
             .cloned()
             .chain(raw_req_args)


Test patch:
diff --git a/tests/builder/groups.rs b/tests/builder/groups.rs
index 085996b6..17bd9c37 100644
--- a/tests/builder/groups.rs
+++ b/tests/builder/groups.rs
@@ -296,6 +296,47 @@ fn group_acts_like_arg() {
     assert!(result.is_ok(), "{}", result.unwrap_err());
     let m = result.unwrap();
     assert!(m.contains_id("mode"));
+    assert_eq!(m.get_one::<clap::Id>("mode").unwrap(), "debug");
+}
+
+#[test]
+fn conflict_with_overlapping_group_in_error() {
+    static ERR: &str = "\
+error: The argument '--major' cannot be used with '--minor'
+
+Usage: prog --major
+
+For more information try '--help'
+";
+
+    let cmd = Command::new("prog")
+        .group(ArgGroup::new("all").multiple(true))
+        .arg(arg!(--major).group("vers").group("all"))
+        .arg(arg!(--minor).group("vers").group("all"))
+        .arg(arg!(--other).group("all"));
+
+    utils::assert_output(cmd, "prog --major --minor", ERR, true);
+}
+
+#[test]
+fn requires_group_with_overlapping_group_in_error() {
+    static ERR: &str = "\
+error: The following required arguments were not provided:
+  <--in|--spec>
+
+Usage: prog --config <--in|--spec>
+
+For more information try '--help'
+";
+
+    let cmd = Command::new("prog")
+        .group(ArgGroup::new("all").multiple(true))
+        .group(ArgGroup::new("input").required(true))
+        .arg(arg!(--in).group("input").group("all"))
+        .arg(arg!(--spec).group("input").group("all"))
+        .arg(arg!(--config).requires("input").group("all"));
+
+    utils::assert_output(cmd, "prog --config", ERR, true);
 }
 
 /* This is used to be fixed in a hack, we need to find a better way to fix it.
Repository: clap-rs/clap
Pull request #4305 (2022-09-30 17:24:46)

feat(derive): Report the group id
This will be needed when we support flattening for #3165

<!--
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_derive/src/derives/args.rs b/clap_derive/src/derives/args.rs
index a92d02ee..21786505 100644
--- a/clap_derive/src/derives/args.rs
+++ b/clap_derive/src/derives/args.rs
@@ -90,6 +90,13 @@ pub fn gen_for_struct(
     let augmentation = gen_augment(fields, &app_var, item, false);
     let augmentation_update = gen_augment(fields, &app_var, item, true);
 
+    let group_id = if item.skip_group() {
+        quote!(None)
+    } else {
+        let group_id = item.ident().unraw().to_string();
+        quote!(Some(clap::Id::from(#group_id)))
+    };
+
     quote! {
         #[allow(dead_code, unreachable_code, unused_variables, unused_braces)]
         #[allow(
@@ -140,6 +147,9 @@ pub fn gen_for_struct(
         )]
         #[deny(clippy::correctness)]
         impl #impl_generics clap::Args for #item_name #ty_generics #where_clause {
+            fn group_id() -> Option<clap::Id> {
+                #group_id
+            }
             fn augment_args<'b>(#app_var: clap::Command) -> clap::Command {
                 #augmentation
             }
@@ -313,11 +323,11 @@ pub fn gen_augment(
         quote!()
     };
     let initial_app_methods = parent_item.initial_top_level_methods();
-    let group_id = parent_item.ident().unraw().to_string();
     let final_app_methods = parent_item.final_top_level_methods();
     let group_app_methods = if parent_item.skip_group() {
         quote!()
     } else {
+        let group_id = parent_item.ident().unraw().to_string();
         let literal_group_members = fields
             .iter()
             .filter_map(|(_field, item)| {


Test patch:
diff --git a/tests/derive/groups.rs b/tests/derive/groups.rs
index 99cba73e..23a9fff3 100644
--- a/tests/derive/groups.rs
+++ b/tests/derive/groups.rs
@@ -53,6 +53,10 @@ Usage: prog --add <CRATES|--path <PATH>|--git <GIT>>
 For more information try '--help'
 ";
     assert_output::<Opt>("prog --add", OUTPUT, true);
+
+    use clap::Args;
+    assert_eq!(Source::group_id(), Some(clap::Id::from("Source")));
+    assert_eq!(Opt::group_id(), Some(clap::Id::from("Opt")));
 }
 
 #[test]
@@ -80,4 +84,9 @@ fn skip_group_avoids_duplicate_ids() {
 
     use clap::CommandFactory;
     Opt::command().debug_assert();
+
+    use clap::Args;
+    assert_eq!(Empty::group_id(), None);
+    assert_eq!(Compose::<Empty, Empty>::group_id(), None);
+    assert_eq!(Opt::group_id(), Some(clap::Id::from("Opt")));
 }
Repository: clap-rs/clap
Pull request #4382 (2022-10-13 17:10:22)

fix(error): Consistently indent suggestions
<!--
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/src/error/format.rs b/src/error/format.rs
index 018a02c3..4442a8e5 100644
--- a/src/error/format.rs
+++ b/src/error/format.rs
@@ -194,9 +194,11 @@ fn write_dynamic_context(error: &crate::error::Error, styled: &mut StyledStr) ->
 
                 let suggestion = error.get(ContextKind::SuggestedCommand);
                 if let Some(ContextValue::String(suggestion)) = suggestion {
+                    styled.none("\n\n");
+                    styled.none(TAB);
                     styled.none(
-            "\n\nIf you believe you received this message in error, try re-running with '",
-        );
+                        "If you believe you received this message in error, try re-running with '",
+                    );
                     styled.good(suggestion);
                     styled.none("'");
                 }


Test patch:
diff --git a/tests/builder/subcommands.rs b/tests/builder/subcommands.rs
index 57ed714f..8437aef0 100644
--- a/tests/builder/subcommands.rs
+++ b/tests/builder/subcommands.rs
@@ -102,7 +102,7 @@ error: The subcommand 'subcm' wasn't recognized
 
   Did you mean 'subcmd'?
 
-If you believe you received this message in error, try re-running with 'dym -- subcm'
+  If you believe you received this message in error, try re-running with 'dym -- subcm'
 
 Usage: dym [COMMAND]
 
@@ -123,7 +123,7 @@ error: The subcommand 'te' wasn't recognized
 
   Did you mean 'test', 'temp'?
 
-If you believe you received this message in error, try re-running with 'dym -- te'
+  If you believe you received this message in error, try re-running with 'dym -- te'
 
 Usage: dym [COMMAND]
 
@@ -524,7 +524,7 @@ error: The subcommand 'baz' wasn't recognized
 
   Did you mean 'bar'?
 
-If you believe you received this message in error, try re-running with ' -- baz'
+  If you believe you received this message in error, try re-running with ' -- baz'
 
 Usage: <COMMAND>
Repository: clap-rs/clap
Pull request #4384 (2022-10-13 18:57:08)

fix(error): Be consistent in puncutation
<!--
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/src/error/format.rs b/src/error/format.rs
index 2e0f8e9f..d6edf31c 100644
--- a/src/error/format.rs
+++ b/src/error/format.rs
@@ -149,7 +149,7 @@ fn write_dynamic_context(error: &crate::error::Error, styled: &mut StyledStr) ->
             if let Some(ContextValue::String(invalid_arg)) = invalid_arg {
                 styled.none("Equal sign is needed when assigning values to '");
                 styled.warning(invalid_arg);
-                styled.none("'.");
+                styled.none("'");
                 true
             } else {
                 false


Test patch:
diff --git a/tests/builder/empty_values.rs b/tests/builder/empty_values.rs
index 02aa7cf2..d818c0b9 100644
--- a/tests/builder/empty_values.rs
+++ b/tests/builder/empty_values.rs
@@ -118,7 +118,7 @@ fn no_empty_values_without_equals_but_requires_equals() {
     assert_eq!(m.unwrap_err().kind(), ErrorKind::NoEquals);
 
     static NO_EUQALS_ERROR: &str =
-        "error: Equal sign is needed when assigning values to '--config=<config>'.
+        "error: Equal sign is needed when assigning values to '--config=<config>'
 
 Usage: config [OPTIONS]
 
diff --git a/tests/builder/opts.rs b/tests/builder/opts.rs
index cccd1146..f149528c 100644
--- a/tests/builder/opts.rs
+++ b/tests/builder/opts.rs
@@ -21,8 +21,7 @@ fn require_equals_fail() {
 #[test]
 #[cfg(feature = "error-context")]
 fn require_equals_fail_message() {
-    static NO_EQUALS: &str =
-        "error: Equal sign is needed when assigning values to '--config=<cfg>'.
+    static NO_EQUALS: &str = "error: Equal sign is needed when assigning values to '--config=<cfg>'
 
 Usage: prog [OPTIONS]