nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: urfave/cli
Pull request #1705 (2023-03-18 14:28:55)

Add makezero linter
## What type of PR is this?

- cleanup

## What this PR does / why we need it:

Fixes copying of errors for multiErrors. I already mentioned this in #1697.

I don't think this actually has an impact on users, because the handleMultiError function will just drop nil errors.

I added a regression test, just in case.

## Which issue(s) this PR fixes:

Partially fixes: #1704

## Release Notes

```release-note
NONE
```



Patch:
diff --git a/.golangci.yaml b/.golangci.yaml
index 00f166a..a6e8c7e 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -1,4 +1,5 @@
 # https://golangci-lint.run/usage/configuration/
 linters:
   enable:
-    - misspell
\ No newline at end of file
+    - makezero
+    - misspell
diff --git a/errors.go b/errors.go
index a77144f..55b6b01 100644
--- a/errors.go
+++ b/errors.go
@@ -41,9 +41,7 @@ func (m *multiError) Error() string {
 // Errors returns a copy of the errors slice
 func (m *multiError) Errors() []error {
 	errs := make([]error, len(*m))
-	for _, err := range *m {
-		errs = append(errs, err)
-	}
+	copy(errs, *m)
 	return errs
 }
 


Test patch:
diff --git a/errors_test.go b/errors_test.go
index aea0a63..999a625 100644
--- a/errors_test.go
+++ b/errors_test.go
@@ -159,3 +159,13 @@ func TestHandleExitCoder_MultiErrorWithFormat(t *testing.T) {
 	expect(t, called, true)
 	expect(t, ErrWriter.(*bytes.Buffer).String(), "This the format: err1\nThis the format: err2\n")
 }
+
+func TestMultiErrorErrorsCopy(t *testing.T) {
+	errList := []error{
+		errors.New("foo"),
+		errors.New("bar"),
+		errors.New("baz"),
+	}
+	me := newMultiError(errList...)
+	expect(t, errList, me.Errors())
+}
Repository: urfave/cli
Pull request #1710 (2023-03-23 09:41:49)

Preserve separator spec on subcommands
## What type of PR is this?

- bug

## What this PR does / why we need it:

The separatorSpec is not passed along to the subcommands which means that SliceFlags on subcommands will not use the global separator settings. Extended the command to pass the separatorSpec along.

## Which issue(s) this PR fixes:

SliceFlags on sub commands will not use the global separator settings.

## Testing

Added test case to ensure this  change works as expected.

## Release Notes

```release-note
NONE
```



Patch:
diff --git a/command.go b/command.go
index f978b4a..69a0fdf 100644
--- a/command.go
+++ b/command.go
@@ -135,6 +135,7 @@ func (c *Command) setup(ctx *Context) {
 		if scmd.HelpName == "" {
 			scmd.HelpName = fmt.Sprintf("%s %s", c.HelpName, scmd.Name)
 		}
+		scmd.separator = c.separator
 		newCmds = append(newCmds, scmd)
 	}
 	c.Subcommands = newCmds


Test patch:
diff --git a/command_test.go b/command_test.go
index 53ca54b..d6e40c9 100644
--- a/command_test.go
+++ b/command_test.go
@@ -515,3 +515,30 @@ func TestCommand_RunSubcommandWithDefault(t *testing.T) {
 	err = app.Run([]string{"app"})
 	expect(t, err, errors.New("should not run this subcommand"))
 }
+
+func TestCommand_PreservesSeparatorOnSubcommands(t *testing.T) {
+	var values []string
+	subcommand := &Command{
+		Name: "bar",
+		Flags: []Flag{
+			&StringSliceFlag{Name: "my-flag"},
+		},
+		Action: func(c *Context) error {
+			values = c.StringSlice("my-flag")
+			return nil
+		},
+	}
+	app := &App{
+		Commands: []*Command{
+			{
+				Name:        "foo",
+				Subcommands: []*Command{subcommand},
+			},
+		},
+		SliceFlagSeparator: ";",
+	}
+
+	app.Run([]string{"app", "foo", "bar", "--my-flag", "1;2;3"})
+
+	expect(t, values, []string{"1", "2", "3"})
+}
Repository: urfave/cli
Pull request #1795 (2023-07-18 11:00:02)

Fix nil HelpFlag panic (v2)

## What type of PR is this?

Fix the panic when HelpFlag=nil

## Which issue(s) this PR fixes:

Fix  #1794




Patch:
diff --git a/help.go b/help.go
index 17530c8..e855a72 100644
--- a/help.go
+++ b/help.go
@@ -415,6 +415,9 @@ func checkVersion(cCtx *Context) bool {
 }
 
 func checkHelp(cCtx *Context) bool {
+	if HelpFlag == nil {
+		return false
+	}
 	found := false
 	for _, name := range HelpFlag.Names() {
 		if cCtx.Bool(name) {
@@ -426,24 +429,6 @@ func checkHelp(cCtx *Context) bool {
 	return found
 }
 
-func checkCommandHelp(c *Context, name string) bool {
-	if c.Bool("h") || c.Bool("help") {
-		_ = ShowCommandHelp(c, name)
-		return true
-	}
-
-	return false
-}
-
-func checkSubcommandHelp(cCtx *Context) bool {
-	if cCtx.Bool("h") || cCtx.Bool("help") {
-		_ = ShowSubcommandHelp(cCtx)
-		return true
-	}
-
-	return false
-}
-
 func checkShellCompleteFlag(a *App, arguments []string) (bool, []string) {
 	if !a.EnableBashCompletion {
 		return false, arguments
diff --git a/suggestions.go b/suggestions.go
index 87fa905..c73a001 100644
--- a/suggestions.go
+++ b/suggestions.go
@@ -21,7 +21,7 @@ func suggestFlag(flags []Flag, provided string, hideHelp bool) string {
 
 	for _, flag := range flags {
 		flagNames := flag.Names()
-		if !hideHelp {
+		if !hideHelp && HelpFlag != nil {
 			flagNames = append(flagNames, HelpFlag.Names()...)
 		}
 		for _, name := range flagNames {


Test patch:
diff --git a/help_test.go b/help_test.go
index 3cf9143..1188f85 100644
--- a/help_test.go
+++ b/help_test.go
@@ -101,6 +101,26 @@ func Test_Help_Custom_Flags(t *testing.T) {
 	}
 }
 
+func Test_Help_Nil_Flags(t *testing.T) {
+	oldFlag := HelpFlag
+	defer func() {
+		HelpFlag = oldFlag
+	}()
+	HelpFlag = nil
+
+	app := App{
+		Action: func(context *Context) error {
+			return nil
+		},
+	}
+	output := new(bytes.Buffer)
+	app.Writer = output
+	_ = app.Run([]string{"test"})
+	if output.Len() > 0 {
+		t.Errorf("unexpected output: %s", output.String())
+	}
+}
+
 func Test_Version_Custom_Flags(t *testing.T) {
 	oldFlag := VersionFlag
 	defer func() {
Repository: urfave/cli
Pull request #1796 (2023-07-18 12:00:46)

 Fix nil HelpFlag panic (v3)
## What type of PR is this?

Fix the panic when HelpFlag=nil

## Which issue(s) this PR fixes:

Fix  #1794




Patch:
diff --git a/command.go b/command.go
index b032239..991894e 100644
--- a/command.go
+++ b/command.go
@@ -527,6 +527,10 @@ func (cmd *Command) Run(ctx context.Context, osArgs []string) (deferErr error) {
 func (cmd *Command) checkHelp() bool {
 	tracef("checking if help is wanted (cmd=%[1]q)", cmd.Name)
 
+	if HelpFlag == nil {
+		return false
+	}
+
 	for _, name := range HelpFlag.Names() {
 		if cmd.Bool(name) {
 			return true
diff --git a/suggestions.go b/suggestions.go
index b078d87..607de09 100644
--- a/suggestions.go
+++ b/suggestions.go
@@ -31,7 +31,7 @@ func suggestFlag(flags []Flag, provided string, hideHelp bool) string {
 
 	for _, flag := range flags {
 		flagNames := flag.Names()
-		if !hideHelp {
+		if !hideHelp && HelpFlag != nil {
 			flagNames = append(flagNames, HelpFlag.Names()...)
 		}
 		for _, name := range flagNames {


Test patch:
diff --git a/help_test.go b/help_test.go
index d3bee34..1b387ea 100644
--- a/help_test.go
+++ b/help_test.go
@@ -95,6 +95,24 @@ func Test_Help_Custom_Flags(t *testing.T) {
 	require.Len(t, out.String(), 0)
 }
 
+func Test_Help_Nil_Flags(t *testing.T) {
+	oldFlag := HelpFlag
+	defer func() {
+		HelpFlag = oldFlag
+	}()
+	HelpFlag = nil
+
+	cmd := &Command{
+		Action: func(_ context.Context, cmd *Command) error {
+			return nil
+		},
+	}
+	out := new(bytes.Buffer)
+	cmd.Writer = out
+	_ = cmd.Run(buildTestContext(t), []string{"test"})
+	require.Len(t, out.String(), 0)
+}
+
 func Test_Version_Custom_Flags(t *testing.T) {
 	oldFlag := VersionFlag
 	defer func() {
Repository: urfave/cli
Pull request #1945 (2024-07-05 23:19:50)

Add File()
similar to EnvVar()

It's just a smal helper to make `NewValueSourceChain` more usefull :)


Patch:
diff --git a/godoc-current.txt b/godoc-current.txt
index 07bd07e..80d41e8 100644
--- a/godoc-current.txt
+++ b/godoc-current.txt
@@ -979,6 +979,8 @@ type ValueSource interface {
 
 func EnvVar(key string) ValueSource
 
+func File(path string) ValueSource
+
 type ValueSourceChain struct {
 	Chain []ValueSource
 }
diff --git a/value_source.go b/value_source.go
index 266f5e5..7d3f7ee 100644
--- a/value_source.go
+++ b/value_source.go
@@ -128,6 +128,10 @@ func (f *fileValueSource) GoString() string {
 	return fmt.Sprintf("&fileValueSource{Path:%[1]q}", f.Path)
 }
 
+func File(path string) ValueSource {
+	return &fileValueSource{Path: path}
+}
+
 // Files is a helper function to encapsulate a number of
 // fileValueSource together as a ValueSourceChain
 func Files(paths ...string) ValueSourceChain {


Test patch:
diff --git a/testdata/godoc-v3.x.txt b/testdata/godoc-v3.x.txt
index 07bd07e..80d41e8 100644
--- a/testdata/godoc-v3.x.txt
+++ b/testdata/godoc-v3.x.txt
@@ -979,6 +979,8 @@ type ValueSource interface {
 
 func EnvVar(key string) ValueSource
 
+func File(path string) ValueSource
+
 type ValueSourceChain struct {
 	Chain []ValueSource
 }
diff --git a/value_source_test.go b/value_source_test.go
index 57b9cfd..7f1c36e 100644
--- a/value_source_test.go
+++ b/value_source_test.go
@@ -71,7 +71,7 @@ func TestFileValueSource(t *testing.T) {
 		r.Implements((*ValueSource)(nil), &fileValueSource{})
 
 		t.Run("not found", func(t *testing.T) {
-			src := &fileValueSource{Path: fmt.Sprintf("junk_file_name-%[1]v", rand.Int())}
+			src := File(fmt.Sprintf("junk_file_name-%[1]v", rand.Int()))
 			_, ok := src.Lookup()
 			r.False(ok)
 		})
@@ -82,7 +82,7 @@ func TestFileValueSource(t *testing.T) {
 		r.Nil(os.WriteFile(fileName, []byte("pita"), 0o644))
 
 		t.Run("found", func(t *testing.T) {
-			src := &fileValueSource{Path: fileName}
+			src := File(fileName)
 			str, ok := src.Lookup()
 			r.True(ok)
 			r.Equal("pita", str)
@@ -90,7 +90,7 @@ func TestFileValueSource(t *testing.T) {
 	})
 
 	t.Run("implements fmt.Stringer", func(t *testing.T) {
-		src := &fileValueSource{Path: "/dev/null"}
+		src := File("/dev/null")
 		r := require.New(t)
 
 		r.Implements((*ValueSource)(nil), src)
@@ -98,7 +98,7 @@ func TestFileValueSource(t *testing.T) {
 	})
 
 	t.Run("implements fmt.GoStringer", func(t *testing.T) {
-		src := &fileValueSource{Path: "/dev/null"}
+		src := File("/dev/null")
 		r := require.New(t)
 
 		r.Implements((*ValueSource)(nil), src)