-
-
Notifications
You must be signed in to change notification settings - Fork 7
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
main: extract a Status object to represent the final status of nixpkgs-check-by-name
#91
Conversation
Damn man your killin it today! |
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 is a nice improvement overall!
src/status.rs
Outdated
let maybe_green = |s: &str| if use_color { s.green() } else { s.normal() }; | ||
let maybe_yellow = |s: &str| if use_color { s.yellow() } else { s.normal() }; | ||
let maybe_red = |s: &str| if use_color { s.red() } else { s.normal() }; |
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 will cause it to colorise the output even if it's e.g. just a pipe to a file. So I think I prefer the previous code using NO_COLOR=1
to disable colors when testing, and https://github.com/NixOS/nixpkgs/blob/07c1a652be3a1dda9047f4d8545e17d12958a148/.github/workflows/check-by-name.yml#L113-L115 to force turn it on in CI.
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.
No, it's the same as before.
nixpkgs-check-by-name
used to unilaterally colorize by calling the .red
, .yellow
, etc methods, and in the colored
crate it would decide to actually not color based on this environment variable.
Now, it'll only call those methods if true
is passed to use_color
. ColoredStatus
does this -- see the end of the file. main
uses ColoredStatus
, and so it retains the original behavior. Tests, which use the process
method, format a Status
, which passes false
to use_color
in their display, bypassing colorization in this module itself.
I like that better because it's less action at a distance.
This object contains the actual status of `nixpkgs-check-by-name` checks.
nixpkgs-check-by-name
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.
Forgot about this, looking good, let's go!
Motivation for changes
I didn't like the mixing of error reporting (through
io::Writer
) and business logic inside theprocess
function. By extracting a Status object, the two are separated, just likeNixpkgsProblem
did on a lower level.Description of changes
Status
object which contains the actual status ofnixpkgs-check-by-name
checks.Status::fmt
method.From
impl.ColoredStatus
which is the colored version of status; it's used exclusively inmain
.NO_COLOR
environment variable and test-onlyio::Writer
.It's mildly longer (~53 more lines) due to the needed boilerplate of being a module.