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

support for layered config using a serde Deserializer as a source #7

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

cbeck88
Copy link
Owner

@cbeck88 cbeck88 commented Sep 30, 2024

This allows a serde Deserializer, representing a config file, to be used as a value source, via the new ConfSerde extension trait.

To use it you have to put the #[conf(serde)] tag on your struct.

The priority order is args > env > serde > defaults.

You can use this with a config file in any serde supported format. Or the data can come from another source, such as a json Value that you loaded and modified, or a figment::Value for instance.

I am very happy that this approach avoids creating any specific dependency on code that opens a file or reads any particular format, and that the error reporting is still comprehensive in the way that I want. This is at least proof of concept for a way that I would be happy for this to work in conf.


Still needs a lot more tests and documentation, and we don't really support any serde options right now, but we have a plan for that.

Base automatically changed from subcommands to develop October 7, 2024 16:56
@cbeck88 cbeck88 force-pushed the layered-config branch 5 times, most recently from b6614aa to 0c344bd Compare October 13, 2024 23:12
@cbeck88 cbeck88 marked this pull request as ready for review October 13, 2024 23:15
@cbeck88 cbeck88 changed the title WIP support for layered config using a serde Deserializer as a source support for layered config using a serde Deserializer as a source Oct 13, 2024
This allows a serde Deserializer, representing a config file, to be used
as a value source, via the builder API, which is also new in this commit.

To use the serde feature, you have to put the `#[conf(serde)]` tag on your struct.

We also introduce a `ConfSerde` extension trait, which is implemented
when `#[conf(serde)]` is annotated, and provides implementation details
for this layered config feature on that struct.

The priority order is args > env > serde > defaults

We also support this in subcommands, via the `SubcommandsSerde` extension trait.

To further adjust the serde system, most fields have serde options like
`serde(rename)` and `serde(skip)`. Structs have a `serde(allow_unknown_fields)`
option.

Parameter and Repeat fields have a `serde(use_value_parser)` option, which
can be useful if you just want serde to read a string and then forward it
to the value parser.
@cbeck88 cbeck88 merged commit 5fa7d83 into develop Oct 14, 2024
4 checks passed
@cbeck88 cbeck88 deleted the layered-config branch October 14, 2024 00:10
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.

1 participant