From b664a69bcb6eb674c9a77f076eff70cf7b868a18 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Thu, 2 Apr 2020 14:23:26 +0200 Subject: [PATCH 1/4] fix(plugin): Fix plugin lookup with file ext on Windows --- pkg/kn/commands/plugin/handler.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/kn/commands/plugin/handler.go b/pkg/kn/commands/plugin/handler.go index 7ee7c4eeb5..8fe10dfd5e 100644 --- a/pkg/kn/commands/plugin/handler.go +++ b/pkg/kn/commands/plugin/handler.go @@ -76,6 +76,16 @@ func (h *DefaultPluginHandler) Lookup(name string) (string, bool) { 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 + if _, err = os.Stat(pathWithExt); !os.IsNotExist(err) { + return pathWithExt, true + } + } + } + // No plugins found in pluginsDir, try in PATH of that's an option if h.LookupPluginsInPath { pluginPath, err = exec.LookPath(pluginPath) From d989b88c26b8e8570495f24bf5000192a98cfa27 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Thu, 2 Apr 2020 14:30:40 +0200 Subject: [PATCH 2/4] chore: Update changelog --- CHANGELOG.adoc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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%"] From 2d0a7bfda6998d749bbcd30c83b4930ec12ad67d Mon Sep 17 00:00:00 2001 From: David Simansky Date: Fri, 3 Apr 2020 13:26:23 +0200 Subject: [PATCH 3/4] fix: Reflect review feedback --- pkg/kn/commands/plugin/handler.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/kn/commands/plugin/handler.go b/pkg/kn/commands/plugin/handler.go index 8fe10dfd5e..609dcfe5a9 100644 --- a/pkg/kn/commands/plugin/handler.go +++ b/pkg/kn/commands/plugin/handler.go @@ -80,7 +80,8 @@ func (h *DefaultPluginHandler) Lookup(name string) (string, bool) { if runtime.GOOS == "windows" { for _, ext := range []string{".bat", ".cmd", ".com", ".exe", ".ps1"} { pathWithExt := pluginDirPluginPath + ext - if _, err = os.Stat(pathWithExt); !os.IsNotExist(err) { + _, err = os.Stat(pathWithExt) + if err == nil { return pathWithExt, true } } From 6d28d8e5e6147f315a437f0f0996bcbc4f8bb5f3 Mon Sep 17 00:00:00 2001 From: David Simansky Date: Fri, 3 Apr 2020 14:07:19 +0200 Subject: [PATCH 4/4] fix: Reflect review feedback and add future todo --- pkg/kn/commands/plugin/handler.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/kn/commands/plugin/handler.go b/pkg/kn/commands/plugin/handler.go index 609dcfe5a9..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,7 +73,7 @@ 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 }