@@ -83,56 +83,47 @@ _task "$@"
83
83
84
84
Now after running ` task shorthand ` , your ` task ` commands will get autocompleted.
85
85
86
- ## Splitting Taskfiles
86
+ ## SubTaskfiles
87
87
88
88
Have a (mono)repo with multiple projects, a group of less-used or specialized tasks or just waaay to many tasks for a
89
- single Taskfile? Splitting your Taskfiles might be for you! This allows you to divide your tasks across multiple files
90
- while still (also) calling them from a single one.
89
+ single Taskfile? Splitting your Taskfile might be for you! Using SubTaskfiles allows you to divide your tasks across
90
+ multiple files while still calling them from a single one. Most useful for splitting off a group of tasks that can be
91
+ logically grouped together, like for specific use-cases or because they are rarely used.
91
92
92
- There are two types, but in both cases tasks from the secondary Taskfile are called "via" a task in the root Taskfile,
93
- like this: ` ./Taskfile foo <task> <args> `
93
+ Example use-cases: git-hooks, frontend- / backend-specific tasks, tasks that fix (infrequently occurring) bugs, etc.
94
94
95
- ### Remote Taskfile
95
+ SubTaskfiles can't be run directly, but are always run "via" a task in the root Taskfile, like this:
96
+ ` Usage: ./Taskfile foo <task> <args> `
96
97
97
- This type is more verbose, but can be used on its own as well. Most useful in (mono)repos where people might be working
98
- in a subdirectory as often as on the project as a whole.
98
+ ### How
99
99
100
- In the main Taskfile you call the secondary like any other script :
100
+ Put this in the root Taskfile :
101
101
``` shell
102
102
function task:foo { # # bar
103
- ./path/to/secondary/Taskfile " ${@ -help} "
104
- }
105
- ```
106
-
107
- The secondary is just a regular Taskfile, including utilities (semi) optional ones like ` task:help ` , ` file:ensure ` and
108
- the required line with ` task:"${@-help}" ` at the bottom.
109
-
110
- ### SubTaskfile
111
-
112
- This type cannot be called on its own, but has a lot less boilerplate. Most useful for splitting off a group of tasks
113
- that can be logically grouped together, for specific tasks or because they are rarely used.
103
+ SUBTASKFILE_DIR=" ./path/to/subtaskfile/"
114
104
115
- In the main Taskfile:
116
- ``` shell
117
- function task:foo { # # bar
118
- SUB_TASKFILE_DIR=" ./path/to/subtaskfile/"
119
-
120
- source " $SUB_TASKFILE_DIR /Taskfile"
105
+ source " $SUBTASKFILE_DIR /SubTaskfile"
121
106
122
107
task:" ${@ -_help} "
123
108
}
109
+
110
+ # Optional: use proxy-tasks like this for tasks you want to run straight from the root Taskfile
111
+ function task:baz { # # Call `foo baz` directly
112
+ task:foo baz
113
+ }
124
114
```
125
115
126
- The subTaskfile just needs to contain the tasks and sections you need, but has a few notes:
116
+ Give SubTaskfile the filename ` SubTaskfile ` . It needs to contain only the tasks and sections you think useful (while
117
+ still having access to stuff like ` file:ensure ` from the root Taskfile!), but it has a few notes:
127
118
``` shell
128
- # When you use files in the subTaskfile's directory, you need prefix them with $SUB_TASKFILE_DIR
119
+ # When you refer to files in the subTaskfile's directory, you need prefix them with $SUBTASKFILE_DIR
129
120
function task:call-script { # # Call a script
130
- " $SUB_TASKFILE_DIR /some-script.sh"
121
+ " $SUBTASKFILE_DIR /some-script.sh"
131
122
}
132
123
133
124
# Without this, you cannot run `./Taskfile foo` or `./Taskfile foo help`
134
125
function task:_help { # # Show all available tasks
135
- task:help " $SUB_TASKFILE_DIR /Taskfile "
126
+ task:help " $SUBTASKFILE_DIR /SubTaskfile "
136
127
}
137
128
```
138
129
0 commit comments