Commit Graph

68 Commits

Author SHA1 Message Date
Cyphersnake
cb8f879b92 Add parse_env attribute to confique::Config macro
Since there is no established format for representing collections within env variables, to enable their support, the feature with a custom parser attribute added.

Add helpers for parsing env variables into collections

Improve rustdoc for `env_utils` functions

Improve `parse_env` example
2022-11-06 10:18:42 +04:00
Lukas Kalbertodt
337fb3204f Fix some clippy warnings 2022-10-24 10:19:35 +02:00
Lukas Kalbertodt
0e47eb7acf Format code
This is `cargo fmt` but with lots of changes reverted and some adjusted.
2022-10-24 10:13:06 +02:00
Lukas Kalbertodt
d1a62e47eb Add map default values (e.g. default = { "foo": 33 })
This commit also adds a bunch of tests testing maps in several
situations.
2022-10-21 18:13:59 +02:00
Lukas Kalbertodt
093957b515 Add array default value to formatting test example 1 2022-10-21 17:22:03 +02:00
Lukas Kalbertodt
2e432b1f4a Improve docs 2022-10-21 15:27:29 +02:00
Lukas Kalbertodt
2bf2727875 Mark some types in meta as #[non_exhaustive]
This allows some more likely changes without a breaking change.
2022-10-21 15:27:29 +02:00
Lukas Kalbertodt
52b9369f9a Make all FormatOptions #[non_exhaustive]
This is to make adding fields to those structs a non-breaking change.
This unfortunately means that users cannot use the struct initializer
syntax anymore. They have to create a mutable variable and change fields
that way. It's slightly annoying, but I think we want `non_exhaustive`.

Also, there are multiple discussions and pre-RFCs for letting Rust allow
the struct initializer syntax when the type implements `Default`. So
maybe this will improve in the future.
2022-10-21 14:55:30 +02:00
Lukas Kalbertodt
bc03ecaf4e Remove a bunch of cfg attributes 2022-10-21 13:13:32 +02:00
Lukas Kalbertodt
4533f2b2d4 Fix visibility of template module and items
The trait and `template::format` are now crate-private as I don't want
to expose that API surface (alongside the `TomlFormatter` types).
2022-10-21 12:39:41 +02:00
Lukas Kalbertodt
a784e6ee64 Rename format to template (except template::format()) 2022-10-21 12:02:13 +02:00
Lukas Kalbertodt
9b9610a6ac Add JSON5 support 2022-10-21 11:52:53 +02:00
Lukas Kalbertodt
6a9ccd4e22 Do major refactor of format code
This gets rid of a lot of duplicated logic that was previously
copy&pasted. This commit alos:
- Makes it easier to implement new formats
- Gets rid of a few bugs
- Makes the system more flexible (more options)
- Adds a lot of additional tests
2022-10-19 17:12:32 +02:00
Lukas Kalbertodt
44f59f415a Implement Serialize for meta::Expr and use it in PrintExpr
This probably fixes a few edge case bugs (float infinity and stuff) and
results in less code.
2022-10-19 17:10:17 +02:00
Lukas Kalbertodt
4f5c458150 Add YAML formatting tests 2022-10-19 10:12:25 +02:00
Lukas Kalbertodt
736584ad9d Fix incorrect newlines in yaml::format 2022-10-19 10:11:33 +02:00
Lukas Kalbertodt
dd55a17b14 Show env key in config template 2022-10-18 16:07:51 +02:00
Lukas Kalbertodt
075078ac89 Slightly simplify generated code 2022-10-17 14:50:53 +02:00
Lukas Kalbertodt
37bb6b6b14 Add PartialEq impls to all meta items
This is useful for unit-testing but also generally usable. So why not.
2022-10-17 12:37:22 +02:00
Lukas Kalbertodt
f0895a8b2f Add support for array default values 2022-10-17 11:29:38 +02:00
Lukas Kalbertodt
5c3315b015 Move to Rust edition 2021 2022-10-14 16:42:49 +02:00
Lukas Kalbertodt
eb03488973 Fix using env with deserialize_with
Fixes #2

