This repository has been archived by the owner on Jun 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.go
66 lines (56 loc) · 1.73 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
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"os"
"github.com/flanksource/konfigadm/cmd"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
func init() {
log.SetOutput(os.Stderr)
}
func main() {
var root = &cobra.Command{
Use: "konfigadm",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
level, _ := cmd.Flags().GetCount("loglevel")
switch {
case level > 2:
log.SetLevel(log.TraceLevel)
case level > 1:
log.SetLevel(log.DebugLevel)
case level > 0:
log.SetLevel(log.InfoLevel)
default:
log.SetLevel(log.WarnLevel)
}
log.SetOutput(os.Stderr)
},
}
root.PersistentFlags().StringSliceP("config", "c", []string{}, "Config file path in YAML or JSON format, Use - to read YAML from stdin")
root.PersistentFlags().StringSliceP("var", "e", []string{}, "Extra Variables to in key=value format ")
root.PersistentFlags().StringSliceP("tag", "t", []string{}, "Runtime tags to use, valid tags: debian,ubuntu,redhat,rhel,centos,aws,vmware,photon")
root.PersistentFlags().BoolP("detect-tags", "d", true, "Detect tags to use")
root.AddCommand(&cmd.CloudInit, &cmd.Minify, &cmd.Apply, &cmd.Verify, &cmd.Images)
if len(commit) > 8 {
version = fmt.Sprintf("%v, commit %v, built at %v", version, commit[0:8], date)
}
root.AddCommand(&cobra.Command{
Use: "version",
Short: "Print the version of konfigadm",
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version)
},
})
root.PersistentFlags().CountP("loglevel", "v", "Increase logging level")
root.SetUsageTemplate(root.UsageTemplate() + fmt.Sprintf("\nversion: %s\n ", version))
if err := root.Execute(); err != nil {
os.Exit(1)
}
}