mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-16 20:50:25 +00:00
Also dump excluded links (#615)
This is a minimally invasive version, which allows to grep for `[excluded]`. The reason for exclusion would require more work and it's debatable if it adds any value, because it might make grepping harder and the source of exclusion is easily deducatable from the commandline parameters or the `.lycheeignore` file. Fixes #587.
This commit is contained in:
parent
b0136683a9
commit
b40c785b64
3 changed files with 49 additions and 10 deletions
3
fixtures/TEST_DUMP_EXCLUDE.txt
vendored
Normal file
3
fixtures/TEST_DUMP_EXCLUDE.txt
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
https://example.com
|
||||
https://example.org
|
||||
https://example.com/foo/bar
|
||||
|
|
@ -18,15 +18,18 @@ where
|
|||
while let Some(request) = requests.next().await {
|
||||
let request = request?;
|
||||
|
||||
if params.client.is_excluded(&request.uri) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Avoid panic on broken pipe.
|
||||
// See https://github.com/rust-lang/rust/issues/46016
|
||||
// This can occur when piping the output of lychee
|
||||
// to another program like `grep`.
|
||||
if let Err(e) = write(&request, params.cfg.verbose) {
|
||||
|
||||
let excluded = params.client.is_excluded(&request.uri);
|
||||
let verbose = params.cfg.verbose;
|
||||
|
||||
if excluded && !verbose {
|
||||
continue;
|
||||
}
|
||||
if let Err(e) = write(&request, verbose, excluded) {
|
||||
if e.kind() != io::ErrorKind::BrokenPipe {
|
||||
eprintln!("{e}");
|
||||
return Ok(ExitCode::UnexpectedFailure);
|
||||
|
|
@ -38,13 +41,17 @@ where
|
|||
}
|
||||
|
||||
/// Dump request to stdout
|
||||
/// Only print source in verbose mode. This way the normal link output
|
||||
/// can be fed into another tool without data mangling.
|
||||
fn write(request: &Request, verbose: bool) -> io::Result<()> {
|
||||
let output = if verbose {
|
||||
fn write(request: &Request, verbose: bool, excluded: bool) -> io::Result<()> {
|
||||
let request = if verbose {
|
||||
// Only print source in verbose mode. This way the normal link output
|
||||
// can be fed into another tool without data mangling.
|
||||
request.to_string()
|
||||
} else {
|
||||
request.uri.to_string()
|
||||
};
|
||||
writeln!(io::stdout(), "{}", output)
|
||||
if excluded {
|
||||
writeln!(io::stdout(), "{} [excluded]", request)
|
||||
} else {
|
||||
writeln!(io::stdout(), "{}", request)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -666,4 +666,33 @@ mod cli {
|
|||
.success();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_print_excluded_links_in_verbose_mode() -> Result<()> {
|
||||
let test_path = fixtures_path().join("TEST_DUMP_EXCLUDE.txt");
|
||||
let mut cmd = main_command();
|
||||
|
||||
cmd.arg("--dump")
|
||||
.arg("--verbose")
|
||||
.arg("--exclude")
|
||||
.arg("example.com*")
|
||||
.arg("--")
|
||||
.arg(&test_path)
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(contains(format!(
|
||||
"https://example.com/ ({}) [excluded]",
|
||||
test_path.display()
|
||||
)))
|
||||
.stdout(contains(format!(
|
||||
"https://example.org/ ({})",
|
||||
test_path.display()
|
||||
)))
|
||||
.stdout(contains(format!(
|
||||
"https://example.com/foo/bar ({}) [excluded]",
|
||||
test_path.display()
|
||||
)));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue