-
Notifications
You must be signed in to change notification settings - Fork 109
/
root.go
92 lines (80 loc) · 2.68 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
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
// Package cmd implements the commands for the oasis-node executable.
package cmd
import (
"os"
"syscall"
"github.com/spf13/cobra"
"github.com/oasisprotocol/oasis-core/go/common/version"
cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/consensus"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/control"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/debug"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/genesis"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/governance"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/ias"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/identity"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/keymanager"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/node"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/registry"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/signer"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/stake"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/storage"
)
var rootCmd = &cobra.Command{
Use: "oasis-node",
Short: "Oasis Node",
Version: version.SoftwareVersion,
Run: node.Run,
}
// RootCommand returns the root (top level) cobra.Command.
func RootCommand() *cobra.Command {
return rootCmd
}
// Execute spawns the main entry point after handling the config file
// and command line arguments.
func Execute() {
// Only the owner should have read/write/execute permissions for
// anything created by the oasis-node binary.
syscall.Umask(0o077)
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}
func initVersions() {
cobra.AddTemplateFunc("nodeVersion", func() interface{} { return version.Versions })
cobra.AddTemplateFunc("toolchain", func() interface{} { return version.Toolchain })
rootCmd.SetVersionTemplate(`Software version: {{.Version}}
{{- with nodeVersion }}
Consensus:
Consensus protocol version: {{ .ConsensusProtocol }}
Runtime:
Host protocol version: {{ .RuntimeHostProtocol }}
Committee protocol version: {{ .RuntimeCommitteeProtocol }}
{{ end -}}
Go toolchain version: {{ toolchain }}
`)
}
func init() {
cobra.OnInitialize(cmdCommon.InitConfig)
initVersions()
rootCmd.PersistentFlags().AddFlagSet(cmdCommon.RootFlags)
rootCmd.Flags().AddFlagSet(node.Flags)
// Register all of the sub-commands.
for _, v := range []func(*cobra.Command){
control.Register,
debug.Register,
genesis.Register,
governance.Register,
ias.Register,
identity.Register,
keymanager.Register,
registry.Register,
signer.Register,
stake.Register,
storage.Register,
consensus.Register,
node.Register,
} {
v(rootCmd)
}
}