1
0
mirror of https://github.com/go-task/task.git synced 2024-12-04 10:24:45 +02:00

feat: run default task in included file when task is omitted

This commit is contained in:
Pete Davison 2022-11-02 14:27:15 +00:00
parent a990ffe53d
commit 5a08409a27
8 changed files with 60 additions and 0 deletions

View File

@ -1107,6 +1107,30 @@ func TestInternalTask(t *testing.T) {
}
}
func TestIncludesShadowedDefault(t *testing.T) {
tt := fileContentTest{
Dir: "testdata/includes_shadowed_default",
Target: "included",
TrimSpace: true,
Files: map[string]string{
"file.txt": "shadowed",
},
}
tt.Run(t)
}
func TestIncludesUnshadowedDefault(t *testing.T) {
tt := fileContentTest{
Dir: "testdata/includes_unshadowed_default",
Target: "included",
TrimSpace: true,
Files: map[string]string{
"file.txt": "included",
},
}
tt.Run(t)
}
func TestSupportedFileNames(t *testing.T) {
fileNames := []string{
"Taskfile.yml",

View File

@ -153,6 +153,13 @@ func Taskfile(readerNode *ReaderNode) (*taskfile.Taskfile, error) {
if err = taskfile.Merge(t, includedTaskfile, &includedTask, namespace); err != nil {
return err
}
if includedTaskfile.Tasks["default"] != nil && t.Tasks[namespace] == nil {
defaultTaskName := fmt.Sprintf("%s:default", namespace)
t.Tasks[defaultTaskName].Aliases = append(t.Tasks[defaultTaskName].Aliases, namespace)
t.Tasks[defaultTaskName].Aliases = append(t.Tasks[defaultTaskName].Aliases, includedTask.Aliases...)
}
return nil
})
if err != nil {

View File

@ -0,0 +1,10 @@
version: '3'
includes:
included:
taskfile: Taskfile2.yml
tasks:
included:
cmds:
- echo "shadowed" > file.txt

View File

@ -0,0 +1,6 @@
version: '3'
tasks:
default:
cmds:
- echo "included" > file.txt

View File

@ -0,0 +1 @@
shadowed

View File

@ -0,0 +1,5 @@
version: '3'
includes:
included:
taskfile: Taskfile2.yml

View File

@ -0,0 +1,6 @@
version: '3'
tasks:
default:
cmds:
- echo "included" > file.txt

View File

@ -0,0 +1 @@
included