lib/envflag: check for incorrect flag values read from environment vars

This commit is contained in:
Aliaksandr Valialkin 2020-02-10 16:08:04 +02:00
parent 5d207b2025
commit 025297f15d

View file

@ -2,6 +2,7 @@ package envflag
import (
"flag"
"log"
"os"
)
@ -34,7 +35,10 @@ func Parse() {
}
// Get flag value from environment var.
if v, ok := os.LookupEnv(f.Name); ok {
f.Value.Set(v)
if err := f.Value.Set(v); err != nil {
// Do not use lib/logger here, since it is uninitialized yet.
log.Fatalf("cannot set flag %s to %q, which is read from environment variable: %s", f.Name, v, err)
}
}
})
}