-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
106 lines (95 loc) · 3.27 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"os"
"syscall"
magcli "github.com/openshift-pipelines/manual-approval-gate/pkg/cli"
magcmd "github.com/openshift-pipelines/manual-approval-gate/pkg/cli/cmd"
opccli "github.com/openshift-pipelines/opc/pkg"
paccli "github.com/openshift-pipelines/pipelines-as-code/pkg/cli"
"github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/tknpac"
pacversion "github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/tknpac/version"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
"github.com/spf13/cobra"
tkncli "github.com/tektoncd/cli/pkg/cli"
"github.com/tektoncd/cli/pkg/cmd"
tknversion "github.com/tektoncd/cli/pkg/cmd/version"
"github.com/tektoncd/cli/pkg/plugins"
resultscmd "github.com/tektoncd/results/pkg/cli/cmd"
)
const (
pacLongDesc = `Manage your Pipelines as Code installation and resources
See https://pipelinesascode.com for more details`
pacShortdesc = "CLI to interact with Pipelines as Code resources"
tknShortDesc = "CLI to interact with Openshift Pipelines resources"
resultsShortDesc = "CLI to interact with Tekton Results API."
magShortDesc = "CLI to interact with Manual Approval Gate."
binaryName = `opc`
)
func main() {
tp := &tkncli.TektonParams{}
tkn := cmd.Root(tp)
tkn.Use = binaryName
tkn.Short = tknShortDesc
clients := params.New()
pac := tknpac.Root(clients)
pac.Use = "pac"
pac.Short = pacShortdesc
pac.Long = pacLongDesc
tkn.AddCommand(pac)
// adding manual approval gate cli
p := &magcli.ApprovalTaskParams{}
mag := magcmd.Root(p)
mag.Use = "approvaltask"
mag.Short = magShortDesc
tkn.AddCommand(mag)
// adding results
results := resultscmd.Root()
results.Use = "results"
results.Short = resultsShortDesc
tkn.AddCommand(results)
pluginList := plugins.GetAllTknPluginFromPaths()
newPluginList := []string{}
// remove pac from the plugin list
for _, value := range pluginList {
if value != "pac" {
newPluginList = append(newPluginList, value)
}
}
cobra.AddTemplateFunc("pluginList", func() []string { return newPluginList })
paciostreams := paccli.NewIOStreams()
tkn.RemoveCommand(pacversion.Command(paciostreams)) // does not work 🤷🏽♂️, we do the hard way later on
tkn.RemoveCommand(tknversion.Command(tp))
tkn.AddCommand(opccli.VersionCommand(paciostreams))
args := os.Args[1:]
var cmd *cobra.Command
if len(args) > 0 && args[0] == "version" {
cmd = opccli.VersionCommand(paciostreams)
goto CoreTkn
}
if len(args) > 1 && args[0] == "pac" && args[1] == "version" {
// Arthur: "I've Got Nothing Left To Lose. Nothing Can Hurt Me Anymore. My Life Is Nothing But A Comedy." 🃏
os.Args = []string{"version"}
vcmd := opccli.VersionCommand(paciostreams)
_ = vcmd.Execute()
os.Exit(0)
}
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 := cmd.Execute(); err != nil {
os.Exit(1)
}
}