-
Notifications
You must be signed in to change notification settings - Fork 24
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
Implement Serialization and Deserialization for Verbosity #114
base: master
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 12205777991Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will:
- remove rstest
- serialize to/from LevelFilter instead of Option(Level)
- add a specific test for TOML serialization
- Fix the github lints
- split the i8 change out to another commit (and will raise another PR for it if necessary)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving to LevelFilter made it easy to derive serialize / deserialize using From<LevelFilter>
instead of a custom implementation.
src/lib.rs
Outdated
} | ||
|
||
// round-trips | ||
let toml = "meaning_of_life = 42\nverbose = \"DEBUG\"\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how I feel about deserializing to all-caps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this irks me a little too, but being consistent with the existing behavior won out over my ideal approach. If I was designing the log
crate, I think I'd have made that serialization lower case too.
Here, this can deserialize from either case, but serializes to upper case. It comes from the serialization of log::LevelFilter
. That means upper case is consistent with any other serialization that works with log level serialization (and is consistent with the usual display of the level in log outputs).
If you did want to avoid this, it would require going back to using a custom serialization implementation. This doesn't seem worth the extra code and tests to me. I prefer the simplicity even if that comes with a slightly ugly default which is consistent with other things doing the same thing.
I also suspect the serialization side of this will be used much less frequently than the deserialization side, and the serialization side will also often be more focused on programs re-reading the format rather than humans.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On one hand, if people are serializing LevelFilter
, this keeps us consistent with that. On the other hand, this will produce results inconsistent with every other serialized value. This isn't just important here but for other cases like schemars. I think I want to let this sit for a time to mull over this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no problem :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eb58de2 serializes to VerbosityFilter
instead of this, which doesn't have a deserialization implementation that handles upper case tokens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That replaced SCREAMING CASE with Title case
assert_eq!(toml, "meaning_of_life = 42\nverbosity = \"Debug\"\n");
I feel like lower case is much more likely to align with a users configuration format design (as most are likely kebab-case or snake_case)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw eb58de2 just changed the value but it doesn't answer the question about interoperability
2a3fb79
to
99d104e
Compare
In eb58de2, I rewrote this based on the 3.0 release. Notably this uses the |
Verbosity is serialized and deserialized using the title case of the VerbosityFilter (e.g. "Debug") The `serde` dependency is gated behind an optional feature flag. Added conversion methods between Verbosity and VerbosityFilter to simplify the implementation and derived PartialEq, Eq impls on types where this was necesary for testing. Fixes: clap-rs#88
@@ -70,8 +70,21 @@ pub mod log; | |||
pub mod tracing; | |||
|
|||
/// Logging flags to `#[command(flatten)]` into your CLI | |||
#[derive(clap::Args, Debug, Clone, Default)] | |||
#[derive(clap::Args, Debug, Clone, Default, PartialEq, Eq)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR seems to be mixing a lot of different things
- Making types support
Eq
- More
From
impls - A refactor with how the count math is done
etc
Ideally these would at least be split into individual commits
- We can track them in release notes more easily
- I can better see how all of the parts for a single change fit together
Verbosity is serialized and deserialized using the title case of the
VerbosityFilter (e.g. "Debug")
The
serde
dependency is gated behind an optional feature flag.Added conversion methods between Verbosity and VerbosityFilter to
simplify the implementation and derived PartialEq, Eq impls on
types where this was necesary for testing.
Fixes: #88