Skip to content

Commit f2034a9

Browse files
committed
Also dump excluded links
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.
1 parent 4690cc0 commit f2034a9

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

fixtures/TEST_DUMP_EXCLUDE.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://example.com
2+
https://example.org
3+
https://example.com/foo/bar

lychee-bin/src/commands/dump.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ where
1818
while let Some(request) = requests.next().await {
1919
let request = request?;
2020

21-
if params.client.is_excluded(&request.uri) {
22-
continue;
23-
}
24-
2521
// Avoid panic on broken pipe.
2622
// See https://github.com/rust-lang/rust/issues/46016
2723
// This can occur when piping the output of lychee
2824
// to another program like `grep`.
29-
if let Err(e) = write(&request, params.cfg.verbose) {
25+
26+
let excluded = params.client.is_excluded(&request.uri);
27+
let verbose = params.cfg.verbose;
28+
29+
if excluded && !verbose {
30+
continue;
31+
}
32+
if let Err(e) = write(&request, verbose, excluded) {
3033
if e.kind() != io::ErrorKind::BrokenPipe {
3134
eprintln!("{e}");
3235
return Ok(ExitCode::UnexpectedFailure);
@@ -38,13 +41,17 @@ where
3841
}
3942

4043
/// Dump request to stdout
41-
/// Only print source in verbose mode. This way the normal link output
42-
/// can be fed into another tool without data mangling.
43-
fn write(request: &Request, verbose: bool) -> io::Result<()> {
44-
let output = if verbose {
44+
fn write(request: &Request, verbose: bool, excluded: bool) -> io::Result<()> {
45+
let request = if verbose {
46+
// Only print source in verbose mode. This way the normal link output
47+
// can be fed into another tool without data mangling.
4548
request.to_string()
4649
} else {
4750
request.uri.to_string()
4851
};
49-
writeln!(io::stdout(), "{}", output)
52+
if excluded {
53+
writeln!(io::stdout(), "{} [excluded]", request)
54+
} else {
55+
writeln!(io::stdout(), "{}", request)
56+
}
5057
}

lychee-bin/tests/cli.rs

+29
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,33 @@ mod cli {
659659
.success();
660660
Ok(())
661661
}
662+
663+
#[test]
664+
fn test_print_excluded_links_in_verbose_mode() -> Result<()> {
665+
let test_path = fixtures_path().join("TEST_DUMP_EXCLUDE.txt");
666+
let mut cmd = main_command();
667+
668+
cmd.arg("--dump")
669+
.arg("--verbose")
670+
.arg("--exclude")
671+
.arg("example.com*")
672+
.arg("--")
673+
.arg(&test_path)
674+
.assert()
675+
.success()
676+
.stdout(contains(format!(
677+
"https://example.com/ ({}) [excluded]",
678+
test_path.display()
679+
)))
680+
.stdout(contains(format!(
681+
"https://example.org/ ({})",
682+
test_path.display()
683+
)))
684+
.stdout(contains(format!(
685+
"https://example.com/foo/bar ({}) [excluded]",
686+
test_path.display()
687+
)));
688+
689+
Ok(())
690+
}
662691
}

0 commit comments

Comments
 (0)