Skip to content

Commit

Permalink
Position cluster argument after commands to fix tab-completion kubect…
Browse files Browse the repository at this point in the history
…l call
  • Loading branch information
oldium committed Sep 8, 2022
1 parent 41c6f48 commit 8b23826
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cmd/minikube/cmd/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"os/exec"
"path"
"strings"
"syscall"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -96,9 +97,23 @@ host. Please be aware that when using --ssh all paths will apply to the remote m
os.Exit(1)
}

if len(args) > 1 && args[0] != "--help" {
cluster := []string{"--cluster", cname}
args = append(cluster, args...)
if len(args) > 0 {
var insertIndex int = 0
if args[0] == "__complete" {
// Treat __complete command as insertion point to allow code completion.
} else {
// Add cluster argument before first flag, but after all commands.
// This improves error message of kubectl in case the command is wrong.
insertIndex = len(args)
for i, arg := range args {
if strings.HasPrefix(arg, "-") {
insertIndex = i
break
}
}
}
clusterArg := "--cluster=" + cname
args = append(append(append([]string{}, args[:insertIndex]...), clusterArg), args[insertIndex:]...)
}

c, err := KubectlCommand(version, binaryMirror, args...)
Expand Down

0 comments on commit 8b23826

Please sign in to comment.