-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
switch from termcolor
to anstream
and anstyle
#737
Changes from 2 commits
bdc8b94
a48d569
76a13fa
46179f8
b21b96f
08bb372
59dc0b2
1ad3dc3
45fa121
3a6f5bf
735600e
f043188
0022148
dd0207b
a08265b
e762fa5
250ec9a
0cc2a90
43c3358
0abdff0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
use std::{collections::BTreeMap, sync::Arc, time::Instant}; | ||
|
||
use anstream::{eprintln, println}; | ||
use anstyle::{AnsiColor, Color, Reset, Style}; | ||
|
||
use anyhow::Context; | ||
use clap::crate_version; | ||
use itertools::Itertools; | ||
use rayon::prelude::*; | ||
use termcolor::Color; | ||
use termcolor_output::{colored, colored_ln}; | ||
use trustfall::TransparentValue; | ||
use trustfall_rustdoc::{VersionedCrate, VersionedIndexedCrate, VersionedRustdocAdapter}; | ||
|
||
|
@@ -157,39 +158,35 @@ pub(super) fn run_check_release( | |
let mut results_with_errors = vec![]; | ||
for (semver_query, time_to_decide, results) in all_results { | ||
config | ||
.log_verbose(|config| { | ||
.log_verbose(|_| { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the callbacks will need config anymore, so we could (1) make the methods There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be a good idea to let the Imagine a user is using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a little bit lost. When someone uses @epage IIRC, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Not configure separate stdout/stderr, just give them the option to redirect the cargo-semver-checks-as-library output to a buffer (or drop it altogether) instead of having it printed to their app's stdout/stderr.
Not worth adding here, let's optimize this PR for being easy to review and merge. We can add that in the future, I just wanted to not remove that option from us. If this PR can make sure to print to the configured |
||
let category = match semver_query.required_update { | ||
RequiredSemverUpdate::Major => "major", | ||
RequiredSemverUpdate::Minor => "minor", | ||
}; | ||
if results.is_empty() { | ||
colored_ln(config.stderr(), |w| { | ||
colored!( | ||
w, | ||
"{}{}{:>12}{} [{:>8.3}s] {:^18} {}", | ||
fg!(Some(Color::Green)), | ||
bold!(true), | ||
"PASS", | ||
reset!(), | ||
time_to_decide.as_secs_f32(), | ||
category, | ||
semver_query.id, | ||
) | ||
})?; | ||
eprintln!( | ||
"{}{:>12}{} [{:8.3}s] {:^18} {}", | ||
Style::new() | ||
.fg_color(Some(Color::Ansi(AnsiColor::Green))) | ||
.bold(), | ||
"PASS", | ||
Reset, | ||
time_to_decide.as_secs_f32(), | ||
category, | ||
semver_query.id | ||
); | ||
} else { | ||
colored_ln(config.stderr(), |w| { | ||
colored!( | ||
w, | ||
"{}{}{:>12}{} [{:>8.3}s] {:^18} {}", | ||
fg!(Some(Color::Red)), | ||
bold!(true), | ||
"FAIL", | ||
reset!(), | ||
time_to_decide.as_secs_f32(), | ||
category, | ||
semver_query.id, | ||
) | ||
})?; | ||
eprintln!( | ||
"{}{:>12}{} [{:>8.3}s] {:^18} {}", | ||
Style::new() | ||
.fg_color(Some(Color::Ansi(AnsiColor::Red))) | ||
.bold(), | ||
"FAIL", | ||
Reset, | ||
time_to_decide.as_secs_f32(), | ||
category, | ||
semver_query.id | ||
); | ||
} | ||
Ok(()) | ||
}) | ||
|
@@ -211,7 +208,7 @@ pub(super) fn run_check_release( | |
results_with_errors.len(), | ||
skipped_queries, | ||
), | ||
Color::Red, | ||
Color::Ansi(AnsiColor::Red), | ||
true, | ||
) | ||
.expect("print failed"); | ||
|
@@ -221,68 +218,54 @@ pub(super) fn run_check_release( | |
for (semver_query, results) in results_with_errors { | ||
required_versions.push(semver_query.required_update); | ||
config | ||
.log_info(|config| { | ||
colored_ln(config.stdout(), |w| { | ||
colored!( | ||
w, | ||
"\n--- failure {}: {} ---\n", | ||
&semver_query.id, | ||
&semver_query.human_readable_name, | ||
) | ||
})?; | ||
.log_info(|_| { | ||
println!( | ||
"\n--- failure {}: {} ---\n", | ||
&semver_query.id, &semver_query.human_readable_name | ||
); | ||
Ok(()) | ||
}) | ||
.expect("print failed"); | ||
|
||
if let Some(ref_link) = semver_query.reference_link.as_deref() { | ||
config.log_info(|config| { | ||
colored_ln(config.stdout(), |w| { | ||
colored!( | ||
w, | ||
"{}Description:{}\n{}\n{:>12} {}\n{:>12} {}\n", | ||
bold!(true), | ||
reset!(), | ||
&semver_query.error_message, | ||
"ref:", | ||
ref_link, | ||
"impl:", | ||
format!( | ||
"https://github.com/obi1kenobi/cargo-semver-checks/tree/v{}/src/lints/{}.ron", | ||
crate_version!(), | ||
semver_query.id, | ||
) | ||
config.log_info(|_| { | ||
println!("{}Description:{}\n{}\n{:>12} {}\n{:>12} {}\n", | ||
Style::new().bold(), Reset, | ||
&semver_query.error_message, | ||
"ref:", | ||
ref_link, | ||
"impl:", | ||
format!( | ||
"https://github.com/obi1kenobi/cargo-semver-checks/tree/v{}/src/lints/{}.ron", | ||
crate_version!(), | ||
semver_query.id, | ||
) | ||
})?; | ||
); | ||
Ok(()) | ||
}) | ||
.expect("print failed"); | ||
} else { | ||
config.log_info(|config| { | ||
colored_ln(config.stdout(), |w| { | ||
colored!( | ||
w, | ||
"{}Description:{}\n{}\n{:>12} {}\n", | ||
bold!(true), | ||
reset!(), | ||
&semver_query.error_message, | ||
"impl:", | ||
format!( | ||
"https://github.com/obi1kenobi/cargo-semver-checks/tree/v{}/src/lints/{}.ron", | ||
crate_version!(), | ||
semver_query.id, | ||
) | ||
config.log_info(|_| { | ||
println!( | ||
"{}Description:{}\n{}\n{:>12} {}\n", | ||
Style::new().bold(), | ||
Reset, | ||
&semver_query.error_message, | ||
"impl:", | ||
format!( | ||
"https://github.com/obi1kenobi/cargo-semver-checks/tree/v{}/src/lints/{}.ron", | ||
crate_version!(), | ||
semver_query.id, | ||
) | ||
})?; | ||
); | ||
Ok(()) | ||
}) | ||
.expect("print failed"); | ||
} | ||
|
||
config | ||
.log_info(|config| { | ||
colored_ln(config.stdout(), |w| { | ||
colored!(w, "{}Failed in:{}", bold!(true), reset!()) | ||
})?; | ||
.log_info(|_| { | ||
println!("{}Failed in:{}", Style::new().bold(), Reset); | ||
Ok(()) | ||
}) | ||
.expect("print failed"); | ||
|
@@ -300,38 +283,28 @@ pub(super) fn run_check_release( | |
.context("Error instantiating semver query template.") | ||
.expect("could not materialize template"); | ||
config | ||
.log_info(|config| { | ||
colored_ln(config.stdout(), |w| colored!(w, " {}", message,))?; | ||
.log_info(|_| { | ||
println!(" {}", message); | ||
Ok(()) | ||
}) | ||
.expect("print failed"); | ||
|
||
config | ||
.log_extra_verbose(|config| { | ||
colored_ln(config.stdout(), |w| { | ||
let serde_pretty = serde_json::to_string_pretty(&pretty_result) | ||
.expect("serde failed"); | ||
let indented_serde = serde_pretty | ||
.split('\n') | ||
.map(|line| format!(" {line}")) | ||
.join("\n"); | ||
colored!(w, " lint rule output values:\n{}", indented_serde) | ||
}) | ||
.map_err(|e| e.into()) | ||
.log_extra_verbose(|_| { | ||
let serde_pretty = | ||
serde_json::to_string_pretty(&pretty_result).expect("serde failed"); | ||
let indented_serde = serde_pretty | ||
.split('\n') | ||
.map(|line| format!(" {line}")) | ||
.join("\n"); | ||
println!("\tlint rule output values:\n{}", indented_serde); | ||
Ok(()) | ||
}) | ||
.expect("print failed"); | ||
} else { | ||
config | ||
.log_info(|config| { | ||
colored_ln(config.stdout(), |w| { | ||
colored!( | ||
w, | ||
"{}\n", | ||
serde_json::to_string_pretty(&pretty_result) | ||
.expect("serde failed"), | ||
) | ||
}) | ||
.expect("print failed"); | ||
.log_info(|_| { | ||
println!("{}\n", serde_json::to_string_pretty(&pretty_result)?); | ||
Ok(()) | ||
}) | ||
.expect("print failed"); | ||
|
@@ -362,7 +335,7 @@ pub(super) fn run_check_release( | |
.filter(|x| *x == &RequiredSemverUpdate::Minor) | ||
.count(), | ||
), | ||
Color::Red, | ||
Color::Ansi(AnsiColor::Red), | ||
true, | ||
) | ||
.expect("print failed"); | ||
|
@@ -382,7 +355,7 @@ pub(super) fn run_check_release( | |
queries_to_run.len(), | ||
skipped_queries, | ||
), | ||
Color::Green, | ||
Color::Ansi(AnsiColor::Green), | ||
true, | ||
) | ||
.expect("print failed"); | ||
|
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.