-
Notifications
You must be signed in to change notification settings - Fork 1
/
root.go
48 lines (41 loc) · 1.17 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
package cliqmstr
import (
"io/ioutil"
golog "log" // avoid having "log" in the namespace
"os"
"github.com/spf13/cobra"
)
var (
// Enable verbose log output using the Debug logger
verbose bool
// Debug receives log messages in verbose mode
Debug *golog.Logger
// Log is the standard logger
Log *golog.Logger
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "qmstr",
Short: "qmstr performs Quartermaster client-side operations",
Long: `qmstr performs Quartermaster operations that have only client-side effects.
It does not require a QMSTR master to be available.`,
}
func init() {
cobra.OnInitialize(initLogging)
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "enable diagnostics")
}
func initLogging() {
if verbose {
Debug = golog.New(os.Stderr, "DEBUG: ", golog.Ldate|golog.Ltime)
} else {
Debug = golog.New(ioutil.Discard, "", golog.Ldate|golog.Ltime)
}
Log = golog.New(os.Stderr, "", golog.Ldate|golog.Ltime)
}
// Execute the control program and perform the command
func Execute() {
if err := rootCmd.Execute(); err != nil {
golog.Printf("Error: %v!\n", err)
os.Exit(1)
}
}