This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
root.go
61 lines (48 loc) · 1.53 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Package cmd implements the oasis-core-ledger tool.
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/oasisprotocol/oasis-core/go/common/logging"
cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
"github.com/oasisprotocol/oasis-core-ledger/common"
)
const cfgLogLevel = "log.level"
var (
rootCmd = &cobra.Command{
Use: "oasis-core-ledger",
Short: "Oasis Core Ledger Tool",
Version: common.SoftwareVersion,
}
rootFlags = flag.NewFlagSet("", flag.ContinueOnError)
)
// RootCommand returns the root (top level) cobra.Command.
func RootCommand() *cobra.Command {
return rootCmd
}
// Execute spawns the main entry point after handling the command line arguments.
func Execute() {
var logLevel logging.Level
if err := logLevel.Set(viper.GetString(cfgLogLevel)); err != nil {
cmdCommon.EarlyLogAndExit(fmt.Errorf("root: failed to set log level: %w", err))
}
if err := logging.Initialize(os.Stdout, logging.FmtLogfmt, logLevel, nil); err != nil {
cmdCommon.EarlyLogAndExit(fmt.Errorf("root: failed to initialize logging: %w", err))
}
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
func init() { // nolint: gochecknoinits
InitVersions(rootCmd)
logLevel := logging.LevelInfo
rootFlags.Var(&logLevel, cfgLogLevel, "log level")
_ = viper.BindPFlags(rootFlags)
rootCmd.PersistentFlags().AddFlagSet(rootFlags)
// Register all of the sub-commands.
rootCmd.AddCommand(listCmd)
rootCmd.AddCommand(showAddressCmd)
}