-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
81 lines (66 loc) · 1.97 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
package main
import (
"os"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/ydb-platform/ydbops/cmd"
"github.com/ydb-platform/ydbops/pkg/client/auth/credentials"
"github.com/ydb-platform/ydbops/pkg/client/cms"
"github.com/ydb-platform/ydbops/pkg/client/connectionsfactory"
"github.com/ydb-platform/ydbops/pkg/client/discovery"
"github.com/ydb-platform/ydbops/pkg/cmdutil"
"github.com/ydb-platform/ydbops/pkg/command"
"github.com/ydb-platform/ydbops/pkg/options"
)
func createLogger(level string) (zap.AtomicLevel, *zap.Logger) {
atom, _ := zap.ParseAtomicLevel(level)
encoderCfg := zap.NewProductionEncoderConfig()
encoderCfg.EncodeTime = zapcore.ISO8601TimeEncoder
logger := zap.New(
zapcore.NewCore(
zapcore.NewConsoleEncoder(encoderCfg),
zapcore.Lock(os.Stdout),
atom,
),
)
_ = zap.ReplaceGlobals(logger)
return atom, logger
}
var (
factory cmdutil.Factory
baseOptions *command.BaseOptions
cmsClient cms.Client
discoveryClient discovery.Client
credentialsProvider credentials.Provider
)
func initFactory() {
factory = cmdutil.New(baseOptions, cmsClient, discoveryClient, credentialsProvider)
}
func initClients(
cf connectionsfactory.Factory,
logger *zap.SugaredLogger,
cp credentials.Provider,
) {
cmsClient = cms.NewCMSClient(cf, logger, cp)
discoveryClient = discovery.NewDiscoveryClient(cf, logger, cp)
}
func mainNoExit() error {
logLevelSetter, logger := createLogger("info")
baseOptions = &command.BaseOptions{}
root := cmd.NewRootCommand(logLevelSetter, logger.Sugar(), baseOptions)
cf := connectionsfactory.New(baseOptions)
options.Logger = logger.Sugar() // TODO(shmel1k@): tmp hack
credentialsProvider = credentials.New(baseOptions, cf, logger.Sugar(), nil)
initClients(cf, logger.Sugar(), credentialsProvider)
initFactory()
defer func() {
_ = logger.Sync()
}()
cmd.InitRootCommandTree(root, factory)
return root.Execute()
}
func main() {
if err := mainNoExit(); err != nil {
os.Exit(1)
}
}