Provide an option to define priority between environment variables and cli arguments
rpdelaney opened this issue · 5 comments
Currently, environment variables beat command line arguments. It would be nice to be able to reverse this behavior with an option.
env: the default value of the option is overridden from the
specified environment variable, if one has been defined.
(optional)
The documentation referenced here doesn't seem to talk about priority between command line arguments and environment variables. It talks about default values and environment variables, IMHO.
As to the actual priority between command line arguments and environment variables, command line arguments seem to override environment variables during go-flags
parsing in my tests. Looking at the relevant code place(s) of the go-flags
implementation could help corroborate or refute this.
It talks about default values and environment variables, IMHO.
Agreed. This issue is meant as a feature request to extend the existing functionality.
I thought that by "environment variables beat command line arguments" you meant that environment variables override command line arguments. I've found that neither the documentation says this nor does the tool behave like this. That is why I cared to comment here. Sorry for the eventual confusion my comment may have caused.
The ask is for an option to set the priority.
As to the actual priority between command line arguments and environment variables, command line arguments seem to override environment variables during
go-flags
parsing in my tests...
in mine too.
I found the order is,
command line arguments override environment variables, which override default variables if any.
Here are the sample outputs:
https://github.com/suntong/lang/tree/master/lang/Go/src/sys/go-flags/wireframed#update
This is actually the order that I'd prefer.