-
Notifications
You must be signed in to change notification settings - Fork 349
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
cli: Introduce write_labeled!
template formatter macro
#4539
Conversation
66f0460
to
e185b4f
Compare
@@ -384,14 +385,14 @@ fn write_modified_change_summary( | |||
) -> Result<(), std::io::Error> { | |||
writeln!(formatter, "Change {}", short_change_hash(change_id))?; | |||
for commit in modified_change.added_commits.iter() { | |||
formatter.with_label("diff", |formatter| write!(formatter.labeled("added"), "+"))?; | |||
formatter.with_label("diff", |formatter| write_labeled!(formatter, "added", "+"))?; |
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.
Interesting one being nested. Could make the macro accept something like
formatter.with_label("diff", |formatter| write_labeled!(formatter, "added", "+"))?; | |
write_labeled!(formatter, "diff" & "added", "+")?; |
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.
label string could be separated by whitespace (and split by formatter.labeled()
), but I don't know if we like it.
@@ -775,12 +776,12 @@ fn print_error_sources(ui: &Ui, source: Option<&dyn error::Error>) -> io::Result | |||
ui.stderr_formatter() | |||
.with_label("error_source", |formatter| { | |||
if err.source().is_none() { | |||
write!(formatter.labeled("heading"), "Caused by: ")?; | |||
write_labeled!(formatter, "heading", "Caused by: ")?; |
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 like the original code because it's clearer which string literal is a label.
@@ -384,14 +385,14 @@ fn write_modified_change_summary( | |||
) -> Result<(), std::io::Error> { | |||
writeln!(formatter, "Change {}", short_change_hash(change_id))?; | |||
for commit in modified_change.added_commits.iter() { | |||
formatter.with_label("diff", |formatter| write!(formatter.labeled("added"), "+"))?; | |||
formatter.with_label("diff", |formatter| write_labeled!(formatter, "added", "+"))?; |
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.
label string could be separated by whitespace (and split by formatter.labeled()
), but I don't know if we like it.
I personally don't like the macro variant, as it doesn't improve the readability of the code. |
Fair, I am indifferent to the change so mainly opened it to see opinions. |
Mainly an experiment to see if this looks more readable / uniform.
Checklist
If applicable:
CHANGELOG.md