forked from rai-project/dlframework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
58 lines (50 loc) · 1.24 KB
/
config.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
package cmd
import (
"path/filepath"
"github.com/k0kubun/pp/v3"
"github.com/unknwon/com"
"github.com/fatih/color"
homedir "github.com/mitchellh/go-homedir"
"github.com/c3sr/config"
"github.com/c3sr/logger"
"github.com/sirupsen/logrus"
)
var (
IsDebug bool
IsVerbose bool
AppSecret string
CfgFile string
log *logrus.Entry = logrus.New().WithField("pkg", "dlframework/framework/cmd")
)
// Init reads in config file and ENV variables if set.
func Init() {
log.Level = logrus.DebugLevel
config.AfterInit(func() {
log = logger.New().WithField("pkg", "dlframework/framework/cmd")
})
color.NoColor = false
opts := []config.Option{
config.AppName("carml"),
config.ColorMode(true),
config.DebugMode(IsDebug),
config.VerboseMode(IsVerbose),
}
if IsDebug || IsVerbose {
pp.WithLineInfo = true
}
if c, err := homedir.Expand(CfgFile); err == nil {
CfgFile = c
}
if config.IsValidRemotePrefix(CfgFile) {
opts = append(opts, config.ConfigRemotePath(CfgFile))
} else if com.IsFile(CfgFile) {
if c, err := filepath.Abs(CfgFile); err == nil {
CfgFile = c
}
opts = append(opts, config.ConfigFileAbsolutePath(CfgFile))
}
if AppSecret != "" {
opts = append(opts, config.AppSecret(AppSecret))
}
config.Init(opts...)
}