You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a task, is the list of files specified in sources available for commands so it can be used as a variable?
I have a script that that I would like to pass the list of sources available to:
Reacted by Stéphane Archer, Hernan Garcia, William Orr, James Lucktaylor, Hans Donner, Marko Bausch, Jacob Wang, Alex Davidson Bryan, Mandeep Gill, Chris and 13 more
This indeed makes sense, because we already have other special variables like TASK, TIMESTAMP and CHECKSUM.
Implementation note: this variable should probably be an array (slice) because them users will have more flexibility on what to do with it (join with space or ,, loop through it, or other). TIMESTAMP is already of a different type (time.Time).
I think this might help with a use-case I'm looking at now.
I discover go.mod files and put the results into a GO_MODULES variable at the top level of Taskfile.yaml.
Then there are tasks using cmds.for.var to execute something in each of the GO_MODULES directories.
I would like the tasks to be able to look at sources with globs relative to each of the GO_MODULES items as each iteration of the for loops run.
edit: never mind, a colleague came up with a pattern for what I want to do that works quite well as-is:
do-thing:singular:
desc: Run a single thing
requires:
vars:
- THING
sources:
- 'subdir/{{.THING}}/**/*.{go,mod,sum}'
cmds:
- task: gotest
vars:
GOTESTVAR: './subdir/{{.THING}}/...'
do-thing:plural:
desc: Run several things
requires:
vars:
- THINGS
cmds:
- for: { var: THINGS }
task: do-thing:singular
vars:
THING: '{{.ITEM}}'
Task seems great but I'm very surprised this is not yet possible for a tool that aims to replace GNU Make.
So many of my Make recipes use $^ variable and I don't see any way to migrate to Task before this is implemented.
Do you have any workaround when you need to pass the whole list of sources to a command of a rule at the same time (and not one by one which I saw is possible with the for keyword) ?
I was just wandering about this (just like @Cheekie25, I often use/used the (cryptic) shorthand notation in make).
I guess it would make sense to add the variable TASK_SOURCES but I thought of a "workaround" that seems
actually less error prone[1]:
Defining the source and generated files as variables first
and then add the variables in sources/generates respectivly.
[1] The variable TASK_SOURCE would probably just be an array, so the position of the source files in the list would matter. This workaround names each source so it is not dependent on the order.
The best of both worlds would be if you could define sources/generates as associative arrays, i.e. the sources/generates
would define variables without the extra step through vars.
Note that any solution or workaround needs to be able to handle filenames with whitespace. The user needs to be able to pass an array of strings to a command to be executed, without the unpleasant surprise of seeing arguments further split by whitespace.
Activity
andreynering commentedon Dec 6, 2022
Hi @NVolcz,
This indeed makes sense, because we already have other special variables like
TASK,TIMESTAMPandCHECKSUM.Implementation note: this variable should probably be an array (slice) because them users will have more flexibility on what to do with it (join with space or
,, loop through it, or other).TIMESTAMPis already of a different type (time.Time).jlucktay commentedon Oct 4, 2023
I think this might help with a use-case I'm looking at now.
I discover
go.modfiles and put the results into aGO_MODULESvariable at the top level of Taskfile.yaml.Then there are tasks using
cmds.for.varto execute something in each of theGO_MODULESdirectories.I would like the tasks to be able to look at
sourceswith globs relative to each of theGO_MODULESitems as each iteration of theforloops run.edit: never mind, a colleague came up with a pattern for what I want to do that works quite well as-is:
callegar commentedon Jun 4, 2024
Wonder if this is the only possible solution. May I suggest:
IMHO this would be more flexible since it would let any variable be usable based on filename expansion.
feat: add TASK_SOURCES special variable
feat: add TASK_SOURCES special variable
Cheekie25 commentedon Nov 21, 2025
Hello.
Task seems great but I'm very surprised this is not yet possible for a tool that aims to replace GNU Make.
So many of my Make recipes use $^ variable and I don't see any way to migrate to Task before this is implemented.
Do you have any workaround when you need to pass the whole list of sources to a command of a rule at the same time (and not one by one which I saw is possible with the for keyword) ?
Thanks
LuckyJosh commentedon Dec 8, 2025
I was just wandering about this (just like @Cheekie25, I often use/used the (cryptic) shorthand notation in make).
I guess it would make sense to add the variable
TASK_SOURCESbut I thought of a "workaround" that seemsactually less error prone[1]:
Defining the source and generated files as variables first
and then add the variables in
sources/generatesrespectivly.My minimal working example:
[1] The variable
TASK_SOURCEwould probably just be an array, so the position of the source files in the list would matter. This workaround names each source so it is not dependent on the order.The best of both worlds would be if you could define
sources/generatesas associative arrays, i.e. thesources/generateswould define variables without the extra step through
vars.feat: add TASK_SOURCES special variable
feat: add TASK_SOURCES special variable
feat: add TASK_SOURCES special variable
trulede commentedon Apr 26, 2026
I think this issue would be resolved by #2671.
Flimm commentedon Jun 18, 2026
Note that any solution or workaround needs to be able to handle filenames with whitespace. The user needs to be able to pass an array of strings to a command to be executed, without the unpleasant surprise of seeing arguments further split by whitespace.