Fixes to Taskfile including:

- Disallow recursive Taskfile including (i.e. included Taskfile including other Taskfiles)
- Write test for included a file instead of a directory
This commit is contained in:
Andrey Nering
2018-10-13 17:52:09 -03:00
parent 5a28560177
commit 5eb1a1f7f5
5 changed files with 19 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
package read
import (
"errors"
"fmt"
"os"
"path/filepath"
@@ -11,6 +12,9 @@ import (
"gopkg.in/yaml.v2"
)
// ErrIncludedTaskfilesCantHaveIncludes is returned when a included Taskfile contains includes
var ErrIncludedTaskfilesCantHaveIncludes = errors.New("task: Included Taskfiles can't have includes. Please, move the include to the main Taskfile")
// Taskfile reads a Taskfile for a given directory
func Taskfile(dir string) (*taskfile.Taskfile, error) {
path := filepath.Join(dir, "Taskfile.yml")
@@ -35,6 +39,9 @@ func Taskfile(dir string) (*taskfile.Taskfile, error) {
if err != nil {
return nil, err
}
if len(includedTaskfile.Includes) > 0 {
return nil, ErrIncludedTaskfilesCantHaveIncludes
}
if err = taskfile.Merge(t, includedTaskfile, namespace); err != nil {
return nil, err
}