diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index babe9b32aa..298a26f3be 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -17,12 +17,17 @@ [cols="1,10,3", options="header", width="100%"] |=== | | Description | PR -|=== | 🐣 | Refactor `e2e` common code into `lib/test` | https://github.com/knative/client/pull/765[#765] +| 🐛 +| Fix plugin lookup with file ext on Windows +| https://github.com/knative/client/pull/774[#774] + +|=== + ## v0.13.1 (2020-03-25) [cols="1,10,3", options="header", width="100%"] diff --git a/pkg/kn/commands/plugin/handler.go b/pkg/kn/commands/plugin/handler.go index 7ee7c4eeb5..5f8b86a065 100644 --- a/pkg/kn/commands/plugin/handler.go +++ b/pkg/kn/commands/plugin/handler.go @@ -60,6 +60,7 @@ func NewDefaultPluginHandler(validPrefixes []string, pluginsDir string, lookupPl } // Lookup implements PluginHandler +// TODO: The current error handling is not optimal, and some errors may be lost. We should refactor the code in the future. func (h *DefaultPluginHandler) Lookup(name string) (string, bool) { for _, prefix := range h.ValidPrefixes { pluginPath := fmt.Sprintf("%s-%s", prefix, name) @@ -72,10 +73,21 @@ func (h *DefaultPluginHandler) Lookup(name string) (string, bool) { pluginDirPluginPath := filepath.Join(pluginDir, pluginPath) _, err = os.Stat(pluginDirPluginPath) - if !os.IsNotExist(err) { + if err == nil { return pluginDirPluginPath, true } + // Try to match well-known file extensions on Windows + if runtime.GOOS == "windows" { + for _, ext := range []string{".bat", ".cmd", ".com", ".exe", ".ps1"} { + pathWithExt := pluginDirPluginPath + ext + _, err = os.Stat(pathWithExt) + if err == nil { + return pathWithExt, true + } + } + } + // No plugins found in pluginsDir, try in PATH of that's an option if h.LookupPluginsInPath { pluginPath, err = exec.LookPath(pluginPath)