From 419064226a84383e5efa3e420304a1c75f98bf4a Mon Sep 17 00:00:00 2001 From: Johan van Overbeeke Date: Fri, 8 Aug 2025 19:48:38 +0200 Subject: [PATCH 1/4] Allow running help on/for other Taskfiles --- src/components/Generator/GeneredTaskfile/taskfile-base.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Generator/GeneredTaskfile/taskfile-base.sh b/src/components/Generator/GeneredTaskfile/taskfile-base.sh index beca5a7..9997d86 100644 --- a/src/components/Generator/GeneredTaskfile/taskfile-base.sh +++ b/src/components/Generator/GeneredTaskfile/taskfile-base.sh @@ -52,13 +52,15 @@ function title { echo -e "\n${BLUE}=>${RESET} $1\n" } +# shellcheck disable=SC2120 function task:help { ## Show all available tasks + TASKFILE_FILE=${1-$0} title "Available tasks" awk 'BEGIN {FS = " { [#][#][ ]?"} /^([a-zA-Z_-]*:?.*)(\{ )?[#][#][ ]?/ \ - {printf "\033[33m%-34s\033[0m %s\n", $1, $2}' $0 |\ + {printf "\033[33m%-34s\033[0m %s\n", $1, $2}' "$TASKFILE_FILE" |\ sed -E "s/[#]{2,}[ ]*/${RESET}/g" |\ sed -E "s/function task:*/ /g" - echo -e "\n${BLUE}Usage:${RESET} ./Taskfile ${YELLOW}${RESET} " + echo -e "\n${BLUE}Usage:${RESET} $TASKFILE_FILE ${YELLOW}${RESET} " } function task:shorthand { ## Create CLI shorthand task instead of ./Taskfile From 4982ae46602a8cc42b4c4652939b568acbfd05fc Mon Sep 17 00:00:00 2001 From: Johan van Overbeeke Date: Fri, 8 Aug 2025 20:57:31 +0200 Subject: [PATCH 2/4] Document subTaskfiles --- README.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eef7334..579c434 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,8 @@ Lines with only a single `#` will not appear as section in `task:help` and can b Running `./Taskfile help`, the `task:help` function is triggered. This task will list all available sections and tasks using the double `##` comments you've learned about above. Now it's clear how you can run any other task! -# Auto-completion +# Advanced +## Auto-completion Autocompletion works when you use `zsh` and `oh-my-zsh`. Create the following file in your oh-my-zsh directory `~/.oh-my-zsh/completions/_task.zsh`: @@ -82,6 +83,59 @@ _task "$@" Now after running `task shorthand`, your `task` commands will get autocompleted. +## SubTaskfiles + +Have a (mono)repo with multiple projects, a group of less-used or specialized tasks or just waaay to many tasks for a +single Taskfile? SubTaskfiles might be for you! They allow you to divide your tasks across multiple files while still +(also) calling them from a single one. + +There are two flavours, but in both cases tasks from the subTaskfile are called "via" a task in the root Taskfile, +like this: `./Taskfile foo ` + +### Full SubTaskfile + +This flavour of subTaskfile is more verbose, but can be used on its own as well. Most useful in (mono)repos where people might +be working on part as often as the whole project. + +In the main Taskfile you call the subTaskfile like any other script: +```shell +function task:foo { ## bar + ./path/to/subtaskfile/Taskfile "${@-help}" +} +``` + +The subTaskfile is just a regular Taskfile, including utilities like `task:help`, `file:ensure` and a line with `task:"${@-help}"` +at the bottom. + +### Lean SubTaskfile + +This flavour of subTaskfile cannot be called on its own, but has a lot less boilerplate. Most useful for splitting off a +group of tasks that can be logically grouped together, possibly because they are rarely used. + +In the main Taskfile: +```shell +function task:foo { ## bar + SUB_TASKFILE_DIR="./path/to/subtaskfile/" + + source "$SUB_TASKFILE_DIR/Taskfile" + + task:"${@-_help}" +} +``` + +The subTaskfile just needs to contain the tasks and sections you need, but has a few notes: +```shell +# Files in the subTaskfile's directory need to be prefixed with $SUB_TASKFILE_DIR +function task:call-script { ## Call a script + "$SUB_TASKFILE_DIR/some-script.sh" +} + +# Without this, you cannot run `./Taskfile foo` or `./Taskfile foo help` +function task:_help { ## Show all available tasks + task:help "$SUB_TASKFILE_DIR/Taskfile" +} +``` + # Credits This Taskfile setup is based on [Adrian Cooney's Taskfile](https://github.com/adriancooney/Taskfile) and is widely From 96feaa729dcd573e24a88c5c3a21a0525f19175e Mon Sep 17 00:00:00 2001 From: Johan van Overbeeke Date: Fri, 8 Aug 2025 21:09:27 +0200 Subject: [PATCH 3/4] Clarify naming of the two types --- README.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 579c434..dd0ae6e 100644 --- a/README.md +++ b/README.md @@ -83,34 +83,34 @@ _task "$@" Now after running `task shorthand`, your `task` commands will get autocompleted. -## SubTaskfiles +## Splitting Taskfiles Have a (mono)repo with multiple projects, a group of less-used or specialized tasks or just waaay to many tasks for a -single Taskfile? SubTaskfiles might be for you! They allow you to divide your tasks across multiple files while still -(also) calling them from a single one. +single Taskfile? Splitting your Taskfiles might be for you! This allows you to divide your tasks across multiple files +while still (also) calling them from a single one. -There are two flavours, but in both cases tasks from the subTaskfile are called "via" a task in the root Taskfile, +There are two types, but in both cases tasks from the secondary Taskfile are called "via" a task in the root Taskfile, like this: `./Taskfile foo ` -### Full SubTaskfile +### Remote Taskfile -This flavour of subTaskfile is more verbose, but can be used on its own as well. Most useful in (mono)repos where people might -be working on part as often as the whole project. +This type is more verbose, but can be used on its own as well. Most useful in (mono)repos where people might be working +in a subdirectory as often as on the project as a whole. -In the main Taskfile you call the subTaskfile like any other script: +In the main Taskfile you call the secondary like any other script: ```shell function task:foo { ## bar - ./path/to/subtaskfile/Taskfile "${@-help}" + ./path/to/secondary/Taskfile "${@-help}" } ``` -The subTaskfile is just a regular Taskfile, including utilities like `task:help`, `file:ensure` and a line with `task:"${@-help}"` -at the bottom. +The secondary is just a regular Taskfile, including utilities (semi) optional ones like `task:help`, `file:ensure` and +the required line with `task:"${@-help}"`at the bottom. -### Lean SubTaskfile +### SubTaskfile -This flavour of subTaskfile cannot be called on its own, but has a lot less boilerplate. Most useful for splitting off a -group of tasks that can be logically grouped together, possibly because they are rarely used. +This type cannot be called on its own, but has a lot less boilerplate. Most useful for splitting off a group of tasks +that can be logically grouped together, for specific tasks or because they are rarely used. In the main Taskfile: ```shell @@ -125,7 +125,7 @@ function task:foo { ## bar The subTaskfile just needs to contain the tasks and sections you need, but has a few notes: ```shell -# Files in the subTaskfile's directory need to be prefixed with $SUB_TASKFILE_DIR +# When you use files in the subTaskfile's directory, you need prefix them with $SUB_TASKFILE_DIR function task:call-script { ## Call a script "$SUB_TASKFILE_DIR/some-script.sh" } From e987427e87125ca1f1965ca728938b57538a52c7 Mon Sep 17 00:00:00 2001 From: Johan van Overbeeke Date: Fri, 8 Aug 2025 23:55:07 +0200 Subject: [PATCH 4/4] Remove "Remote Taskfile" type and other findings from in-person review --- README.md | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index dd0ae6e..f0e186a 100644 --- a/README.md +++ b/README.md @@ -83,56 +83,47 @@ _task "$@" Now after running `task shorthand`, your `task` commands will get autocompleted. -## Splitting Taskfiles +## SubTaskfiles Have a (mono)repo with multiple projects, a group of less-used or specialized tasks or just waaay to many tasks for a -single Taskfile? Splitting your Taskfiles might be for you! This allows you to divide your tasks across multiple files -while still (also) calling them from a single one. +single Taskfile? Splitting your Taskfile might be for you! Using SubTaskfiles allows you to divide your tasks across +multiple files while still calling them from a single one. Most useful for splitting off a group of tasks that can be +logically grouped together, like for specific use-cases or because they are rarely used. -There are two types, but in both cases tasks from the secondary Taskfile are called "via" a task in the root Taskfile, -like this: `./Taskfile foo ` +Example use-cases: git-hooks, frontend- / backend-specific tasks, tasks that fix (infrequently occurring) bugs, etc. -### Remote Taskfile +SubTaskfiles can't be run directly, but are always run "via" a task in the root Taskfile, like this: +`Usage: ./Taskfile foo ` -This type is more verbose, but can be used on its own as well. Most useful in (mono)repos where people might be working -in a subdirectory as often as on the project as a whole. +### How -In the main Taskfile you call the secondary like any other script: +Put this in the root Taskfile: ```shell function task:foo { ## bar - ./path/to/secondary/Taskfile "${@-help}" -} -``` - -The secondary is just a regular Taskfile, including utilities (semi) optional ones like `task:help`, `file:ensure` and -the required line with `task:"${@-help}"`at the bottom. - -### SubTaskfile - -This type cannot be called on its own, but has a lot less boilerplate. Most useful for splitting off a group of tasks -that can be logically grouped together, for specific tasks or because they are rarely used. + SUBTASKFILE_DIR="./path/to/subtaskfile/" -In the main Taskfile: -```shell -function task:foo { ## bar - SUB_TASKFILE_DIR="./path/to/subtaskfile/" - - source "$SUB_TASKFILE_DIR/Taskfile" + source "$SUBTASKFILE_DIR/SubTaskfile" task:"${@-_help}" } + +# Optional: use proxy-tasks like this for tasks you want to run straight from the root Taskfile +function task:baz { ## Call `foo baz` directly + task:foo baz +} ``` -The subTaskfile just needs to contain the tasks and sections you need, but has a few notes: +Give SubTaskfile the filename `SubTaskfile`. It needs to contain only the tasks and sections you think useful (while +still having access to stuff like `file:ensure` from the root Taskfile!), but it has a few notes: ```shell -# When you use files in the subTaskfile's directory, you need prefix them with $SUB_TASKFILE_DIR +# When you refer to files in the subTaskfile's directory, you need prefix them with $SUBTASKFILE_DIR function task:call-script { ## Call a script - "$SUB_TASKFILE_DIR/some-script.sh" + "$SUBTASKFILE_DIR/some-script.sh" } # Without this, you cannot run `./Taskfile foo` or `./Taskfile foo help` function task:_help { ## Show all available tasks - task:help "$SUB_TASKFILE_DIR/Taskfile" + task:help "$SUBTASKFILE_DIR/SubTaskfile" } ```