Repository: bazelbuild/bazelisk
Pull request #363 (2022-09-10 13:50:50)

Fix spelling
Fix minor spelling mistakes


Patch:
diff --git a/core/core.go b/core/core.go
index e9e0743..6241a7c 100644
--- a/core/core.go
+++ b/core/core.go
@@ -110,7 +110,7 @@ func RunBazeliskWithArgsFunc(argsFunc ArgsFunc, repos *Repositories) (int, error
 		baseDirectory := filepath.Join(bazeliskHome, "local")
 		bazelPath, err = linkLocalBazel(baseDirectory, bazelPath)
 		if err != nil {
-			return -1, fmt.Errorf("cound not link local Bazel: %v", err)
+			return -1, fmt.Errorf("could not link local Bazel: %v", err)
 		}
 	}
 
@@ -403,7 +403,7 @@ func linkLocalBazel(baseDirectory string, bazelPath string) (string, error) {
 		if err != nil {
 			err = copyFile(bazelPath, destinationPath, 0755)
 			if err != nil {
-				return "", fmt.Errorf("cound not copy file from %s to %s: %v", bazelPath, destinationPath, err)
+				return "", fmt.Errorf("could not copy file from %s to %s: %v", bazelPath, destinationPath, err)
 			}
 		}
 	}
@@ -537,14 +537,50 @@ func insertArgs(baseArgs []string, newArgs []string) []string {
 	return result
 }
 
