You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, that fails when you try to use filter.FilesWithExtensions with filter.Keep, e.g., to keep only ".xyz" files:
filter.Keep(filter.FilesWithExtensions(".xyz"))
That fails because none of the directories are kept, so / is not included.
Need to think about how to best resolve this. Some options are to do nothing at all, to document this, to remove FilesWithExtensions (or turn it into a documentation example), to change FilesWithExtensions or to change Keep/Skip.
The text was updated successfully, but these errors were encountered:
I wrote this code (yes, I'm embedding the source code into Go binary!):
varFS=filter.Keep(http.Dir("github.com/some/project"), func(pathstring, fi os.FileInfo) bool {
ifstrings.HasSuffix(path, ".go") &&!strings.HasSuffix(path, "_test.go") {
returntrue
}
iffi.IsDir() {
// This condition is missing in filter.FilesWithExtensions() and causes// vfsgen.Generate() to fail, since it can't walk a FS with no directoriesreturntrue
}
returnfalse
})
which adds directories to theFS, so vfsgen can walk all its files.
But, this actually add all the directories from the project, including those that didn't have any files matching the desired extensions (ie. thousands of /.git/objects/* directories!).
@slimsag The above proposal filter.And(filter.AllDirs(), filter.FilesWithExtensions(".xyz")) would suffer from the same issue.
I think we have two options:
Introduce filter.KeepWithDirs() that would return directories for all the "kept" files.
Introduce filter.FilesWithExtensionsAndDirs(".xyz") (I know, this func name is silly)
An issue that @VojtechVitek made me aware of is that
FilesWithExtensions
does not work well withfilter.Keep
.When we created it (/cc @slimsag @neelance), we had
filter.Skip
usage in mind, e.g., to skip.html
and.go
files (but not folders), one could do:And it'd do what you'd expect.
However, that fails when you try to use
filter.FilesWithExtensions
withfilter.Keep
, e.g., to keep only ".xyz" files:That fails because none of the directories are kept, so
/
is not included.Need to think about how to best resolve this. Some options are to do nothing at all, to document this, to remove
FilesWithExtensions
(or turn it into a documentation example), to changeFilesWithExtensions
or to changeKeep
/Skip
.The text was updated successfully, but these errors were encountered: