-
Notifications
You must be signed in to change notification settings - Fork 130
/
enable.go
46 lines (39 loc) · 1.12 KB
/
enable.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
package telemetry
import (
"github.com/spf13/cobra"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/config"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/ui"
)
func NewEnableTelemetryCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "telemetry",
Short: "Enable collecting of anonymous telemetry data",
Run: func(cmd *cobra.Command, args []string) {
ui.NL()
ui.Print(ui.IconRocket + " Enabling telemetry on the testkube CLI")
cfg, err := config.Load()
if err == nil {
cfg.EnableAnalytics()
err = config.Save(cfg)
}
if err != nil {
ui.PrintDisabled("Telemetry on CLI", "failed")
ui.PrintConfigError(err)
} else {
ui.PrintEnabled("Telemetry on CLI", "enabled")
}
client, _ := common.GetClient(cmd)
_, err = client.UpdateConfig(testkube.Config{EnableTelemetry: true})
if err != nil {
ui.PrintDisabled("Telemetry on API", "failed")
ui.PrintConfigError(err)
} else {
ui.PrintEnabled("Telemetry on API", "enabled")
}
ui.NL()
},
}
return cmd
}