Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should exit with the sub process exit code shouldn't we ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

absolutely!

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