diff --git a/cmd/multibuild/multibuild.go b/cmd/multibuild/multibuild.go index 6fc5458..0e0aa75 100644 --- a/cmd/multibuild/multibuild.go +++ b/cmd/multibuild/multibuild.go @@ -62,15 +62,15 @@ func targetList() ([]target, error) { // Returns the binary name/path that `go build` would produce. func determineTargetName(args []string) (string, error) { - for i := 0; i < len(args); i++ { + for i := range args { arg := args[i] if arg == "-o" && i+1 < len(args) { return args[i+1], nil } - if strings.HasPrefix(arg, "-o=") { - return strings.TrimPrefix(arg, "-o="), nil + if after, ok := strings.CutPrefix(arg, "-o="); ok { + return after, nil } } @@ -99,7 +99,7 @@ func determineTargetName(args []string) (string, error) { } func displayUsageAndExit(self string) { - fmt.Fprintln(os.Stderr, fmt.Sprintf("usage: %s [-o output] [build flags] [packages]", self)) + fmt.Fprintf(os.Stderr, "usage: %s [-o output] [build flags] [packages]\n", self) fmt.Fprintln(os.Stderr, "multibuild is a thin wrapper around 'go build'.") fmt.Fprintln(os.Stderr, "For documentation on multibuild's configuration, see https://github.com/rburchell/multibuild") fmt.Fprintln(os.Stderr, "Otherwise, run 'go help build' for command line flags.") diff --git a/cmd/multibuild/options.go b/cmd/multibuild/options.go index 18380e6..bfe0b10 100644 --- a/cmd/multibuild/options.go +++ b/cmd/multibuild/options.go @@ -9,6 +9,7 @@ import ( "io" "log" "os" + "slices" "strings" ) @@ -62,13 +63,7 @@ func (this options) buildTargetList(targets []target) ([]target, error) { // Check includes still present for _, inc := range this.Include { - found := false - for _, t := range targets { - if inc.matches(t) { - found = true - break - } - } + found := slices.ContainsFunc(targets, inc.matches) if !found { return nil, fmt.Errorf("multibuild: required target %q was not found, or was excluded", inc) } diff --git a/cmd/multibuild/options_test.go b/cmd/multibuild/options_test.go index 8d9749b..5f5ff87 100644 --- a/cmd/multibuild/options_test.go +++ b/cmd/multibuild/options_test.go @@ -5,6 +5,7 @@ package main import ( "os" + "slices" "strings" "testing" ) @@ -264,13 +265,7 @@ func TestScanBuildDir_ExcludeDefaultCGO(t *testing.T) { // Unset CGO_ENABLED os.Setenv("CGO_ENABLED", "0") opts, _ := scanBuildDir([]string{file}) - found := false - for _, x := range opts.Exclude { - if x == "android/*" { - found = true - break - } - } + found := slices.Contains(opts.Exclude, "android/*") if !found { t.Errorf("expected android/* to be excluded when CGO_ENABLED=0, got excludes %v", opts.Exclude) } diff --git a/cmd/multibuild/utils.go b/cmd/multibuild/utils.go index 8d95fa6..489aa43 100644 --- a/cmd/multibuild/utils.go +++ b/cmd/multibuild/utils.go @@ -8,7 +8,7 @@ import ( "os" ) -func fatal(format string, args ...interface{}) { +func fatal(format string, args ...any) { format += "\n" fmt.Fprintf(os.Stderr, format, args...) os.Exit(1)