Parameterized goal
Make code easier to reuse.
Declaration syntax (using @params
):
@goal goal_name @params A B C
Usage syntax (using @args
):
@goal other_goal @params PARAM
@depends_on goal_name @args 'value1' 'value 2' PARAM
The idea of using two complementary keywords @params
+ @args
was inspired by async
+ await
from JavaScript.
Example:
@goal file_downloaded @params FILE_NAME
echo "Downloading $FILE_NAME..."
@goal file_processed @params FILE_NAME
@depends_on file_downloaded @args FILE_NAME
echo "Processing $FILE_NAME..."
@goal all_files_processed
@depends_on file_processed @args 'file1'
@depends_on file_processed @args 'file2'
@depends_on file_processed @args 'file3'
Having the above in Makesurefile
will produce next output when ran with ./makesure all_files_processed
:
goal 'file_downloaded@file1' ...
Downloading file1...
goal 'file_processed@file1' ...
Processing file1...
goal 'file_downloaded@file2' ...
Downloading file2...
goal 'file_processed@file2' ...
Processing file2...
goal 'file_downloaded@file3' ...
Downloading file3...
goal 'file_processed@file3' ...
Processing file3...
goal 'all_files_processed' [empty].
When listing goals, you'll see "instantiated" goals there:
$ ./makesure -l
Available goals:
all_files_processed
file_processed@file1
file_downloaded@file1
file_processed@file2
file_downloaded@file2
file_processed@file3
file_downloaded@file3
And you can even call such "instantiated" goal:
$ ./makesure file_processed@file2
goal 'file_downloaded@file2' ...
Downloading file2...
goal 'file_processed@file2' ...
Processing file2...
You can also take a look at an example from a real project.
Note, the goal's body parameter values will appear as environment variables (as if defined via export
).
Note, you can reference the @define
-ed variables in the arguments of the parameterized goals:
@define HELLO 'hello'
@goal parameterized_goal @params ARG
echo "ARG=$ARG"
@goal goal1
@depends_on parameterized_goal @args HELLO # reference by name
@depends_on parameterized_goal @args "$HELLO world" # interpolated inside string
Having the above in Makesurefile
will produce next output when ran with ./makesure goal1
:
goal 'parameterized_goal@hello' ...
ARG=hello
goal 'parameterized_goal@hello world' ...
ARG=hello world
goal 'goal1' [empty].
You can also rely on parameterized goals parameters interpolation.
Also, it's possible for a @glob
goal to be parameterized.
Please find a more real-world example here.
For more technical consideration regarding this feature see parameterized_goals.md.