-
Notifications
You must be signed in to change notification settings - Fork 132
/
root.go
92 lines (73 loc) · 2.35 KB
/
root.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
package commands
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/config"
"github.com/kubeshop/testkube/pkg/analytics"
"github.com/kubeshop/testkube/pkg/ui"
)
var (
Commit string
Version string
BuiltBy string
Date string
analyticsEnabled bool
client string
verbose bool
namespace string
)
func init() {
// New commands
RootCmd.AddCommand(NewCreateCmd())
RootCmd.AddCommand(NewUpdateCmd())
RootCmd.AddCommand(NewGetCmd())
RootCmd.AddCommand(NewRunCmd())
RootCmd.AddCommand(NewDeleteCmd())
RootCmd.AddCommand(NewAbortCmd())
RootCmd.AddCommand(NewEnableCmd())
RootCmd.AddCommand(NewDisableCmd())
RootCmd.AddCommand(NewStatusCmd())
RootCmd.AddCommand(NewDownloadCmd())
RootCmd.AddCommand(NewGenerateCmd())
RootCmd.AddCommand(NewInstallCmd())
RootCmd.AddCommand(NewUpgradeCmd())
RootCmd.AddCommand(NewUninstallCmd())
RootCmd.AddCommand(NewWatchCmd())
RootCmd.AddCommand(NewDashboardCmd())
RootCmd.AddCommand(NewMigrateCmd())
RootCmd.AddCommand(NewVersionCmd())
RootCmd.AddCommand(NewConfigCmd())
}
var RootCmd = &cobra.Command{
Use: "kubectl-testkube",
Short: "Testkube entrypoint for kubectl plugin",
Run: func(cmd *cobra.Command, args []string) {
ui.Logo()
cmd.Usage()
cmd.DisableAutoGenTag = true
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
ui.Verbose = verbose
if analyticsEnabled {
ui.Debug("collecting anonymous analytics data, you can disable it by calling `kubectl testkube disable analytics`")
analytics.SendAnonymouscmdInfo()
}
},
}
func Execute() {
cfg, err := config.Load()
ui.WarnOnError("Config loading error", err)
defaultNamespace := "testkube"
if cfg.Namespace != "" {
defaultNamespace = cfg.Namespace
}
RootCmd.PersistentFlags().BoolVarP(&analyticsEnabled, "analytics-enabled", "", cfg.AnalyticsEnabled, "enable analytics")
RootCmd.PersistentFlags().StringVarP(&client, "client", "c", "proxy", "client used for connecting to Testkube API one of proxy|direct")
RootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "s", defaultNamespace, "Kubernetes namespace, default value read from config if set")
RootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "show additional debug messages")
if err := RootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}