backend/flag: error when config is partial
rogpeppe opened this issue · 1 comments
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
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.