mirror of
https://github.com/rclone/rclone.git
synced 2025-01-10 16:28:30 +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
|
// This is a function pointer to decouple the config
|
||||||
// implementation from the fs
|
// 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
|
// CountError counts an error. If any errors have been
|
||||||
// counted then it will exit with a non zero error code.
|
// counted then it will exit with a non zero error code.
|
||||||
|
@ -82,7 +82,7 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Set the function pointer up in fs
|
// Set the function pointer up in fs
|
||||||
fs.ConfigFileGet = FileGet
|
fs.ConfigFileGet = FileGetFlag
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfigData() *goconfig.ConfigFile {
|
func getConfigData() *goconfig.ConfigFile {
|
||||||
@ -1108,6 +1108,19 @@ func Authorize(args []string) {
|
|||||||
fs.Config(name)
|
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
|
// FileGet gets the config key under section returning the
|
||||||
// default or empty string if not set.
|
// 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) {
|
func ParseRemote(path string) (fsInfo *RegInfo, configName, fsPath string, err error) {
|
||||||
configName, fsPath = fspath.Parse(path)
|
configName, fsPath = fspath.Parse(path)
|
||||||
var fsName string
|
var fsName string
|
||||||
|
var ok bool
|
||||||
if configName != "" {
|
if configName != "" {
|
||||||
fsName = ConfigFileGet(configName, "type")
|
fsName, ok = ConfigFileGet(configName, "type")
|
||||||
if fsName == "" {
|
if !ok {
|
||||||
return nil, "", "", ErrorNotFoundInConfigFile
|
return nil, "", "", ErrorNotFoundInConfigFile
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user