@@ -56,7 +56,8 @@ Lines with only a single `#` will not appear as section in `task:help` and can b
56
56
Running ` ./Taskfile help ` , the ` task:help ` function is triggered. This task will list all available sections and tasks
57
57
using the double ` ## ` comments you've learned about above. Now it's clear how you can run any other task!
58
58
59
- # Auto-completion
59
+ # Advanced
60
+ ## Auto-completion
60
61
61
62
Autocompletion works when you use ` zsh ` and ` oh-my-zsh ` . Create the following file in your oh-my-zsh directory
62
63
` ~/.oh-my-zsh/completions/_task.zsh ` :
@@ -82,6 +83,59 @@ _task "$@"
82
83
83
84
Now after running ` task shorthand ` , your ` task ` commands will get autocompleted.
84
85
86
+ ## SubTaskfiles
87
+
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? SubTaskfiles might be for you! They allow you to divide your tasks across multiple files while still
90
+ (also) calling them from a single one.
91
+
92
+ There are two flavours, but in both cases tasks from the subTaskfile are called "via" a task in the root Taskfile,
93
+ like this: ` ./Taskfile foo <task> <args> `
94
+
95
+ ### Full SubTaskfile
96
+
97
+ This flavour of subTaskfile is more verbose, but can be used on its own as well. Most useful in (mono)repos where people might
98
+ be working on part as often as the whole project.
99
+
100
+ In the main Taskfile you call the subTaskfile like any other script:
101
+ ``` shell
102
+ function task:foo { # # bar
103
+ ./path/to/subtaskfile/Taskfile " ${@ -help} "
104
+ }
105
+ ```
106
+
107
+ The subTaskfile is just a regular Taskfile, including utilities like ` task:help ` , ` file:ensure ` and a line with ` task:"${@-help}" `
108
+ at the bottom.
109
+
110
+ ### Lean SubTaskfile
111
+
112
+ This flavour of subTaskfile cannot be called on its own, but has a lot less boilerplate. Most useful for splitting off a
113
+ group of tasks that can be logically grouped together, possibly because they are rarely used.
114
+
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"
121
+
122
+ task:" ${@ -_help} "
123
+ }
124
+ ```
125
+
126
+ The subTaskfile just needs to contain the tasks and sections you need, but has a few notes:
127
+ ``` shell
128
+ # Files in the subTaskfile's directory need to be prefixed with $SUB_TASKFILE_DIR
129
+ function task:call-script { # # Call a script
130
+ " $SUB_TASKFILE_DIR /some-script.sh"
131
+ }
132
+
133
+ # Without this, you cannot run `./Taskfile foo` or `./Taskfile foo help`
134
+ function task:_help { # # Show all available tasks
135
+ task:help " $SUB_TASKFILE_DIR /Taskfile"
136
+ }
137
+ ```
138
+
85
139
# Credits
86
140
87
141
This Taskfile setup is based on [ Adrian Cooney's Taskfile] ( https://github.com/adriancooney/Taskfile ) and is widely
0 commit comments