Skip to content

Commit b40c785

Browse files
authored
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.
1 parent b013668 commit b40c785

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
@@ -666,4 +666,33 @@ mod cli {
666666
.success();
667667
Ok(())
668668
}
669+
670+
#[test]
671+
fn test_print_excluded_links_in_verbose_mode() -> Result<()> {
672+
let test_path = fixtures_path().join("TEST_DUMP_EXCLUDE.txt");
673+
let mut cmd = main_command();
674+
675+
cmd.arg("--dump")
676+
.arg("--verbose")
677+
.arg("--exclude")
678+
.arg("example.com*")
679+
.arg("--")
680+
.arg(&test_path)
681+
.assert()
682+
.success()
683+
.stdout(contains(format!(
684+
"https://example.com/ ({}) [excluded]",
685+
test_path.display()
686+
)))
687+
.stdout(contains(format!(
688+
"https://example.org/ ({})",
689+
test_path.display()
690+
)))
691+
.stdout(contains(format!(
692+
"https://example.com/foo/bar ({}) [excluded]",
693+
test_path.display()
694+
)));
695+
696+
Ok(())
697+
}
669698
}

0 commit comments

Comments
 (0)