-
Notifications
You must be signed in to change notification settings - Fork 277
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
Feature: allow user to disable info fields with flag --disable #82
Conversation
Merge changes from fork parent
if flag specified without value, CLI will now error out
Actually, I realized I could simplify the code a bit more by removing the default value for |
Very Impressive @ktsuench, Still, I think It would be a better user experience, if the program would not fail if the info name(s) inputed by the user is either missing or not included in the possible values.
What do you think ? |
I agree with you on that. Using my first solution we could do that by removing the set of possible values and just have unrecognized values fall back to |
Reverted my last commit and updated to allow any value but values are checked afterwards.
|
src/main.rs
Outdated
if !self.disable_fields.contains(&InfoFields::Project) { | ||
writeln!( | ||
buffer, | ||
"{}{}", | ||
"Project: ".color(color).bold(), | ||
self.project_name | ||
)?; | ||
} | ||
|
||
writeln!( | ||
buffer, | ||
"{}{}", | ||
"HEAD: ".color(color).bold(), | ||
self.current_commit | ||
)?; | ||
if !self.disable_fields.contains(&InfoFields::HEAD) { | ||
writeln!( | ||
buffer, | ||
"{}{}", | ||
"HEAD: ".color(color).bold(), | ||
self.current_commit | ||
)?; | ||
} |
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.
Running Vec::contains
multiple times is kind of computationally intensive, as each call will iterate through until finding a match. See source code here and here.
Iterating through once and keeping track bool
values might be better.
Example:
let mut no_project = false;
// etc.
for field in self.disable_fields.iter() {
match field {
InfoFields::Project => no_project = true,
// etc.
}
}
if !no_project {
// write project
}
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 decided to create a struct of bools just to make it easier to track.
…using bool struct instead
I implemented the feature using the package
Strum
to work with the newInfoFields
enum. The package allows iteration over enums and creates static str for each value in the enum essentially allowing us to create a vector of selected values from the enum (less code). In this case, I hid a enum valueUnrecognizedField
as the end user should not see that value in the output of possible values. That value is used to filter out the default value which is an empty string allowing all info fields to be shown.Use:
Overrides showing the dominant language ascii logo
Examples:
Addresses issue #73.