go-flags icon indicating copy to clipboard operation
go-flags copied to clipboard

Provide an option to define priority between environment variables and cli arguments

Open rpdelaney opened this issue 5 years ago • 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)

rpdelaney avatar Nov 07 '19 20:11 rpdelaney

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.

pdkovacs avatar Dec 06 '20 16:12 pdkovacs

It talks about default values and environment variables, IMHO.

Agreed. This issue is meant as a feature request to extend the existing functionality.

rpdelaney avatar Dec 06 '20 18:12 rpdelaney

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.

pdkovacs avatar Dec 07 '20 09:12 pdkovacs

The ask is for an option to set the priority.

rpdelaney avatar Dec 07 '20 15:12 rpdelaney

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.

suntong avatar Jan 17 '22 22:01 suntong