Repository navigation
Fix context.(Global)IsSet to respect environment variables - #502
Merged
Merged
Conversation
This appeared to be the least messy approach to hack in support for IsSet also checking environment variables to see if a particular cli.Flag was set without making backwards incompatible changes to the interface. I intend to fix this more properly in v2, probably by adding another method to the cli.Flag interface to push the responsibility down as it occurred to me that it was really the `Flag`s themselves that offer support for configuration via the environment as opposed to the `context` or other supporting structures. This opens the door for the anything implementing the `Flag` interface to have additional sources of input while still supporting `context.IsSet`.
Contributor
Author
|
Fixes #294 |
| return | ||
| } | ||
|
|
||
| envVars := reflect.ValueOf(f).FieldByName("EnvVar").String() |
Member
There was a problem hiding this comment.
Given that this is a context level operation in v1, I think the lookup of the EnvVar field should be more defensive since it's not a part of the Flag interface.
Contributor
Author
There was a problem hiding this comment.
During my testing, I discovered that you just end up with "" in the case that EnvVar doesn't exist on the struct.
Member
There was a problem hiding this comment.
Hot diggety! Ignore me then 😸
Contributor
Author
There was a problem hiding this comment.
Actually, scratch that, you end up with <invalid Value>. I must have made a mistake before, will update.
Member
|
LGTM other than that one lil note |
Contributor
Author
|
Haha, too quick for me, will update on master for the |
Contributor
Author
|
Fixed in 168c954 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This appeared to be the least messy approach to hack in support for
IsSet also checking environment variables to see if a particular
cli.Flag was set without making backwards incompatible changes to the
interface.
I intend to fix this more properly in v2, probably by adding another
method to the cli.Flag interface to push the responsibility down as it
occurred to me that it was really the
Flags themselves that offersupport for configuration via the environment as opposed to the
contextor other supporting structures. This opens the door for theanything implementing the
Flaginterface to have additional sources ofinput while still supporting
context.IsSet.