diff --git a/cmd/cmd.go b/cmd/cmd.go index ca01ecf1d..df1a208b0 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -513,7 +513,7 @@ func AddBackendFlags() { if opt.IsPassword { help += " (obscured)" } - flag := pflag.CommandLine.VarPF(opt, name, opt.ShortOpt, help) + flag := flags.VarPF(pflag.CommandLine, opt, name, opt.ShortOpt, help) if _, isBool := opt.Default.(bool); isBool { flag.NoOptDefVal = "true" } diff --git a/fs/config/flags/flags.go b/fs/config/flags/flags.go index bd27810fa..39b5db0ea 100644 --- a/fs/config/flags/flags.go +++ b/fs/config/flags/flags.go @@ -156,6 +156,15 @@ func FVarP(flags *pflag.FlagSet, value pflag.Value, name, shorthand, usage strin setDefaultFromEnv(flags, name) } +// VarPF defines a flag which can be overridden by an environment variable +// +// It is a thin wrapper around pflag.VarPF +func VarPF(flags *pflag.FlagSet, value pflag.Value, name, shorthand, usage string) *pflag.Flag { + flag := flags.VarPF(value, name, shorthand, usage) + setDefaultFromEnv(flags, name) + return flag +} + // StringArrayP defines a flag which can be overridden by an environment variable // // It sets one value only - command line flags can be used to set more.