/
root.go
41 lines (31 loc) · 1.01 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
package cmd
import (
"os"
"github.com/1995parham/saf/internal/cmd/consumer"
"github.com/1995parham/saf/internal/cmd/producer"
"github.com/1995parham/saf/internal/config"
"github.com/1995parham/saf/internal/logger"
"github.com/1995parham/saf/internal/telemetry/trace"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
// ExitFailure status code.
const ExitFailure = 1
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
cfg := config.New()
logger := logger.New(cfg.Logger)
tracer := trace.New(cfg.Telemetry.Trace)
// nolint: exhaustivestruct
root := &cobra.Command{
Use: "saf",
Short: "Queue with NATS Jetstream to remove all the erlangs from cloud",
}
producer.Register(root, cfg, logger, tracer)
consumer.Register(root, cfg, logger, tracer)
if err := root.Execute(); err != nil {
logger.Error("failed to execute root command", zap.Error(err))
os.Exit(ExitFailure)
}
}