Skip to content

Commit

Permalink
Attempt at adding a plugin sub-cmd
Browse files Browse the repository at this point in the history
Fixes: tektoncd#1039
Signed-off-by: Sunil Thaha <sthaha@redhat.com>
  • Loading branch information
sthaha committed Aug 20, 2020
1 parent 781f094 commit b239367
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions cmd/tkn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
package main

import (
"fmt"
"log"
"os"
"os/exec"
"syscall"

"github.com/tektoncd/cli/pkg/cli"
"github.com/tektoncd/cli/pkg/cmd"
Expand All @@ -26,7 +30,43 @@ func main() {
tp := &cli.TektonParams{}
tkn := cmd.Root(tp)

if err := tkn.Execute(); err != nil {
os.Exit(1)
args := os.Args[1:]
_, _, err := tkn.Find(args)

if err == nil {
if err := tkn.Execute(); err != nil {
os.Exit(1)
}
return
}

pluginCmd := "tkn-" + os.Args[1]

exCmd, err := exec.LookPath(pluginCmd)

if err != nil {
fmt.Fprintf(os.Stderr, `
============================================
looked for: %s
error:
%s
_____________________________________________
`, pluginCmd, err)

if err := tkn.Execute(); err != nil {
os.Exit(1)
}
}

fmt.Fprintf(os.Stderr, `
============================================
external binary: %s
error:
%s
_____________________________________________
`, exCmd, err)

errX := syscall.Exec(exCmd, append([]string{exCmd}, os.Args[2:]...), os.Environ())
log.Printf("Command finished with error: %v", errX)

}
Empty file added tmp/cli.log
Empty file.

0 comments on commit b239367

Please sign in to comment.