-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
Generate option value derivations in the rust parser. #20535
Conversation
@@ -200,20 +199,28 @@ pub enum Source { | |||
|
|||
#[derive(Debug)] | |||
pub struct OptionValue<T> { | |||
pub derivation: Option<Vec<(Source, T)>>, | |||
// Scalar options are always set from a single source, so we provide that |
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.
Just documenting why we have this here but not for list or dict-valued options. We could also get rid of it, but it is slightly useful in error messages.
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.
Just confirming my understanding: source
is the same as the last source in derivation
(if that is Some
), right?
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.
Correct - it's broken out here because derivation may not be set, and we were already using it prior in a handful of user-facing messages.
pub source: Source, | ||
pub value: T, | ||
} | ||
|
||
impl<T> Deref for OptionValue<T> { |
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 prefer to be explicit about which field we're accessing.
Most of the diff lines are the added testing. |
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.
Nice tests!
@@ -200,20 +199,28 @@ pub enum Source { | |||
|
|||
#[derive(Debug)] | |||
pub struct OptionValue<T> { | |||
pub derivation: Option<Vec<(Source, T)>>, | |||
// Scalar options are always set from a single source, so we provide that |
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.
Just confirming my understanding: source
is the same as the last source in derivation
(if that is Some
), right?
("key1".to_string(), Val::Int(1)), | ||
("key2".to_string(), Val::String("val2".to_string())), | ||
]), | ||
hashmap! { |
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.
maplit
looks nice 👍
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, I was googling "macro for hashmap literals" and it turned out we already had one we were using elsewhere.
We use these to show the source of option values in help output.
The derivations can be a lot of data, so we only produce them
if asked to.
Note that the derivations currently only show the source type
(args, env, config, default) but not, for example, which config
file a value came from. A future change may add this, but it
will require some changes to the Source enum which are out
of scope for this PR.
Also: use maplit for easy hashmap literals in the test.