Skip to content

Commit

Permalink
Lookup plugins in current path
Browse files Browse the repository at this point in the history
If we can't find them in plugins dir look them up in the user path.

Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
  • Loading branch information
chmouel authored and tekton-robot committed May 12, 2021
1 parent 6fb3580 commit fea4e6a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cmd/tkn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"syscall"

Expand Down Expand Up @@ -44,10 +45,14 @@ func main() {
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting plugin folder: %v", err)
}
exCmd, err := findPlugin(pluginDir, pluginCmd)
exCmd, err := findBinaryPluginDir(pluginDir, pluginCmd)
if err != nil {
// Can't find the binary in PATH, bailing to usual execution
goto CoreTkn
// If we can't find the plugin in the plugin dir, try in the user
// PATH
exCmd, err = exec.LookPath(pluginCmd)
if err != nil {
goto CoreTkn
}
}

if err := syscall.Exec(exCmd, append([]string{exCmd}, os.Args[2:]...), os.Environ()); err != nil {
Expand Down Expand Up @@ -77,7 +82,8 @@ func getPluginDir() (string, error) {
return homedir.Expand(pluginDir)
}

func findPlugin(dir, cmd string) (string, error) {
// Find a binary in Plugin Directory
func findBinaryPluginDir(dir, cmd string) (string, error) {
path := filepath.Join(dir, cmd)
_, err := os.Stat(path)
if err == nil {
Expand Down

0 comments on commit fea4e6a

Please sign in to comment.