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

Feature request expose what "pattern" is passed to getPathMatcher (glob function) #32

Closed
benjamin-asdf opened this issue Oct 19, 2021 · 4 comments

Comments

@benjamin-asdf
Copy link
Contributor

I found myself wanting to put "regex" pattern instead of "glob".
Cheers.

@borkdude
Copy link
Contributor

borkdude commented Oct 19, 2021

@benjamin-asdf Is your use case to pass "regex:foo" or pass a #"foo" object? Can you give some examples of how you would like to use things?

@benjamin-asdf
Copy link
Contributor Author

benjamin-asdf commented Oct 19, 2021

@borkdude I guess a function like fs/match and there I can pass a string like "regex:foo", or any other according to https://docs.oracle.com/javase/7/docs/api/java/nio/file/FileSystem.html#getPathMatcher(java.lang.String).
And fs/glob is then a wrapper like

(defn glob [patt]
  (match (str "glob:" patt)))

pros:

  • open to additions in pathMatcher
  • obvious usage from reading getPathMatcher doc

example

(fs/match
 "dir"
 "regex:.*/subdir/.*\\.json")

(fs/match
 "dir"
 "glob:*.json")

;still works
(fs/glob
 "dir"
 "*.json")

@borkdude
Copy link
Contributor

@benjamin-asdf I added this exactly like you described it.

@borkdude
Copy link
Contributor

@benjamin-asdf Worth mentioning that you can use this library from source in babashka if you add it to your deps and load it with :reload:

$ bb -cp src -e "(ns foo (:require [babashka.fs :as fs] :reload))" -e '(fs/match "." "regex:README.*")'
[#object[sun.nio.fs.UnixPath 0x1256d66e "README.md"]]

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

No branches or pull requests

2 participants