-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Since one possibly hijacks their "Before" by using altsrc we should have another statement run after the context is loaded but after Before #800
Comments
@jszwedko @meatballhat @michaeljs1990 would you guys like to take a look over things and have a discussion and review the PR's with me - I am currently having to use this to get |
Sounds good to me, this weekend I'll take some time out to sit down and grok the above. |
@michaeljs1990 I should mention that there are two separate PR's for |
BUMP Any interest in this? It has been helpful in my personal project to use this as such where the overrides are in decreasing priority:
Also once the |
Hiya, I'm having a bit of a hard time parsing this github issue. I have 2 thoughts: Can you rewrite the issue to follow some slightly more standard change request patterns? Here's some examples (one I googled, and two by me)
I would also note that none of the current maintainers (to my knowledge) are a fan of |
🕐 issue timeout 🕐 I'm timing out this issue since it hasn't been updated in quite some time. Feel free to comment in support, and I'll re-open it! |
As you can see in a few examples floating around the web the
Before
method is sort of hijacked by the use ofaltsrc
in loading YAML or TOML:altsrc
flag optional inBefore:
#793This leaves other initiation you may want to perform that perhaps is some preparation for your entire command and subsequent subcommands (for example setting up generic logging or setting some values all subcommands will need). If you are not loading configuration using
altsrc
thenBefore
is just fine for your use case. However in the event you do want to load configuration from YAML or TOML you are left with yourBefore
held hostage with no option to perform any otherBefore
actions. Thus I am proposing a post-Flags
and post-Before
directived I've dubbedPrepare
.The following code from how you would do this currently is pretty standard in your searches around the documentation and the web for examples of loading configuration. Note that the
Before
method is "hostage" (e.g. it can no longer do anything else) to this process of loading configuration leaving you little option to perform any otherBefore
actions you may want to take:With the YAML file
file.yml
:In previous
test.go
:Output:
Instead I have proposed the use of a
Prepare
directive that will run afterBefore
so you can still load configuration and then do something with everything loaded. Take the above example modified with this newPrepare
directive:The file
test.go
:Output:
The text was updated successfully, but these errors were encountered: