-
Notifications
You must be signed in to change notification settings - Fork 56
/
main.go
101 lines (88 loc) · 2.13 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
package main
import (
"errors"
"fmt"
"os"
"strings"
"github.com/go-clix/cli"
"github.com/grafana/grizzly/pkg/config"
"github.com/grafana/grizzly/pkg/grafana"
"github.com/grafana/grizzly/pkg/grizzly"
"github.com/grafana/grizzly/pkg/grizzly/notifier"
"github.com/grafana/grizzly/pkg/mimir"
"github.com/grafana/grizzly/pkg/syntheticmonitoring"
log "github.com/sirupsen/logrus"
)
// Version is the current version of the grr command.
// To be overwritten at build time
var Version = "dev"
type silentError struct {
Err error
}
func (err silentError) Is(target error) bool {
var e silentError
return errors.As(target, &e)
}
func (err silentError) Error() string {
return err.Err.Error()
}
func main() {
rootCmd := &cli.Command{
Use: "grr",
Short: "Grizzly",
Version: Version,
}
config.Initialise()
err := config.Read()
if err != nil {
log.Fatalln(err)
}
context, err := config.CurrentContext()
if err != nil {
log.Fatalln(err)
}
registry := createRegistry(context)
// workflow commands
rootCmd.AddCommand(
getCmd(registry),
listCmd(registry),
pullCmd(registry),
showCmd(registry),
diffCmd(registry),
applyCmd(registry),
watchCmd(registry),
exportCmd(registry),
snapshotCmd(registry),
providersCmd(registry),
configCmd(),
serveCmd(registry),
selfUpdateCmd(),
)
// Run!
if err = rootCmd.Execute(); err != nil {
if errors.Is(err, silentError{}) {
log.Debugf("Silent error: %s", err)
os.Exit(1)
} else {
log.Fatalln(err)
}
}
}
func createRegistry(context *config.Context) grizzly.Registry {
providers := []grizzly.Provider{
grafana.NewProvider(&context.Grafana),
mimir.NewProvider(&context.Mimir),
syntheticmonitoring.NewProvider(&context.SyntheticMonitoring),
}
var providerList []string
for _, provider := range providers {
err := provider.Validate()
if err != nil {
providerList = append(providerList, fmt.Sprintf("%s - inactive (%s)", provider.Name(), err.Error()))
} else {
providerList = append(providerList, provider.Name()+" - active")
}
}
notifier.InfoStderr(nil, "Providers: "+strings.Join(providerList, ", "))
return grizzly.NewRegistry(providers)
}