diff --git a/cmd/task/task.go b/cmd/task/task.go index f7a5afe9..6afde2d8 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -98,7 +98,7 @@ func main() { Stdout: os.Stdout, Stderr: os.Stderr, } - if err := e.ReadTaskfile(); err != nil { + if err := e.Setup(); err != nil { log.Fatal(err) } diff --git a/task.go b/task.go index ffe739c1..cade5d35 100644 --- a/task.go +++ b/task.go @@ -52,10 +52,6 @@ type Executor struct { // Run runs Task func (e *Executor) Run(calls ...taskfile.Call) error { - if err := e.setup(); err != nil { - return err - } - // check if given tasks exist for _, c := range calls { if _, ok := e.Taskfile.Tasks[c.Task]; !ok { @@ -77,7 +73,12 @@ func (e *Executor) Run(calls ...taskfile.Call) error { return nil } -func (e *Executor) setup() error { +// Setup setups Executor's internal state +func (e *Executor) Setup() error { + if err := e.readTaskfile(); err != nil { + return err + } + v, err := semver.NewVersion(e.Taskfile.Version) if err != nil { return fmt.Errorf(`task: could not parse taskfile version "%s": %v`, e.Taskfile.Version, err) diff --git a/task_test.go b/task_test.go index c0d690cc..6e48faa8 100644 --- a/task_test.go +++ b/task_test.go @@ -38,7 +38,7 @@ func (fct fileContentTest) Run(t *testing.T) { Stdout: ioutil.Discard, Stderr: ioutil.Discard, } - assert.NoError(t, e.ReadTaskfile(), "e.ReadTaskfile()") + assert.NoError(t, e.Setup(), "e.Setup()") assert.NoError(t, e.Run(taskfile.Call{Task: fct.Target}), "e.Run(target)") for name, expectContent := range fct.Files { @@ -176,7 +176,7 @@ func TestVarsInvalidTmpl(t *testing.T) { Stdout: ioutil.Discard, Stderr: ioutil.Discard, } - assert.NoError(t, e.ReadTaskfile(), "e.ReadTaskfile()") + assert.NoError(t, e.Setup(), "e.Setup()") assert.EqualError(t, e.Run(taskfile.Call{Task: target}), expectError, "e.Run(target)") } @@ -228,7 +228,7 @@ func TestDeps(t *testing.T) { Stdout: ioutil.Discard, Stderr: ioutil.Discard, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) assert.NoError(t, e.Run(taskfile.Call{Task: "default"})) for _, f := range files { @@ -256,7 +256,7 @@ func TestStatus(t *testing.T) { Stderr: &buff, Silent: true, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) assert.NoError(t, e.Run(taskfile.Call{Task: "gen-foo"})) if _, err := os.Stat(file); err != nil { @@ -295,7 +295,7 @@ func TestGenerates(t *testing.T) { Stdout: buff, Stderr: buff, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) for _, theTask := range []string{relTask, absTask} { var destFile = filepath.Join(dir, theTask) @@ -347,7 +347,7 @@ func TestStatusChecksum(t *testing.T) { Stdout: &buff, Stderr: &buff, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) assert.NoError(t, e.Run(taskfile.Call{Task: "build"})) for _, f := range files { @@ -386,7 +386,7 @@ func TestCyclicDep(t *testing.T) { Stdout: ioutil.Discard, Stderr: ioutil.Discard, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) assert.IsType(t, &task.MaximumTaskCallExceededError{}, e.Run(taskfile.Call{Task: "task-1"})) } @@ -406,7 +406,7 @@ func TestTaskVersion(t *testing.T) { Stdout: ioutil.Discard, Stderr: ioutil.Discard, } - assert.NoError(t, e.ReadTaskfile()) + assert.NoError(t, e.Setup()) assert.Equal(t, test.Version, e.Taskfile.Version) assert.Equal(t, 2, len(e.Taskfile.Tasks)) }) diff --git a/taskfile.go b/taskfile.go index d6ebf9d8..8a5a37f1 100644 --- a/taskfile.go +++ b/taskfile.go @@ -12,8 +12,8 @@ import ( "gopkg.in/yaml.v2" ) -// ReadTaskfile parses Taskfile from the disk -func (e *Executor) ReadTaskfile() error { +// readTaskfile parses Taskfile from the disk +func (e *Executor) readTaskfile() error { path := filepath.Join(e.Dir, TaskFilePath) var err error