1
0
mirror of https://github.com/go-task/task.git synced 2025-03-19 21:17:46 +02:00

Merge pull request #815 from pd93/default-included-task

feat: run default task in included file when task is omitted
This commit is contained in:
Andrey Nering 2022-11-02 11:34:19 -03:00 committed by GitHub
commit 13f4b376e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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