I simply forgot to use the `deserialize_with` attribute for the env
deserialization. The previous code was somewhat weirdly coded in that
we would always deserialize `Option<T>` (as it's a partial type) and
the "env variable not present" info would travel through the
deserializer to the `Option<T> as Deserialize` impl. Now it's more
straight forward.
2022-10-14 16:33:37 +02:00
Lukas Kalbertodt
963e4745a3 Allow unused test utility
This is only unused with `--no-default-features`.
2022-10-11 13:17:19 +02:00
Lukas Kalbertodt
65d0b7ca17 Fix minor docs formatting issue 2022-10-11 12:59:54 +02:00
Lukas Kalbertodt
56f8ff24d5 Improve toml::format regarding space above nested objects 2022-04-07 17:19:38 +02:00
Lukas Kalbertodt
8db8fcafc4 Add two toml::format tests 2022-04-07 14:00:56 +02:00
Lukas Kalbertodt
1c6ecdd4ad Fix doctests using derive
See https://github.com/rust-lang/rust/issues/83583
2022-03-30 17:38:39 +02:00
Lukas Kalbertodt
e801403009 Fix output of toml::format by always handling leaf fields first
Otherwise this:

```
struct Config {
    #[config(nested)]
    foo: ...,
    bar: ...,
}
```

would emit:

```
[foo]

```

Which is incorrect.
2022-03-30 16:15:27 +02:00
Lukas Kalbertodt
a50f78e938 Add deserialize_with attribute that is forwarded to serde 2021-11-03 16:01:57 +01:00
Lukas Kalbertodt
4f4f42e8f3 Disable some code (and fix others) when no features are enabled 2021-07-28 12:38:50 +02:00
Lukas Kalbertodt
8a520927a2 Add crate-level documentation 2021-07-28 12:02:09 +02:00
Lukas Kalbertodt
00dbe4dc0a Fix compilation failure for --no-default-features 2021-07-27 17:16:06 +02:00
Lukas Kalbertodt
cc1a0eba5e Minor documentation improvements 2021-07-27 16:20:24 +02:00
Lukas Kalbertodt
a86ab50588 Add more documentation to Config trait and derive 2021-07-27 16:15:05 +02:00
Lukas Kalbertodt
271a807ab0 Fix emission of TOML strings (in particular, quoting) 2021-07-27 15:10:07 +02:00
Lukas Kalbertodt
0bc105b22d Add yaml::format 2021-07-27 15:05:07 +02:00
Lukas Kalbertodt
74ce2daf05 Add Builder::env to read environment variables 2021-07-27 01:14:00 +02:00
Lukas Kalbertodt
aa5eb06f49 Add Partial::from_env and implement it in derive macro 2021-07-27 01:12:57 +02:00
Lukas Kalbertodt
3ac922ca2f Add deserialization logic for reading values from environment variables 2021-07-27 01:10:12 +02:00
Lukas Kalbertodt
db2aebc270 Parse #[env] attribute and representing it in meta types 2021-07-25 11:36:36 +02:00
Lukas Kalbertodt
3c7376035c Add Config::from_file 2021-07-25 10:56:46 +02:00
Lukas Kalbertodt
ebd8aba2fa Disallow Option<_> type for fields with #[nested] or #[default]
Regarding nested fields: I cannot imagine a situation where that
distinction is useful. Also, specifying an empty nested object looks
stupid in TOML and YAML anyway.

Regarding default fields: If there is a default value, then the field
should not be declared as optional to begin with.
2021-07-25 10:46:06 +02:00
Lukas Kalbertodt
9c5990d803 Add Partial::is_empty and Partial::is_complete 2021-07-25 10:06:46 +02:00
Lukas Kalbertodt
ca5bb2488f Add Builder type as convenient high level loading API 2021-07-25 09:45:59 +02:00
Lukas Kalbertodt
76373278b0 Remove Source trait and Config::from_sources
I'm not sure about a good high level API.
2021-07-24 22:25:40 +02:00
Lukas Kalbertodt
6aece589c4 Add toml::FormatOptions::comments 2021-07-24 19:44:27 +02:00
Lukas Kalbertodt
522494aa5c Fix derive macro for pub(crate) visibility 2021-07-24 18:48:15 +02:00
Lukas Kalbertodt
ceb9799e55 Add toml module with format function for config templates 2021-07-24 18:48:15 +02:00
Lukas Kalbertodt
b663e698ba Implement Display for meta::Integer and meta::Float
Those impls is pretty unambiguous I think.
2021-07-24 18:48:14 +02:00
Lukas Kalbertodt
066e7a0023 Add meta::Field::optional 2021-07-24 18:48:14 +02:00