-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathread.go
51 lines (40 loc) · 1.07 KB
/
read.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
package config
import "fmt"
// ReadConfig parses commandline arguments, reads parameters from config and from environment
func (p *providerImpl) ReadConfig(args []string) error {
if p.pFlagSet == nil {
return fmt.Errorf("Pflag is nil")
}
if p.Viper == nil {
return fmt.Errorf("Viper is nil")
}
if err := p.setDefaults(); err != nil {
return err
}
if err := p.registerAndParseFlags(args); err != nil {
return err
}
if err := p.registerEnvParams(); err != nil {
return err
}
configFilenameEntryname := p.configFileEntry.name
cfgFile := p.Viper.GetString(configFilenameEntryname)
if err := p.readCfgFile(cfgFile); err != nil {
return err
}
// apply the configuration automatically in case a target is available
if p.configTarget != nil {
return applyConfig(p, p.configTarget, "", configTag{}, p.mappingFuncRegistry)
}
return nil
}
func (p *providerImpl) readCfgFile(cfgFileName string) error {
if len(cfgFileName) == 0 {
return nil
}
p.Viper.SetConfigFile(cfgFileName)
if err := p.Viper.ReadInConfig(); err != nil {
return err
}
return nil
}