A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pathikrit/better-files/issues/114 below:

Cooked Glob and Regex? · Issue #114 · pathikrit/better-files · GitHub

Would it to make sense to support cooked glob and regex with better-files?

At the moment better-files glob works as:

     // root_a = basedir / "a"
     // basedir / "a" / "a1" / "t1.txt"
     // basedir / "a" / "a1" / "t2.txt"

     root_a.glob("a1/*.txt").foreach(println) => finds nothing
     root_a.glob("**/a1/*.txt").foreach(println) => finds t1, t2

With cooked glob it would be:

     root_a.glob("a1/*.txt").foreach(println) => finds t1, t2

Cooked glob or regex works so that it "cooks" basepath to wildcard (glob or regex) if following is true:

This cooked form makes it possible to write more natural glob, when at the beging there doesn't have to be cross-path component regex or glob. This especially important when these glob/regex are used on configuration files, where non-programming human has to understand how they work.

If this makes sense with better-files, I can provide PR for this feature with tests. There is an existing implementation here (I am author of SN127, so MIT licensing is not problem):

findFiles with support for cooked globs and regex:
https://github.com/sn127/utils/blob/b116036de96f7b66fba29117ce91168bf4323c45/fs/src/main/scala/fi/sn127/utils/fs/FileUtils.scala#L204

Glob-cooking:
https://github.com/sn127/utils/blob/b116036de96f7b66fba29117ce91168bf4323c45/fs/src/main/scala/fi/sn127/utils/fs/FileUtils.scala#L270

Regex-cooking:
https://github.com/sn127/utils/blob/b116036de96f7b66fba29117ce91168bf4323c45/fs/src/main/scala/fi/sn127/utils/fs/FileUtils.scala#L288

Glob-cooking tests:
https://github.com/sn127/utils/blob/b116036de96f7b66fba29117ce91168bf4323c45/fs/src/test/scala/fi/sn127/utils/fs/GlobTest.scala

Glob-findFiles tests:
https://github.com/sn127/utils/blob/b116036de96f7b66fba29117ce91168bf4323c45/fs/src/test/scala/fi/sn127/utils/fs/GlobTest.scala#L236

Glob-findFiles target:
https://github.com/sn127/utils/tree/b116036de96f7b66fba29117ce91168bf4323c45/tests/globtree

And finally here is an example how this cooked form is used in "end-product". This is DirSuite scalatest extension, which let you define your tests as inputs and output references on filesystem:

https://github.com/sn127/utils/blob/b116036de96f7b66fba29117ce91168bf4323c45/testing/src/test/scala/fi/sn127/utils/testing/DirSuiteDemo.scala#L49


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4