-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Finished color refactor #1824
Finished color refactor #1824
Conversation
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 looks good so far, but I'd like to test it on Windows once you make it build to make sure it actually does work.
Do we really want to make the coloring facilities public? Maybe limit this API to Error
and ColorChoice
?
Another thought: do we really need to panic if coloring fails? Maybe just ignore the error and try to write uncolored? |
6f8c2ba
to
529f863
Compare
This is ready. I haven't made them public at all. Also panics are io::write default stuff. |
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.
Feel free to address/ignore to_string
spam, my concerns are:
fn exit(&mut self) -> !
- no real need for it to be mutpub
where it doesn't belong - or does it?- Panicking on failed
set_color
55dde33
to
8df109b
Compare
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.
Almost ready 😛
src/parse/matches/arg_matches.rs
Outdated
@@ -331,17 +331,21 @@ impl ArgMatches { | |||
pub fn value_of_t<R>(&self, name: &str) -> Result<R, Error> | |||
where | |||
R: FromStr, | |||
<R as FromStr>::Err: Display, | |||
<R as FromStr>::Err: Display + Debug, |
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.
Why do we need Debug
here?
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.
Because of parsed.expect
below.
src/parse/matches/arg_matches.rs
Outdated
if let Err(e) = parsed { | ||
Err(Error::value_validation_auto(&format!( | ||
"The argument '{}' isn't a valid value: {}", | ||
v, e | ||
)) | ||
}) | ||
))?) | ||
} else { | ||
Ok(parsed.expect(INTERNAL_ERROR_MSG)) | ||
} |
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.
You can use match
instead of if let Err {} else { unwrap }
.
Btw, you can just .map_err
here.
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.
map_err
doesn't work because Error::value_validation_auto
returns a Result
and using the ?
gives:
the `?` operator can only be used in a closure that returns `Result` or `Option` (or another type that implements `std::ops::Try`)
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.
Than use Result::or_else
which is made exactly for this situation.
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 kind of think this situation when creating an error - not displaying! - can return io::Error
is rather unfortunate. I''' be seeing into this further, but not blocker for this PR.
src/parse/matches/arg_matches.rs
Outdated
@@ -378,7 +382,7 @@ impl ArgMatches { | |||
pub fn value_of_t_or_exit<R>(&self, name: &str) -> R | |||
where | |||
R: FromStr, | |||
<R as FromStr>::Err: Display, | |||
<R as FromStr>::Err: Display + Debug, |
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.
Another debug
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.
Because of forwarding it to value_of_t
src/parse/matches/arg_matches.rs
Outdated
if let Err(e) = parsed { | ||
Err(Error::value_validation_auto(&format!( | ||
"The argument '{}' isn't a valid value: {}", | ||
v, e | ||
)) | ||
}) | ||
))?) | ||
} else { | ||
Ok(parsed.expect(INTERNAL_ERROR_MSG)) | ||
} |
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.
Yet another candidate for map_err
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.
Explained the reason above
src/parse/matches/arg_matches.rs
Outdated
@@ -466,7 +474,7 @@ impl ArgMatches { | |||
pub fn values_of_t_or_exit<R>(&self, name: &str) -> Vec<R> | |||
where | |||
R: FromStr, | |||
<R as FromStr>::Err: Display, | |||
<R as FromStr>::Err: Display + Debug, |
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.
Debug
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.
Because of forwarding to values_of_t
and because values_of_t
has parsed.expect
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.
bors r+
Build succeeded: |
No description provided.