forked from project-copacetic/copacetic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (47 loc) · 1.08 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
package main
import (
"os"
"strings"
"github.com/project-copacetic/copacetic/pkg/patch"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// Globals for Debug logging flag and version reporting.
var (
debug bool
version string
)
func newRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "copa",
Short: "Copacetic",
Long: "Project Copacetic: container patching tool",
PersistentPreRun: func(_ *cobra.Command, _ []string) {
if debug {
log.SetLevel(log.DebugLevel)
}
},
RunE: func(cmd *cobra.Command, _ []string) error {
return cmd.Usage()
},
SilenceUsage: true,
Version: version,
}
flags := rootCmd.PersistentFlags()
flags.BoolVar(&debug, "debug", false, "enable debug level logging")
rootCmd.AddCommand(patch.NewPatchCmd())
return rootCmd
}
func initConfig() {
viper.SetEnvPrefix("copa")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
}
func main() {
cobra.OnInitialize(initConfig)
rootCmd := newRootCmd()
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
}