Merge pull request #73469 from dany74q/patch-1

Added windows executable extensions to Kubectl plugins
This commit is contained in:
Kubernetes Prow Robot 2019-01-30 14:28:54 -08:00 committed by GitHub
commit a780dd78d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 13 deletions

View File

@ -22,7 +22,6 @@ import (
"io" "io"
"os" "os"
"os/exec" "os/exec"
"runtime"
"strings" "strings"
"syscall" "syscall"
@ -339,12 +338,6 @@ type defaultPluginHandler struct{}
// Lookup implements PluginHandler // Lookup implements PluginHandler
func (h *defaultPluginHandler) Lookup(filename string) (string, error) { func (h *defaultPluginHandler) Lookup(filename string) (string, error) {
// if on Windows, append the "exe" extension
// to the filename that we are looking up.
if runtime.GOOS == "windows" {
filename = filename + ".exe"
}
return exec.LookPath(filename) return exec.LookPath(filename)
} }

View File

@ -100,11 +100,7 @@ func (o *PluginListOptions) Complete(cmd *cobra.Command) error {
seenPlugins: make(map[string]string, 0), seenPlugins: make(map[string]string, 0),
} }
path := "PATH" o.PluginPaths = filepath.SplitList(os.Getenv("PATH"))
if runtime.GOOS == "windows" {
path = "path"
}
o.PluginPaths = filepath.SplitList(os.Getenv(path))
return nil return nil
} }
@ -230,7 +226,10 @@ func isExecutable(fullPath string) (bool, error) {
} }
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
if strings.HasSuffix(info.Name(), ".exe") { fileExt := strings.ToLower(filepath.Ext(fullPath))
switch fileExt {
case ".bat", ".cmd", ".com", ".exe":
return true, nil return true, nil
} }
return false, nil return false, nil