mirror of
https://github.com/go-task/task.git
synced 2024-12-04 10:24:45 +02:00
fix: include flatten with a default task (#1778)
This commit is contained in:
parent
dd9cec611a
commit
0e2c9cc88f
@ -1240,6 +1240,8 @@ func TestIncludesFlatten(t *testing.T) {
|
|||||||
expectedOutput string
|
expectedOutput string
|
||||||
}{
|
}{
|
||||||
{name: "included flatten", taskfile: "Taskfile.yml", task: "gen", expectedOutput: "gen from included\n"},
|
{name: "included flatten", taskfile: "Taskfile.yml", task: "gen", expectedOutput: "gen from included\n"},
|
||||||
|
{name: "included flatten with default", taskfile: "Taskfile.yml", task: "default", expectedOutput: "default from included flatten\n"},
|
||||||
|
{name: "included flatten can call entrypoint tasks", taskfile: "Taskfile.yml", task: "from_entrypoint", expectedOutput: "from entrypoint\n"},
|
||||||
{name: "included flatten with deps", taskfile: "Taskfile.yml", task: "with_deps", expectedOutput: "gen from included\nwith_deps from included\n"},
|
{name: "included flatten with deps", taskfile: "Taskfile.yml", task: "with_deps", expectedOutput: "gen from included\nwith_deps from included\n"},
|
||||||
{name: "included flatten nested", taskfile: "Taskfile.yml", task: "from_nested", expectedOutput: "from nested\n"},
|
{name: "included flatten nested", taskfile: "Taskfile.yml", task: "from_nested", expectedOutput: "from nested\n"},
|
||||||
{name: "included flatten multiple same task", taskfile: "Taskfile.multiple.yml", task: "gen", expectedErr: true, expectedOutput: "task: Found multiple tasks (gen) included by \"included\"\""},
|
{name: "included flatten multiple same task", taskfile: "Taskfile.multiple.yml", task: "gen", expectedErr: true, expectedOutput: "task: Found multiple tasks (gen) included by \"included\"\""},
|
||||||
|
@ -112,12 +112,12 @@ func (t1 *Tasks) Merge(t2 Tasks, include *Include, includedTaskfileVars *Vars) e
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
// If the included Taskfile has a default task and the parent namespace has
|
// If the included Taskfile has a default task, being not flattened and the parent namespace has
|
||||||
// no task with a matching name, we can add an alias so that the user can
|
// no task with a matching name, we can add an alias so that the user can
|
||||||
// run the included Taskfile's default task without specifying its full
|
// run the included Taskfile's default task without specifying its full
|
||||||
// name. If the parent namespace has aliases, we add another alias for each
|
// name. If the parent namespace has aliases, we add another alias for each
|
||||||
// of them.
|
// of them.
|
||||||
if t2.Get("default") != nil && t1.Get(include.Namespace) == nil {
|
if t2.Get("default") != nil && t1.Get(include.Namespace) == nil && !include.Flatten {
|
||||||
defaultTaskName := fmt.Sprintf("%s:default", include.Namespace)
|
defaultTaskName := fmt.Sprintf("%s:default", include.Namespace)
|
||||||
t1.Get(defaultTaskName).Aliases = append(t1.Get(defaultTaskName).Aliases, include.Namespace)
|
t1.Get(defaultTaskName).Aliases = append(t1.Get(defaultTaskName).Aliases, include.Namespace)
|
||||||
t1.Get(defaultTaskName).Aliases = slices.Concat(t1.Get(defaultTaskName).Aliases, include.Aliases)
|
t1.Get(defaultTaskName).Aliases = slices.Concat(t1.Get(defaultTaskName).Aliases, include.Aliases)
|
||||||
|
3
testdata/includes_flatten/Taskfile.with_default.yml
vendored
Normal file
3
testdata/includes_flatten/Taskfile.with_default.yml
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
version: '3'
|
||||||
|
tasks:
|
||||||
|
default: echo "default from included flatten"
|
8
testdata/includes_flatten/Taskfile.yml
vendored
8
testdata/includes_flatten/Taskfile.yml
vendored
@ -5,9 +5,11 @@ includes:
|
|||||||
taskfile: ./included
|
taskfile: ./included
|
||||||
dir: ./included
|
dir: ./included
|
||||||
flatten: true
|
flatten: true
|
||||||
|
with_default:
|
||||||
|
taskfile: ./Taskfile.with_default.yml
|
||||||
|
flatten: true
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
default:
|
from_entrypoint: echo "from entrypoint"
|
||||||
cmds:
|
|
||||||
- echo root_directory > root_directory.txt
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user