-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
37 lines (32 loc) · 939 Bytes
/
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
package main
import (
"github.com/nlm/briq-cli/utils"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
const (
viperKeyBriqSecretKey = "secret_key"
)
var (
config Config
rootCmd = cobra.Command{
Use: "briq-cli",
Short: "briq command-line utility",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
cobra.CheckErr(utils.PrefixError("config error", config.Check()))
},
}
)
func Register(cmd *cobra.Command) {
rootCmd.AddCommand(cmd)
}
func main() {
viper.AddConfigPath(".") // optionally look for config in the working directory
viper.SetConfigName("config") // name of config file (without extension)
viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name
viper.SetEnvPrefix("briq") // prefix for environment variables
viper.AutomaticEnv()
cobra.CheckErr(viper.ReadInConfig())
cobra.CheckErr(viper.Unmarshal(&config))
rootCmd.Execute()
}