mirror of
https://github.com/rclone/rclone
synced 2024-11-21 22:50:16 +01:00
config: Make fs.ConfigFileGet return an exists flag
This commit is contained in:
parent
85d09729f2
commit
3c89406886
@ -15,7 +15,7 @@ var (
|
||||
//
|
||||
// This is a function pointer to decouple the config
|
||||
// implementation from the fs
|
||||
ConfigFileGet = func(section, key string, defaultVal ...string) string { return "" }
|
||||
ConfigFileGet = func(section, key string) (string, bool) { return "", false }
|
||||
|
||||
// CountError counts an error. If any errors have been
|
||||
// counted then it will exit with a non zero error code.
|
||||
|
@ -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.
|
||||
//
|
||||
|
5
fs/fs.go
5
fs/fs.go
@ -790,9 +790,10 @@ func MustFind(name string) *RegInfo {
|
||||
func ParseRemote(path string) (fsInfo *RegInfo, configName, fsPath string, err error) {
|
||||
configName, fsPath = fspath.Parse(path)
|
||||
var fsName string
|
||||
var ok bool
|
||||
if configName != "" {
|
||||
fsName = ConfigFileGet(configName, "type")
|
||||
if fsName == "" {
|
||||
fsName, ok = ConfigFileGet(configName, "type")
|
||||
if !ok {
|
||||
return nil, "", "", ErrorNotFoundInConfigFile
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user