Glob goal
@goal [ goal_name ] @glob <glob pattern> [ @except <except pattern> ] [ @private ]
This one is easy to illustrate with an example:
@goal process_file @glob '*.txt'
echo $ITEM $INDEX $TOTAL
Is equivalent to declaring three goals
@goal [email protected] @private
echo a.txt 0 2
@goal [email protected] @private
echo b.txt 1 2
@goal process_file
@depends_on [email protected]
@depends_on [email protected]
iff
$ ls
a.txt b.txt
For convenience, you can omit name in case of glob goal:
@goal @glob '*.txt'
echo $ITEM $INDEX $TOTAL
as equivalent for
@goal a.txt @private
echo a.txt 0 2
@goal b.txt @private
echo b.txt 1 2
@goal '*.txt'
@depends_on a.txt
@depends_on b.txt
So essentially, one glob goal declaration expands to multiple goal declarations based on files present in a project that match the glob pattern. Shell glob expansion mechanism applies.
The useful use case here would be to represent a set of test files as a set of goals. The example could be found in the project's own build file.
Why may this be useful? Imagine in your Node.js application you have test1.js
, test2.js
, test3.js
.
Now you can use this Makesurefile
@goal @glob 'test*.js'
echo "running test file $INDEX out of $TOTAL ..."
node $ITEM
to be able to run each test individually (./makesure test2.js
for example) and all together (./makesure 'test*.js'
).
In case if you need to glob the files with spaces in their names, please check the naming rules section below.
@except
modifier can be useful to exclude some files from the @glob
coverage. Example:
@goal process @glob '*.txt' @except '*_processed.txt'
echo "processing $ITEM..."
mv "$ITEM" "${ITEM%.txt}_processed.txt"