-
Notifications
You must be signed in to change notification settings - Fork 70
Description
Because command-line arguments have a default and are set after the environment variables are read, environment variables cannot be used with command-line arguments. They will always be overridden by the default or passed command-line arguments.
grafana-kiosk/pkg/cmd/grafana-kiosk/main.go
Lines 184 to 190 in de02bc6
| log.Println("No config specified, using environment and args") | |
| // no config, use environment and args | |
| if err := cleanenv.ReadEnv(&cfg); err != nil { | |
| log.Println("Error reading config from environment", err) | |
| } | |
| cfg.Target.URL = args.URL | |
| cfg.Target.LoginMethod = args.LoginMethod |
I have confirmed this behavior in production as well. Environment variables do nothing when a config file isn't used. I created a test branch where I removed the command-line setters like lines 189-190 above, and this allowed environment variables to be used again (but this disables command-line arguments entirely).
One possible way to fix this is using the flag library's visit method to get a list of only the command-line arguments that have been set and only updating those.