forked from google/go-licenses
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
46 lines (39 loc) · 1.16 KB
/
init.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
package cmd
import (
"fmt"
"os"
"github.com/spf13/viper"
"github.com/khulnasoft/chk-licenses/chklicenses/presenter"
"github.com/khulnasoft/chk-licenses/internal/config"
)
var appConfig *config.Application
var configPath string
func setCliOptions() {
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "application config file")
flag := "output"
rootCmd.PersistentFlags().StringP(
flag, "o", presenter.TextPresenter.String(),
fmt.Sprintf("report output formatter, options=%v", presenter.Options),
)
if err := viper.BindPFlag(flag, rootCmd.PersistentFlags().Lookup(flag)); err != nil {
fmt.Printf("unable to bind flag '%s': %+v", flag, err)
os.Exit(1)
}
flag = "verbose"
rootCmd.PersistentFlags().CountP(
flag, "v",
"increase verbosity (-v = info, -vv = debug)",
)
if err := viper.BindPFlag(flag, rootCmd.PersistentFlags().Lookup(flag)); err != nil {
fmt.Printf("unable to bind flag '%s': %+v", flag, err)
os.Exit(1)
}
}
func initAppConfig() {
cfg, err := config.LoadConfigFromFile(viper.GetViper(), configPath)
if err != nil {
fmt.Printf("failed to load application config: \n\t%+v\n", err)
os.Exit(1)
}
appConfig = cfg
}