"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
fs: factor OptionToEnv and ConfigToEnv into fs
Nick Craig-Wood85d09729f2eb
diff --git a/fs/config.go b/fs/config.goindex 543923981..c5283e14b 100644--- a/fs/config.go+++ b/fs/config.go@@ -2,6 +2,7 @@ package fsimport ("net"+ "strings""time")@@ -103,3 +104,16 @@ func NewConfig() *ConfigInfo {return c}++// ConfigToEnv converts an config section and name, eg ("myremote",+// "ignore-size") into an environment name+// "RCLONE_CONFIG_MYREMOTE_IGNORE_SIZE"+func ConfigToEnv(section, name string) string {+ return "RCLONE_CONFIG_" + strings.ToUpper(strings.Replace(section+"_"+name, "-", "_", -1))+}++// OptionToEnv converts an option name, eg "ignore-size" into an+// environment name "RCLONE_IGNORE_SIZE"+func OptionToEnv(name string) string {+ return "RCLONE_" + strings.ToUpper(strings.Replace(name, "-", "_", -1))+}diff --git a/fs/config/config.go b/fs/config/config.goindex ad4d2ea3d..4eca15032 100644--- a/fs/config/config.go+++ b/fs/config/config.go@@ -1108,19 +1108,12 @@ func Authorize(args []string) {fs.Config(name)}-// configToEnv converts an config section and name, eg ("myremote",-// "ignore-size") into an environment name-// "RCLONE_CONFIG_MYREMOTE_IGNORE_SIZE"-func configToEnv(section, name string) string {- return "RCLONE_CONFIG_" + strings.ToUpper(strings.Replace(section+"_"+name, "-", "_", -1))-}-// FileGet gets the config key under section returning the// default or empty string if not set.//// It looks up defaults in the environment if they are presentfunc FileGet(section, key string, defaultVal ...string) string {- envKey := configToEnv(section, key)+ envKey := fs.ConfigToEnv(section, key)newValue, found := os.LookupEnv(envKey)if found {defaultVal = []string{newValue}@@ -1133,7 +1126,7 @@ func FileGet(section, key string, defaultVal ...string) string {//// It looks up defaults in the environment if they are presentfunc FileGetBool(section, key string, defaultVal ...bool) bool {- envKey := configToEnv(section, key)+ envKey := fs.ConfigToEnv(section, key)newValue, found := os.LookupEnv(envKey)if found {newBool, err := strconv.ParseBool(newValue)@@ -1151,7 +1144,7 @@ func FileGetBool(section, key string, defaultVal ...bool) bool {//// It looks up defaults in the environment if they are presentfunc FileGetInt(section, key string, defaultVal ...int) int {- envKey := configToEnv(section, key)+ envKey := fs.ConfigToEnv(section, key)newValue, found := os.LookupEnv(envKey)if found {newInt, err := strconv.Atoi(newValue)diff --git a/fs/config/flags/flags.go b/fs/config/flags/flags.goindex 1618dd1fd..4297f3c06 100644--- a/fs/config/flags/flags.go+++ b/fs/config/flags/flags.go@@ -5,23 +5,16 @@ package flagsimport ("log""os"- "strings""time""github.com/ncw/rclone/fs""github.com/spf13/pflag")-// optionToEnv converts an option name, eg "ignore-size" into an-// environment name "RCLONE_IGNORE_SIZE"-func optionToEnv(name string) string {- return "RCLONE_" + strings.ToUpper(strings.Replace(name, "-", "_", -1))-}-// setDefaultFromEnv constructs a name from the flag passed in and// sets the default from the environment if possible.func setDefaultFromEnv(name string) {- key := optionToEnv(name)+ key := fs.OptionToEnv(name)newValue, found := os.LookupEnv(key)if found {flag := pflag.Lookup(name)