Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are OverrideDefaultFromEnvar and Required meant to work together? #50

Closed
joprice opened this issue Jun 20, 2015 · 1 comment
Closed

Comments

@joprice
Copy link

joprice commented Jun 20, 2015

From this line of code, it looks like a flag with both OverrideDefaultFromEnvar and Required will cause the parsing to error out, even when an envar is present, since defaultValue is checked on L166 before it is overridden on L172.

func (f *FlagClause) init() error {

alecthomas added a commit that referenced this issue Jun 20, 2015
@alecthomas
Copy link
Owner

That is incorrect. L166 is merely ensuring that users don't do .Default("value").Required(), as it's essentially a programmer error. Once that check is complete, defaultValue is set from the envar so that (later) execution of the context will pull the default value from the environment.

PS. I added a test to illustrate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants