mirror of
https://github.com/Hopiu/lychee.git
synced 2026-05-11 15:23:11 +00:00
Cache verbosity issue (fixes #562)
This commit is contained in:
parent
743d386252
commit
36d3195c68
2 changed files with 44 additions and 8 deletions
|
|
@ -70,7 +70,7 @@ where
|
|||
let verbose = cfg.verbose;
|
||||
async move {
|
||||
while let Some(response) = recv_resp.recv().await {
|
||||
show_progress(&pb, &response, verbose)?;
|
||||
show_progress(&mut io::stdout(), &pb, &response, verbose)?;
|
||||
stats.add(response);
|
||||
}
|
||||
Ok((pb, stats))
|
||||
|
|
@ -143,6 +143,7 @@ async fn handle(client: &Client, cache: Arc<Cache>, request: Request) -> Respons
|
|||
}
|
||||
|
||||
fn show_progress(
|
||||
output: &mut dyn Write,
|
||||
progress_bar: &Option<ProgressBar>,
|
||||
response: &Response,
|
||||
verbose: bool,
|
||||
|
|
@ -155,10 +156,36 @@ fn show_progress(
|
|||
pb.println(out);
|
||||
}
|
||||
} else {
|
||||
if (response.status().is_success() || response.status().is_excluded()) && !verbose {
|
||||
return Ok(());
|
||||
#[allow(clippy::collapsible_if)]
|
||||
if !verbose {
|
||||
if response.status().is_success() || response.status().is_excluded() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
writeln!(io::stdout(), "{out}")?;
|
||||
writeln!(output, "{out}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use lychee_lib::{CacheStatus, InputSource, ResponseBody, Uri};
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_skip_cached_responses_in_progress_output() {
|
||||
let mut buf = Vec::new();
|
||||
let response = Response(
|
||||
InputSource::Stdin,
|
||||
ResponseBody {
|
||||
uri: Uri::try_from("http://127.0.0.1").unwrap(),
|
||||
status: Status::Cached(CacheStatus::Ok(200)),
|
||||
},
|
||||
);
|
||||
show_progress(&mut buf, &None, &response, false).unwrap();
|
||||
|
||||
println!("{:?}", String::from_utf8_lossy(&buf));
|
||||
assert!(buf.is_empty());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,21 +88,27 @@ impl Status {
|
|||
#[must_use]
|
||||
/// Returns `true` if the check was successful
|
||||
pub const fn is_success(&self) -> bool {
|
||||
matches!(self, Status::Ok(_))
|
||||
matches!(self, Status::Ok(_) | Status::Cached(CacheStatus::Ok(_)))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
/// Returns `true` if the check was not successful
|
||||
pub const fn is_failure(&self) -> bool {
|
||||
matches!(self, Status::Error(_))
|
||||
matches!(
|
||||
self,
|
||||
Status::Error(_) | Status::Cached(CacheStatus::Error(_))
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
/// Returns `true` if the check was excluded
|
||||
pub const fn is_excluded(&self) -> bool {
|
||||
matches!(self, Status::Excluded)
|
||||
matches!(
|
||||
self,
|
||||
Status::Excluded | Status::Cached(CacheStatus::Excluded)
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -116,7 +122,10 @@ impl Status {
|
|||
#[must_use]
|
||||
/// Returns `true` if a URI is unsupported
|
||||
pub const fn is_unsupported(&self) -> bool {
|
||||
matches!(self, Status::Unsupported(_))
|
||||
matches!(
|
||||
self,
|
||||
Status::Unsupported(_) | Status::Cached(CacheStatus::Unsupported)
|
||||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
|
|||
Loading…
Reference in a new issue