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

backend/flag: error when config is partial #63

Open
rogpeppe opened this issue May 14, 2019 · 1 comment
Open

backend/flag: error when config is partial #63

rogpeppe opened this issue May 14, 2019 · 1 comment

Comments

@rogpeppe
Copy link
Contributor

With confita, it's usual to use Load on a struct which doesn't contain all the possible configuration information. For example, we might require information on just the configuration required by a single component.

Unfortunately this does not work well with the flags backend, because it's not possible to parse command line flags correctly without knowing all the possible flags.

This code demonstrates the issue: https://play.golang.org/p/rxws8K5Noxb

rogpeppe added a commit that referenced this issue Nov 28, 2019
In #67, the `isFlagSet` logic was changed so that it always returned
true, so even unmentioned flags would override previously set values.

This PR fixes that issue (fixes #79) and also changes the flag tests
to be somewhat more flexible and test this specific issue.

I haven't made any wider fixes because the concept of using command-line
flags as a backend is fundamentally broken in a way that cannot be fixed
(see #63), so will probably be removed in a future major version release
of confita.
@Rheisen
Copy link

Rheisen commented Aug 23, 2022

I seem to have run into this issue as well. Is it possible to have multiple independent Confita configuration structures, and have them parse flags in a manner that does not error when they are loaded separately? It appears like the flags backend when executing the LoadStruct command returns the result of flag.Parse, which will throw an error if a flag is not found in the flag set, which is then returned on line 202 of config.go. If the error is a flag not being found on the configuration struct, could operations continue instead of returning?

It does seem like this could be difficult based on how the standard library parses flags, however.

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