Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glob patterns to exclude directory? #284

Closed
mxpv opened this issue Jul 15, 2021 · 8 comments
Closed

Glob patterns to exclude directory? #284

mxpv opened this issue Jul 15, 2021 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed workaround

Comments

@mxpv
Copy link

mxpv commented Jul 15, 2021

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?

@mre
Copy link
Member

mre commented Jul 19, 2021

I thought that already works. I was wrong.
We should support that, yes. If anyone wants to give it a try, comment here.

@ajoga
Copy link

ajoga commented Aug 17, 2021

Workaround inspired from https://stackoverflow.com/a/16595367 :
lychee --verbose -- $(find . -not \( -path ./tests -prune \) -name '*.py' -print0 |xargs --null)

@mre
Copy link
Member

mre commented Aug 17, 2021

I'm astonished by that ingenuity.😄 It does make sense, though. Thanks for mentioning that!

@ajoga
Copy link

ajoga commented Aug 17, 2021

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

@mre mre added bug Something isn't working help wanted Extra attention is needed labels Sep 4, 2021
@mre
Copy link
Member

mre commented Nov 22, 2021

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/

@mre mre added enhancement New feature or request and removed bug Something isn't working labels Dec 3, 2021
@mre
Copy link
Member

mre commented Dec 3, 2021

"It's not a bug it's a feature." 😆

@mre
Copy link
Member

mre commented Nov 11, 2022

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.

@mre mre added the workaround label Nov 11, 2022
@mxpv
Copy link
Author

mxpv commented Feb 21, 2024

Thanks, that worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed workaround
Projects
None yet
Development

No branches or pull requests

3 participants