config: Make fs.ConfigFileGet return an exists flag

This commit is contained in:
Nick Craig-Wood
2018-07-16 08:50:52 +01:00
parent 85d09729f2
commit 3c89406886
3 changed files with 18 additions and 4 deletions
+14 -1
View File
@@ -82,7 +82,7 @@ var (
func init() {
// Set the function pointer up in fs
fs.ConfigFileGet = FileGet
fs.ConfigFileGet = FileGetFlag
}
func getConfigData() *goconfig.ConfigFile {
@@ -1108,6 +1108,19 @@ func Authorize(args []string) {
fs.Config(name)
}
// FileGetFlag gets the config key under section returning the
// the value and true if found and or ("", false) otherwise
//
// It looks up defaults in the environment if they are present
func FileGetFlag(section, key string) (string, bool) {
newValue, err := getConfigData().GetValue(section, key)
if err == nil {
return newValue, true
}
envKey := fs.ConfigToEnv(section, key)
return os.LookupEnv(envKey)
}
// FileGet gets the config key under section returning the
// default or empty string if not set.
//