mirror of https://github.com/k3s-io/k3s
Added windows executable extensions to Kubectl plugins
Currently, the kubectl plugins system - when running under Windows - will determine that a plugin is executable by looking at its extension, comparing it to '.exe'. I think we should allow plugins w/ a few more known extensions (.bat, .com, .cmd; for example) - This would give more of a similar experience to plugins under *nix, where shell scripts are often used. Moreover, there were two windows-specific behaviors that were redundant, which I've removed: 1. In plugin.go - There's no need to differentiate between windows and under OS-es when looking at the PATH variable; It can be refered as 'PATH' in Windows as well 2. In cmd.go - There's no need to append a suffix when looking up plugins on windows; One can safely use 'exec.LookPath' without a suffix on Windows - and get automatic resolving for known executable typespull/564/head
parent
3fbdc8c327
commit
aae1944a07
|
@ -22,7 +22,6 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
|
@ -339,12 +338,6 @@ type defaultPluginHandler struct{}
|
|||
|
||||
// Lookup implements PluginHandler
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -100,11 +100,7 @@ func (o *PluginListOptions) Complete(cmd *cobra.Command) error {
|
|||
seenPlugins: make(map[string]string, 0),
|
||||
}
|
||||
|
||||
path := "PATH"
|
||||
if runtime.GOOS == "windows" {
|
||||
path = "path"
|
||||
}
|
||||
o.PluginPaths = filepath.SplitList(os.Getenv(path))
|
||||
o.PluginPaths = filepath.SplitList(os.Getenv("PATH"))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -230,7 +226,10 @@ func isExecutable(fullPath string) (bool, error) {
|
|||
}
|
||||
|
||||
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 false, nil
|
||||
|
|
Loading…
Reference in New Issue