-
Notifications
You must be signed in to change notification settings - Fork 49
Description
This library is very cool and I want to use it a project. However, i'm running against a severe limitation: I can't tell which part of a filename was matched.
Consider this example: I have several match patterns (let's call them SpecEntries). They specified what I'm looking for and, optionally, what should the matched thing be remapped to. Example:
'/Documentation/': 'docs/',
'/*.html': 'docs/',
'**/Examples/SDK/': 'docs/'
In the above examples, all those patterns on the left side are remapped to a 'docs/' folder.
Now I'm using match_tree to iterate and directory and compare against the patterns specified by my SpecEntries.
-
The first issue is that the results returned by match_tree doesn't specify which pattern matched which file. I worked around this by iterating through my patterns, compile each one and calling match_files against it. Doable but inneficient (consider this an improvement request).
-
After the matches are returned I'd like to remap those paths according to the right hand side of the SpecEntry for example:
'/Documentation/foo.txt' -> 'docs/foo.txt'
'foo.html': 'docs/foo.html'
'blah/Examples/SDK/bar.txt' -> 'docs/bar.txt'
The problem is that there isn't an API that will allow me to do this. pathspec library knows which part of the path matched my specifier but it doesn't expose that information to me so I can't do this remapping. (I considered using regular expressions or fnmatch but they won't easily match pathspec's capabilities - for example no easy way to match '**')
Is it possible to expose the matching logic in the library APi so callers can implement this kind of remapping feature?