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

skip unrecognized sections, subsections, and variables #2

Closed
wants to merge 1 commit into from
Closed

skip unrecognized sections, subsections, and variables #2

wants to merge 1 commit into from

Conversation

sqs
Copy link

@sqs sqs commented Oct 3, 2015

Changes the behavior to match that of encoding/json, etc., which do
not complain if input data is not fully represented in resulting
struct.

@speter: It seems that it was a conscious design decision to be strict about mapping all input to the struct. Is this a requirement? It actually makes it nearly impossible (AFAICT) to use this to actually parse git config files, which can contain arbitrary top-level sections.

One future improvement could be having gcfg put extraneous unmapped data into a struct field (if present) named Extra or tagged with gcfg:",extra", or something like that.

Changes the behavior to match that of encoding/json, etc., which do
not complain if input data is not fully represented in resulting
struct.
@speter
Copy link
Contributor

speter commented Oct 11, 2015

Thanks for the pull request, but as you noticed, the fail-fast behavior is intentional and I don't really want to change it.

One potential solution would be to introduce a special error type for unmatched data. Parsing would continue after the first error as long as there are no other problems besides extra data. The caller can then do a type assertion on the resulting error, and choose to ignore this kind of error in cases when that is the desirable behavior.

Also note that even though the syntax is based on git config, it is not 100% compatible (and it's not a goal to make it 100% compatible), so sooner or later you will encounter git config files that cannot be parsed by gcfg.

@speter
Copy link
Contributor

speter commented Aug 14, 2016

Sorry for taking ages to implement this, but you can use it now in v1.2.0. Let me know about your experiences (in case you're still interested in this).

@speter speter closed this Aug 14, 2016
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

Successfully merging this pull request may close these issues.

None yet

2 participants