Glob patterns to exclude directory?
I have a fairly large repository with md files spread across many directories.
So I'd like to periodically check for broken links in *.md files.
Something like lychee --verbose --no-progress **/*.md works well,
however I'd like to exclude vendor/ directory to avoid unnecessary checks.
Would something like lychee --verbose --no-progress **/*.md !./vendor/* be within scope of this project?
I thought that already works. I was wrong. We should support that, yes. If anyone wants to give it a try, comment here.
Workaround inspired from https://stackoverflow.com/a/16595367 :
lychee --verbose -- $(find . -not \( -path ./tests -prune \) -name '*.py' -print0 |xargs --null)
I'm astonished by that ingenuity.😄 It does make sense, though. Thanks for mentioning that!
thanks hehe =)
I've spent a bit of time trying to reuse that snippet in a github action with no luck. I found more useful to rm -fr the part of the code I didn't want to check then glob everything than use that snippet
Implementation-wise, this can be done with a GlobSet:
use globset::{Glob, GlobSetBuilder};
let mut builder = GlobSetBuilder::new();
// A GlobBuilder can be used to configure each glob's match semantics
// independently.
builder.add(Glob::new("**/*.md")?);
builder.add(Glob::new("!./vendor/*")?);
let set = builder.build()?;
assert_eq!(set.matches("foo.md"), vec![0, 1]);
assert_eq!(set.matches("./vendor/bar.md"), vec![0]);
So I think we can check if set.matches(input).len() == set.len().
Docs: https://docs.rs/globset/latest/globset/
"It's not a bug it's a feature." 😆
Revisiting this, I just realized there is an easier way:
lychee --exclude-path vendor --verbose --no-progress './**/*.md'
Sorry for missing that. I focused too much on the glob pattern and not the original problem. It probably won't help you anymore, but maybe someone else who runs into the same issue.
In any case we should still tackle glob exclusions at some point.
Thanks, that worked!