diff --git a/lib/envflag/envflag.go b/lib/envflag/envflag.go index e4a79e9e4f..2e41fb2b79 100644 --- a/lib/envflag/envflag.go +++ b/lib/envflag/envflag.go @@ -5,6 +5,10 @@ import ( "os" ) +var enable = flag.Bool("envflag.enable", false, "Whether to enable reading flags from environment variables additionally to command line. "+ + "Command line flag values have priority over values from envoronment vars. "+ + "Flags are read only from command line if this flag isn't set") + // Parse parses environment vars and command-line flags. // // Flags set via command-line override flags set via environment vars. @@ -12,6 +16,9 @@ import ( // This function must be called instead of flag.Parse() before using any flags in the program. func Parse() { flag.Parse() + if !*enable { + return + } // Remember explicitly set command-line flags. flagsSet := make(map[string]bool) @@ -25,6 +32,7 @@ func Parse() { // The flag is explicitly set via command-line. return } + // Get flag value from environment var. if v, ok := os.LookupEnv(f.Name); ok { f.Value.Set(v) }