-
Notifications
You must be signed in to change notification settings - Fork 20
/
root.go
59 lines (48 loc) · 1.3 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
package cmd
import (
"fmt"
"github.com/curusarn/resh/internal/cfg"
"github.com/curusarn/resh/internal/logger"
"github.com/curusarn/resh/internal/output"
"github.com/spf13/cobra"
)
var version string
var commit string
// globals
var out *output.Output
var rootCmd = &cobra.Command{
Use: "reshctl",
Short: "Reshctl (RESH control) - check status, update",
}
// Execute reshctl
func Execute(ver, com, development string) {
version = ver
commit = com
config, errCfg := cfg.New()
logger, err := logger.New("reshctl", config.LogLevel, development)
if err != nil {
fmt.Printf("Error while creating logger: %v", err)
}
defer logger.Sync() // flushes buffer, if any
out = output.New(logger, "ERROR")
if errCfg != nil {
out.ErrorE("Error while getting configuration", errCfg)
}
var versionCmd = cobra.Command{
Use: "version",
Short: "show RESH version",
Run: versionCmdFunc(config),
}
rootCmd.AddCommand(&versionCmd)
doctorCmd := cobra.Command{
Use: "doctor",
Short: "check common problems",
Run: doctorCmdFunc(config),
}
rootCmd.AddCommand(&doctorCmd)
updateCmd.Flags().BoolVar(&betaFlag, "beta", false, "Update to latest version even if it's beta.")
rootCmd.AddCommand(updateCmd)
if err := rootCmd.Execute(); err != nil {
out.FatalE("Command ended with error", err)
}
}