Skip to content

Commit 959c458

Browse files
stuarthicksrburchell
authored andcommitted
style: misc linter-suggested simplifications
1 parent eb34c71 commit 959c458

4 files changed

Lines changed: 9 additions & 19 deletions

File tree

cmd/multibuild/multibuild.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ func targetList() ([]target, error) {
6262

6363
// Returns the binary name/path that `go build` would produce.
6464
func determineTargetName(args []string) (string, error) {
65-
for i := 0; i < len(args); i++ {
65+
for i := range args {
6666
arg := args[i]
6767

6868
if arg == "-o" && i+1 < len(args) {
6969
return args[i+1], nil
7070
}
7171

72-
if strings.HasPrefix(arg, "-o=") {
73-
return strings.TrimPrefix(arg, "-o="), nil
72+
if after, ok := strings.CutPrefix(arg, "-o="); ok {
73+
return after, nil
7474
}
7575
}
7676

@@ -99,7 +99,7 @@ func determineTargetName(args []string) (string, error) {
9999
}
100100

101101
func displayUsageAndExit(self string) {
102-
fmt.Fprintln(os.Stderr, fmt.Sprintf("usage: %s [-o output] [build flags] [packages]", self))
102+
fmt.Fprintf(os.Stderr, "usage: %s [-o output] [build flags] [packages]\n", self)
103103
fmt.Fprintln(os.Stderr, "multibuild is a thin wrapper around 'go build'.")
104104
fmt.Fprintln(os.Stderr, "For documentation on multibuild's configuration, see https://github.com/rburchell/multibuild")
105105
fmt.Fprintln(os.Stderr, "Otherwise, run 'go help build' for command line flags.")

cmd/multibuild/options.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io"
1010
"log"
1111
"os"
12+
"slices"
1213
"strings"
1314
)
1415

@@ -62,13 +63,7 @@ func (this options) buildTargetList(targets []target) ([]target, error) {
6263

6364
// Check includes still present
6465
for _, inc := range this.Include {
65-
found := false
66-
for _, t := range targets {
67-
if inc.matches(t) {
68-
found = true
69-
break
70-
}
71-
}
66+
found := slices.ContainsFunc(targets, inc.matches)
7267
if !found {
7368
return nil, fmt.Errorf("multibuild: required target %q was not found, or was excluded", inc)
7469
}

cmd/multibuild/options_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package main
55

66
import (
77
"os"
8+
"slices"
89
"strings"
910
"testing"
1011
)
@@ -264,13 +265,7 @@ func TestScanBuildDir_ExcludeDefaultCGO(t *testing.T) {
264265
// Unset CGO_ENABLED
265266
os.Setenv("CGO_ENABLED", "0")
266267
opts, _ := scanBuildDir([]string{file})
267-
found := false
268-
for _, x := range opts.Exclude {
269-
if x == "android/*" {
270-
found = true
271-
break
272-
}
273-
}
268+
found := slices.Contains(opts.Exclude, "android/*")
274269
if !found {
275270
t.Errorf("expected android/* to be excluded when CGO_ENABLED=0, got excludes %v", opts.Exclude)
276271
}

cmd/multibuild/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"os"
99
)
1010

11-
func fatal(format string, args ...interface{}) {
11+
func fatal(format string, args ...any) {
1212
format += "\n"
1313
fmt.Fprintf(os.Stderr, format, args...)
1414
os.Exit(1)

0 commit comments

Comments
 (0)