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

Add exclude option #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ascarter
Copy link

Added --exclude option that mimics ctag's exclude flag. The pattern is expected to be a shell glob pattern (which is what Go's filepath.Match method expects). It can be set multiple times to set several filters. Once the file list is built, the patterns will be applied to each file to filter out any names that match the exclude patterns before processing.

@jstemmer
Copy link
Owner

jstemmer commented Aug 3, 2015

Thanks, this is a nice feature to add.

I've had some trouble trying to match subdirectories in a long path. It looks like this is because filepath.Match does not handle the ** wildcard to match multiple directories in a row, which makes it less useful on directory matching unfortunately.

I've got a few minor comments I'll leave inline, other than that it looks good. If you could fix those and squash your commits I'll merge it.

}
}

func TestRecursiveExcludes(t *testing.T) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can be removed. I don't have Go installed in that directory (the test doesn't fail in that case btw), so it's not so useful. For now, I trust the implementation of filepath.Match and the previous tests should be enough to test that it's being used correctly.

@jstemmer
Copy link
Owner

jstemmer commented Aug 3, 2015

I see you opened issue golang/go#11862 in the Go project regarding the ** wildcard. I'll keep an eye on it.

Added --exclude option that mimics ctag's exclude flag. The pattern is expected to be a shell glob pattern (which is what Go's filepath.Match method expects). It can be set multiple times to set several filters. Once the file list is built, the patterns will be applied to each file to filter out any names that match the exclude patterns before processing.

Note: Glob pattern '**' does not work recursively. See open issue golang/go#11862
@ascarter
Copy link
Author

ascarter commented Aug 5, 2015

Changes made and squashed commits

@ascarter
Copy link
Author

ascarter commented Oct 5, 2015

@jstemmer Just wanted to remind you that this is ready to go.

@ascarter
Copy link
Author

Thanks - no worries. Looks like the feature request for the glob handling ** is being implemented too. I think it should just work when it lands but will be sure to test it when it does.

@wobbol
Copy link

wobbol commented Feb 8, 2019

the double star glob seems to have been rejected from the go-stdlib
I propose to use regex.MatchString() with a path conversion filepath.ToSlash(), instead of filepath.Match().
filepath.ToSlash() will keep the exclude regex consistent across platforms.
regex.MatchString() will sidestep the issue of not being able to match a file after traversing an arbitrary number of directories.
The drawbacks are:
The regular expressions won't look as pretty.
Directory names and file names are not distinguishable.

here's a self contained example of what I am proposing.
https://gist.github.com/wobbol/e60d0bf27cc6fa255bde1864b3513645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants