/
root.go
38 lines (31 loc) · 816 Bytes
/
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
package cmd
import (
"github.com/djcass44/go-utils/logging"
"github.com/spf13/cobra"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"os"
)
var command = &cobra.Command{
Use: "ayb",
Short: "build base images",
SilenceUsage: true,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
logLevel, _ := cmd.Flags().GetInt(flagLogLevel)
zc := zap.NewProductionConfig()
zc.Level = zap.NewAtomicLevelAt(zapcore.Level(logLevel * -1))
_, ctx := logging.NewZap(cmd.Context(), zc)
cmd.SetContext(ctx)
},
}
const flagLogLevel = "v"
func init() {
command.PersistentFlags().Int(flagLogLevel, 0, "log level. Higher is more")
command.AddCommand(buildCmd, lockCmd)
}
func Execute(version string) {
command.Version = version
if err := command.Execute(); err != nil {
os.Exit(1)
}
}