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

Configfile #47

Merged
merged 28 commits into from
Feb 8, 2024
Merged

Configfile #47

merged 28 commits into from
Feb 8, 2024

Conversation

vincentdephily
Copy link
Owner

Adds a toml config file.

This is still an experiment, the final feature might look very different. Loading/parsing a config
file is trivial; the hard part is merging the different sources (cli > config > default), giving
clear error feedback (should be as good as cli error feedback), and keeping boiler-plate and
performance in check. I've gone thru a few iterations to reach this MVP, there are a few
complexities left down the road, but this seems like a good snapshot to have in git histroy.
Just one extra boolean, but still an interesting case:
 * It's in a subsection of the toml file
 * Needs to be converted to a option-with-arg in the cli (so that the cli can override the config,
   and to make the "no cli value given" case more straightforward)

The ArgParse trait simplifies returning a detailed error, and writing the `sel()` helper.
And some code cleanups. Things are still messy at this stage, but should clear up once we finish
moving all items.
…e versatile

* We'll have lots of small parsable types, this should be more tidy.
* Some future types need configurable parsing and default.
The same type is used for different purposes, so this required to make the code a bit more versatile
(see previous commit). Took a few trial and errors to arrive at this neat solution.
As a side effect, ensures the conf name is the same in toml and cli.
… clap's

Struggled for a while to get the desired output with clap errors, so I introduced our own error
type. We'll need to maintain it to match the style of clap errors, but it's not a lot of code, call
sites are cleaner, and the error strings are better (see `--from` and `--show`).
Misc improvements:
* Now accepting verbose group values
* Now accepting `(n)one` grouping (to override config)
* Simplified code by using that `None` variant  instead of an `Option`
I initially made this toml-configurable, but I don't think anybody would want to set a different
default. Added `current` enum variant to replace the use of `Option<_>`. Was needed to override a
toml setting, but still seems valuable without it.

The formatting difference between clap::Error and ArgError is not big, but I'll still want to
harmonize things somehow.
Changed integer parsing to i64, relying on runtime range-check and casts to get other integers. This
avoids the need for multiple/generic integer parsing.
This is a quick solution with carefree cloning, I hope to make things leaner at the end.
That was the last use of `ArgMatches` outside of the config module :)
The only way to change the config location now is using the env var. Changing the location should be
a very rare need, so let's simplify things.
I don't agree with clippy here but also don't really care.
Failure to parse is still a hard error, so far.
@vincentdephily vincentdephily merged commit 23e52a2 into master Feb 8, 2024
9 checks passed
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