Generalized path glob patterns that are also builders. The main idea is that an expression like
a/b/{x}.txt
can be interpreted as a pattern or a template at the same time, for example the following expressions have the following intuitive meaning
-
a/b/c.txt
corresponds to the literal filea/b/c.txt
-
{year}-{month}-{day}.txt
will match something like2023-01-20.txt
-
a/{var1}/c.txt
won't matcha/b/b/c.txt
because the capture{var1}
doesn't match/
, the equivalent is that this throws an error when used as a template andvar1
contains slashes. -
{*module}/package.json
, here the*
modifier will also match/
.
so this syntax can be used to
-
match against a given pattern and return a dictionary of captures
-
but also as a path template or builder that is given a dictionary of bindings
This duality can be used to modify paths for example. Using the provided CLI for this library we can do something like the following
echo 'blog/src/projects/go/patbu.html'
| patbu --stdin 'blog/src/{*route}/{page}.html' 'blog/dist/{*route}/{page}/index.html'
$ go build -v -o ./bin/patbu ./cmd/patbu
$ go install -v ./cmd/patbu
Other name ideas: blueprint, pathbp, template, patt
Add some flags to use as a bulk rename utility