-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (79 loc) · 2.43 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
package main
import (
_ "embed"
"fmt"
"log/slog"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/x-ethr/ethr-cli/internal/commands"
"github.com/x-ethr/ethr-cli/internal/constants"
"github.com/x-ethr/ethr-cli/internal/log"
"github.com/x-ethr/ethr-cli/internal/types/level"
)
var version string = "0.0.0" // see go linking for compile-time variable overwrites
// logging is a variable that represents the current log level configuration.
var (
logging level.Type = level.Error
)
func main() {
var root = &cobra.Command{
Use: constants.Name(),
Short: fmt.Sprintf("%s - A Development, Deployment & CI Utilities CLI", constants.Name()),
Long: fmt.Sprintf("%s is a tool that facilitates management of manifests, wraps CI capabilities relating to kubernetes, and overall provides local development assistance.", constants.Name()),
Example: "",
ValidArgs: nil,
ValidArgsFunction: nil,
Args: nil,
ArgAliases: nil,
BashCompletionFunction: "",
Deprecated: "",
Annotations: nil,
Version: version,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
var l level.Type
if e := l.Set(logging.String()); e != nil {
return e
} else {
log.Default(l.String())
}
slog.Log(ctx, log.Trace, "Root", slog.Group("command",
slog.String("name", cmd.Name()),
slog.String("version", version),
slog.Group("flags",
slog.String("log-level", logging.String()),
),
slog.Group("environment",
slog.String("LOG_LEVEL", os.Getenv("LOG_LEVEL")),
),
))
return nil
},
PreRun: func(cmd *cobra.Command, args []string) {
// @todo Logic to check if a newer version is available
},
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
if e := cmd.Help(); e != nil {
panic(e)
}
}
},
PostRun: nil,
CompletionOptions: cobra.CompletionOptions{},
TraverseChildren: true,
Hidden: false,
SilenceErrors: false,
SilenceUsage: false,
}
root.PersistentFlags().VarP(&logging, "verbosity", "v", "sets and configures logging verbosity")
commands.Execute(root)
}
func init() {
version = strings.TrimSpace(version)
if e := os.Setenv("VERSION", version); e != nil {
exception := fmt.Errorf("unable to set VERSION: %w", e)
panic(exception)
}
}