Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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%"]
Expand Down
14 changes: 13 additions & 1 deletion pkg/kn/commands/plugin/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsimansk while we are at it, could you please also adapt the three lines above (just to be consistent) and add a comment that we should strive for a more sophisticated error handling in the future ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do.

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)
Expand Down