-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
flag: should provide call backs as part of Parse() #8716
Labels
Comments
An example of where this becomes necessary is basically any flag used in testing since it is impossible to interject some kind of setup between flag processing and test start without having to put a sync.Once object at the top of every single test (since who knows which will run given the users command line flags.. etc) So if the intention is that the flag library never be used by anything but main then I guess I can see your argument. Ideally though a library could use flags to set things that impact it at runtime rather than forcing the main() function to cram all of that logic in. For example, setting up proxy settings might be a flag driven function (as well as being exposed via helpers in the library directly). This becomes much more important as abstraction layers get setup. Say you want a flag that says which API endpoint you should target as part of your client library, should the author of the application have to know about the existence of these options and program them into main() even though it doesn't impact their code path in any way? I like go for having a common flag library that unifies the ability for many different things to all act the same and not requires the author of main() to have knowledge of a library used three abstraction layers deep, while still giving the end user to have the ability to change the flag if necessary. It ends up like init(), a way for the caller to set things up prior to things getting real such that blah.Do() doesn't need to be littered around in a hundred places. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by brady:
The text was updated successfully, but these errors were encountered: