Skip to content

Commit

Permalink
search plugin in workDir first
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rk committed Mar 26, 2024
1 parent 68dfe07 commit 685a68f
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions internal/util/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ func resolvePluginPath(pluginName string) (string, error) {

pluginExecutable := fmt.Sprintf("kafkactl-%s-plugin%s", pluginName, extension)

// search relative to working dir
workingDir, err := os.Getwd()
if err != nil {
return "", err
}

pluginPath := filepath.Join(workingDir, "../kafkactl-plugins/"+pluginName)
pluginLocationWorkingDir := filepath.Join(pluginPath, pluginExecutable)

if _, err = os.Stat(pluginLocationWorkingDir); err == nil {
return pluginLocationWorkingDir, nil
}

// search in path
if _, err := exec.LookPath(pluginExecutable); err == nil {
return pluginExecutable, nil
Expand All @@ -88,18 +101,5 @@ func resolvePluginPath(pluginName string) (string, error) {
return pluginLocationExe, nil
}

// search relative to working dir
workingDir, err := os.Getwd()
if err != nil {
return "", err
}

pluginPath := filepath.Join(workingDir, "../kafkactl-plugins/"+pluginName)
pluginLocationWorkingDir := filepath.Join(pluginPath, pluginExecutable)

if _, err = os.Stat(pluginLocationWorkingDir); err == nil {
return pluginLocationWorkingDir, nil
}

return "", errors.Wrapf(err, "plugin not found: %q", []string{pluginExecutable, pluginLocationExe, pluginLocationWorkingDir})
}

0 comments on commit 685a68f

Please sign in to comment.