-
Notifications
You must be signed in to change notification settings - Fork 5
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
Configfile #47
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Rewordings and cleanups.
I don't agree with clippy here but also don't really care.
Failure to parse is still a hard error, so far.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds a toml config file.