diff --git a/main.go b/main.go index 34572e98e..7bbfb4f72 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,15 @@ package main import ( + "fmt" "os" + "syscall" "github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/tknpac" "github.com/openshift-pipelines/pipelines-as-code/pkg/params" "github.com/tektoncd/cli/pkg/cli" "github.com/tektoncd/cli/pkg/cmd" + "github.com/tektoncd/cli/pkg/plugins" ) const ( @@ -27,6 +30,24 @@ func main() { pac.Long = pacLongDesc tkn.AddCommand(pac) + args := os.Args[1:] + cmd, _, _ := tkn.Find(args) + if cmd != nil && cmd == tkn && len(args) > 0 { + exCmd, err := plugins.FindPlugin(os.Args[1]) + // if we can't find command then execute the normal tkn command. + if err != nil { + goto CoreTkn + } + + // if we have found the plugin then sysexec it by replacing current process. + if err := syscall.Exec(exCmd, append([]string{exCmd}, os.Args[2:]...), os.Environ()); err != nil { + fmt.Fprintf(os.Stderr, "Command finished with error: %v", err) + os.Exit(127) + } + return + } + +CoreTkn: if err := tkn.Execute(); err != nil { os.Exit(1) }