This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
root.go
68 lines (53 loc) · 2.09 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
package cmd
import (
"os"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var rootCmd = &cobra.Command{
Use: "bot",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.SetEnvPrefix("KR")
viper.AutomaticEnv()
_ = viper.ReadInConfig()
level, err := log.ParseLevel(viper.GetString("log"))
if err != nil {
panic(err)
}
log.SetFormatter(&log.TextFormatter{
ForceColors: viper.GetBool("colors"),
})
log.SetOutput(os.Stdout)
log.SetLevel(level)
},
}
func Execute() {
// Allow running from explorer
cobra.MousetrapHelpText = ""
// Execute run command as default
cmd, _, err := rootCmd.Find(os.Args[1:])
if (len(os.Args) <= 1 || os.Args[1] != "help") && (err != nil || cmd == rootCmd) {
args := append([]string{"run"}, os.Args[1:]...)
rootCmd.SetArgs(args)
}
if err := rootCmd.Execute(); err != nil {
panic(err)
}
}
func init() {
rootCmd.PersistentFlags().String("log", "info", "The log level to output")
rootCmd.PersistentFlags().Bool("colors", false, "Force output with colors")
rootCmd.PersistentFlags().String("environment_name", "", "Name of the environment")
rootCmd.PersistentFlags().String("locality", "", "Name of locality")
rootCmd.PersistentFlags().String("manifest_bucket_location", "", "Manifest bucket location")
rootCmd.PersistentFlags().StringSlice("ingestors", []string{}, "List of ingestors")
rootCmd.PersistentFlags().Int32("batch_signing_key_expiration", 90, "Expiration period in days for the batch signing key")
rootCmd.PersistentFlags().Int32("batch_signing_key_rotation", 70, "Rotation interval in days for the batch signing key")
rootCmd.PersistentFlags().Int32("packet_encryption_key_expiration", 395, "Expiration period in days for the packet encryption key")
rootCmd.PersistentFlags().Int32("packet_encryption_key_rotation", 320, "Rotation interval in days for the packet encryption key")
_ = viper.BindPFlag("log", rootCmd.PersistentFlags().Lookup("log"))
_ = viper.BindPFlag("colors", rootCmd.PersistentFlags().Lookup("colors"))
}