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

Merge args into config #110

Merged
merged 2 commits into from
May 7, 2019
Merged

Merge args into config #110

merged 2 commits into from
May 7, 2019

Conversation

epage
Copy link
Collaborator

@epage epage commented May 6, 2019

This is preparation for #93.

impl Config {
pub fn update(&mut self, source: &ConfigSource) {
if let Some(sign_commit) = source.sign_commit() {
self.sign_commit = Some(sign_commit);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just self.sign_commit = source.sign_commit().clone()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way. Another option is to encapsulate this pattern with an extension trait.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about this...

The current approach references the struct twice with the proposed referencing it three times which increases the chance of error.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is it possible to write a procedural macro for this? To avoid multiples changes required for adding new config option.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a procedural macro could help here. Maybe I'm just not familiar enough with them but it seems like a big hammer to solve this small problem.

I do want to take these lessons back to the CLI-WG discussions. It feels like the current selection of crates is too all-in-one which doesn't let us adapt for the needs of crates like this one. I'm thinking a generalized set of macros to let people layer their config as needed would be helpful for the community.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a clojure library, which I think deals this well. I'll think about the challenge to port it to static-typed language like rust.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config and configure do it to a degree but I think they both use a HashMap when merging the sources which delays error reporting to the end. My goal with this was to report the error (invalid data type, extra field, etc) with being able to tell the user where the problem came from so they could fix it.

@sunng87
Copy link
Collaborator

sunng87 commented May 7, 2019

@epage do you want to improve on this branch, or I will merge it to let the process go

@epage
Copy link
Collaborator Author

epage commented May 7, 2019

@epage do you want to improve on this branch, or I will merge it to let the process go

If you are fine with it, I'd say let's get this in and continue to iterate.

@sunng87
Copy link
Collaborator

sunng87 commented May 7, 2019

Yes.

@sunng87 sunng87 merged commit 47de162 into crate-ci:master May 7, 2019
@epage epage deleted the config branch May 7, 2019 22:55
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.

2 participants