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:
parent
a990ffe53d
commit
5a08409a27
24
task_test.go
24
task_test.go
@ -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",
|
||||
|
@ -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 {
|
||||
|
10
testdata/includes_shadowed_default/Taskfile.yml
vendored
Normal file
10
testdata/includes_shadowed_default/Taskfile.yml
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
version: '3'
|
||||
|
||||
includes:
|
||||
included:
|
||||
taskfile: Taskfile2.yml
|
||||
|
||||
tasks:
|
||||
included:
|
||||
cmds:
|
||||
- echo "shadowed" > file.txt
|
6
testdata/includes_shadowed_default/Taskfile2.yml
vendored
Normal file
6
testdata/includes_shadowed_default/Taskfile2.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
cmds:
|
||||
- echo "included" > file.txt
|
1
testdata/includes_shadowed_default/file.txt
vendored
Normal file
1
testdata/includes_shadowed_default/file.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
shadowed
|
5
testdata/includes_unshadowed_default/Taskfile.yml
vendored
Normal file
5
testdata/includes_unshadowed_default/Taskfile.yml
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
version: '3'
|
||||
|
||||
includes:
|
||||
included:
|
||||
taskfile: Taskfile2.yml
|
6
testdata/includes_unshadowed_default/Taskfile2.yml
vendored
Normal file
6
testdata/includes_unshadowed_default/Taskfile2.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
cmds:
|
||||
- echo "included" > file.txt
|
1
testdata/includes_unshadowed_default/file.txt
vendored
Normal file
1
testdata/includes_unshadowed_default/file.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
included
|
Loading…
Reference in New Issue
Block a user