1
mirror of https://github.com/rclone/rclone synced 2024-12-24 15:43:45 +01:00

flags: improve error message when reading environment vars #4888

The message now includes the flag name to help the user work out what
is happening.

    Invalid value for environment variable "RCLONE_VERSION" when setting default
    for --version: strconv.ParseBool: parsing "yes": invalid syntax
This commit is contained in:
Nick Craig-Wood 2020-12-28 12:26:23 +00:00
parent 629c0d0f65
commit 060642ad14

View File

@ -19,13 +19,13 @@ func setDefaultFromEnv(flags *pflag.FlagSet, name string) {
if found { if found {
flag := flags.Lookup(name) flag := flags.Lookup(name)
if flag == nil { if flag == nil {
log.Fatalf("Couldn't find flag %q", name) log.Fatalf("Couldn't find flag --%q", name)
} }
err := flag.Value.Set(newValue) err := flag.Value.Set(newValue)
if err != nil { if err != nil {
log.Fatalf("Invalid value for environment variable %q: %v", key, err) log.Fatalf("Invalid value for environment variable %q when setting default for --%s: %v", key, name, err)
} }
fs.Debugf(nil, "Set default for %q from %q to %q (%v)", name, key, newValue, flag.Value) fs.Debugf(nil, "Set default for --%q from %q to %q (%v)", name, key, newValue, flag.Value)
flag.DefValue = newValue flag.DefValue = newValue
} }
} }