1
0
mirror of https://github.com/rclone/rclone.git synced 2025-12-06 00:03:32 +00:00

fs: add Options registry and rework rc to use it

This commit is contained in:
Nick Craig-Wood
2024-07-03 17:22:47 +01:00
parent 8e10fe71f7
commit e79273f9c9
5 changed files with 125 additions and 40 deletions

View File

@@ -33,10 +33,15 @@ func (oev optionEnvVars) Get(key string) (value string, ok bool) {
if opt == nil {
return "", false
}
envKey := OptionToEnv(oev.prefix + "-" + key)
var envKey string
if oev.prefix == "" {
envKey = OptionToEnv(key)
} else {
envKey = OptionToEnv(oev.prefix + "-" + key)
}
value, ok = os.LookupEnv(envKey)
if ok {
Debugf(nil, "Setting %s_%s=%q from environment variable %s", oev.prefix, key, value, envKey)
Debugf(nil, "Setting %s %s=%q from environment variable %s", oev.prefix, key, value, envKey)
} else if opt.NoPrefix {
// For options with NoPrefix set, check without prefix too
envKey := OptionToEnv(key)
@@ -115,10 +120,12 @@ func ConfigMap(prefix string, options Options, configName string, connectionStri
}
// remote specific environment vars
config.AddGetter(configEnvVars(configName), configmap.PriorityNormal)
if configName != "" {
config.AddGetter(configEnvVars(configName), configmap.PriorityNormal)
}
// backend specific environment vars
if options != nil && prefix != "" {
if options != nil {
config.AddGetter(optionEnvVars{prefix: prefix, options: options}, configmap.PriorityNormal)
}