lib/envflag: use flag.Set for setting the flags from env vars

This should make visible the set flags at flag.Visit(), which is used later for logging
and exporting the `is_set` label for these flags at /metrics page
This commit is contained in:
Aliaksandr Valialkin 2021-10-20 00:41:02 +03:00
parent 53bb58ed2a
commit 676ad70d9f
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1

View File

@ -40,7 +40,7 @@ func Parse() {
// Get flag value from environment var.
fname := getEnvFlagName(f.Name)
if v, ok := os.LookupEnv(fname); ok {
if err := f.Value.Set(v); err != nil {
if err := flag.Set(f.Name, 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 %q: %s", f.Name, v, fname, err)
}