-func shutdownIfNeeded(bazelPath string) {
+func parseStartupOptions(baseArgs []string) []string {
+	var result []string
+	var BAZEL_COMMANDS = map[string]bool{
+		"analyze-profile": true,
+		"aquery": true,
+		"build": true,
+		"canonicalize-flags": true,
+		"clean": true,
+		"coverage": true,
+		"cquery": true,
+		"dump": true,
+		"fetch": true,
+		"help": true,
+		"info": true,
+		"license": true,
+		"mobile-install": true,
+		"mod": true,
+		"print_action": true,
+		"query": true,
+		"run": true,
+		"shutdown": true,
+		"sync": true,
+		"test": true,
+		"version": true,
+	}
+	// Arguments before a Bazel command are startup options.
+	for _, arg := range baseArgs {
+		if _, ok := BAZEL_COMMANDS[arg]; ok {
+			return result
+		}
+		result = append(result, arg)
+	}
+	return result
+}
+
+func shutdownIfNeeded(bazelPath string, startupOptions []string) {
 	bazeliskClean := GetEnvOrConfig("BAZELISK_SHUTDOWN")
 	if len(bazeliskClean) == 0 {
 		return
 	}
 
-	fmt.Printf("bazel shutdown\n")
-	exitCode, err := runBazel(bazelPath, []string{"shutdown"}, nil)
+	args := append(startupOptions, "shutdown")
+	fmt.Printf("bazel %s\n", strings.Join(args, " "))
+	exitCode, err := runBazel(bazelPath, args, nil)
 	fmt.Printf("\n")
 	if err != nil {
 		log.Fatalf("failed to run bazel shutdown: %v", err)
@@ -555,14 +591,15 @@ func shutdownIfNeeded(bazelPath string) {
 	}
 }
 
-func cleanIfNeeded(bazelPath string) {
+func cleanIfNeeded(bazelPath string, startupOptions []string) {
 	bazeliskClean := GetEnvOrConfig("BAZELISK_CLEAN")
 	if len(bazeliskClean) == 0 {
 		return
 	}
 
-	fmt.Printf("bazel clean --expunge\n")
-	exitCode, err := runBazel(bazelPath, []string{"clean", "--expunge"}, nil)
+	args := append(startupOptions, "clean", "--expunge")
+	fmt.Printf("bazel %s\n", strings.Join(args, " "))
+	exitCode, err := runBazel(bazelPath, args, nil)
 	fmt.Printf("\n")
 	if err != nil {
 		log.Fatalf("failed to run clean: %v", err)
@@ -575,11 +612,13 @@ func cleanIfNeeded(bazelPath string) {
 
 // migrate will run Bazel with each flag separately and report which ones are failing.
 func migrate(bazelPath string, baseArgs []string, flags []string) {
+	var startupOptions = parseStartupOptions(baseArgs)
+
 	// 1. Try with all the flags.
 	args := insertArgs(baseArgs, flags)
 	fmt.Printf("\n\n--- Running Bazel with all incompatible flags\n\n")
-	shutdownIfNeeded(bazelPath)
-	cleanIfNeeded(bazelPath)
+	shutdownIfNeeded(bazelPath, startupOptions)
+	cleanIfNeeded(bazelPath, startupOptions)
 	fmt.Printf("bazel %s\n", strings.Join(args, " "))
 	exitCode, err := runBazel(bazelPath, args, nil)
 	if err != nil {
@@ -593,8 +632,8 @@ func migrate(bazelPath string, baseArgs []string, flags []string) {
 	// 2. Try with no flags, as a sanity check.
 	args = baseArgs
 	fmt.Printf("\n\n--- Running Bazel with no incompatible flags\n\n")
-	shutdownIfNeeded(bazelPath)
-	cleanIfNeeded(bazelPath)
+	shutdownIfNeeded(bazelPath, startupOptions)
+	cleanIfNeeded(bazelPath, startupOptions)
 	fmt.Printf("bazel %s\n", strings.Join(args, " "))
 	exitCode, err = runBazel(bazelPath, args, nil)
 	if err != nil {
@@ -611,8 +650,8 @@ func migrate(bazelPath string, baseArgs []string, flags []string) {
 	for _, arg := range flags {
 		args = insertArgs(baseArgs, []string{arg})
 		fmt.Printf("\n\n--- Running Bazel with %s\n\n", arg)
-		shutdownIfNeeded(bazelPath)
-		cleanIfNeeded(bazelPath)
+		shutdownIfNeeded(bazelPath, startupOptions)
+		cleanIfNeeded(bazelPath, startupOptions)
 		fmt.Printf("bazel %s\n", strings.Join(args, " "))
 		exitCode, err = runBazel(bazelPath, args, nil)
 		if err != nil {
diff --git a/platforms/platforms.go b/platforms/platforms.go
index 93333e3..9cf38db 100644
--- a/platforms/platforms.go
+++ b/platforms/platforms.go
@@ -1,4 +1,4 @@
-// Package platforms determins file names and extensions based on the current operating system.
+// Package platforms determines file names and extensions based on the current operating system.
 package platforms
 
 import (
diff --git a/repositories/github.go b/repositories/github.go
index b75edcd..f03fd6a 100644
--- a/repositories/github.go
+++ b/repositories/github.go
@@ -54,7 +54,7 @@ func (gh *GitHubRepo) getFilteredVersions(bazeliskHome, bazelFork string, wantPr
 	url := fmt.Sprintf("https://api.github.com/repos/%s/bazel/releases", bazelFork)
 	releasesJSON, err := httputil.MaybeDownload(bazeliskHome, url, bazelFork+"-releases.json", "list of Bazel releases from github.com/"+bazelFork, fmt.Sprintf("token %s", gh.token), merger)
 	if err != nil {
-		return []string{}, fmt.Errorf("unable to dermine '%s' releases: %v", bazelFork, err)
+		return []string{}, fmt.Errorf("unable to determine '%s' releases: %v", bazelFork, err)
 	}
 
 	if len(releases) == 0 {


Test patch:
diff --git a/bazelisk_version_test.go b/bazelisk_version_test.go
index 7e41b96..e542372 100644
--- a/bazelisk_version_test.go
+++ b/bazelisk_version_test.go
@@ -201,7 +201,7 @@ func TestResolveLatestVersion_GitHubIsDown(t *testing.T) {
 	if err == nil {
 		t.Fatal("Expected resolveLatestVersion() to fail.")
 	}
-	expectedPrefix := "unable to determine latest version: unable to dermine 'some_fork' releases: could not download list of Bazel releases from github.com/some_fork"
+	expectedPrefix := "unable to determine latest version: unable to determine 'some_fork' releases: could not download list of Bazel releases from github.com/some_fork"
 	if !strings.HasPrefix(err.Error(), expectedPrefix) {
 		t.Fatalf("Expected error message that starts with %q, but got '%v'", expectedPrefix, err)
 	}