Skip to content

Commit

Permalink
add support for plugins
Browse files Browse the repository at this point in the history
Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed Jul 26, 2022
1 parent cd9238b commit 9899873
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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)
}
Expand Down

0 comments on commit 9899873

Please sign in to comment.