From c3f833d85f02544d75be0ff6d5144a065bce53b5 Mon Sep 17 00:00:00 2001 From: jaedle Date: Fri, 23 Aug 2019 18:04:17 +0200 Subject: [PATCH 1/5] create test fixture for short task notation --- task_test.go | 14 ++++++++++++++ testdata/short_task_notation/Taskfile.yml | 16 ++++++++++++++++ testdata/short_task_notation/expected_output.txt | 4 ++++ 3 files changed, 34 insertions(+) create mode 100644 testdata/short_task_notation/Taskfile.yml create mode 100644 testdata/short_task_notation/expected_output.txt diff --git a/task_test.go b/task_test.go index b4aa45443e..2f8a06f396 100644 --- a/task_test.go +++ b/task_test.go @@ -678,3 +678,17 @@ func TestWhenDirAttributeItCreatesMissingAndRunsInThatDir(t *testing.T) { // Clean-up after ourselves only if no error. _ = os.Remove(toBeCreated) } + +func TestShortTaskNotation(t *testing.T) { + const dir = "testdata/short_task_notation/" + + var buff bytes.Buffer + e := task.Executor{ + Dir: dir, + Stdout: &buff, + Stderr: &buff, + } + assert.NoError(t, e.Setup()) + assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "run"})) + assert.Equal(t, readTestFixture(t, dir, "expected_output.txt"), buff.String()) +} diff --git a/testdata/short_task_notation/Taskfile.yml b/testdata/short_task_notation/Taskfile.yml new file mode 100644 index 0000000000..d6895277ad --- /dev/null +++ b/testdata/short_task_notation/Taskfile.yml @@ -0,0 +1,16 @@ +version: '3' + +tasks: + + run: + cmds: + - task: short-1 + - task: short-2 + + short-1: + cmds: + - echo "output of short-1" + + short-2: + cmds: + - echo "output of short-2" diff --git a/testdata/short_task_notation/expected_output.txt b/testdata/short_task_notation/expected_output.txt new file mode 100644 index 0000000000..95acaf40a0 --- /dev/null +++ b/testdata/short_task_notation/expected_output.txt @@ -0,0 +1,4 @@ +task: echo "output of short-1" +output of short-1 +task: echo "output of short-2" +output of short-2 From 405c99ff8cfdd4379d243532a95072d87ce6978a Mon Sep 17 00:00:00 2001 From: jaedle Date: Fri, 23 Aug 2019 18:09:40 +0200 Subject: [PATCH 2/5] better test fixture --- testdata/short_task_notation/Taskfile.yml | 13 +++++++------ testdata/short_task_notation/expected_output.txt | 10 ++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/testdata/short_task_notation/Taskfile.yml b/testdata/short_task_notation/Taskfile.yml index d6895277ad..c930225fd5 100644 --- a/testdata/short_task_notation/Taskfile.yml +++ b/testdata/short_task_notation/Taskfile.yml @@ -4,13 +4,14 @@ tasks: run: cmds: - - task: short-1 - - task: short-2 + - task: single-cmd + - task: multiple-cmds - short-1: + single-cmd: cmds: - - echo "output of short-1" + - echo "single-line-short-task" - short-2: + multiple-cmds: cmds: - - echo "output of short-2" + - echo "multiple-cmds-short-tasks-1" + - echo "multiple-cmds-short-tasks-2" diff --git a/testdata/short_task_notation/expected_output.txt b/testdata/short_task_notation/expected_output.txt index 95acaf40a0..7ba981547d 100644 --- a/testdata/short_task_notation/expected_output.txt +++ b/testdata/short_task_notation/expected_output.txt @@ -1,4 +1,6 @@ -task: echo "output of short-1" -output of short-1 -task: echo "output of short-2" -output of short-2 +task: echo "single-line-short-task" +single-line-short-task +task: echo "multiple-cmds-short-tasks-1" +multiple-cmds-short-tasks-1 +task: echo "multiple-cmds-short-tasks-2" +multiple-cmds-short-tasks-2 From 6690bec1141bb4e8f625027e8e51e7e457903c1e Mon Sep 17 00:00:00 2001 From: jaedle Date: Fri, 23 Aug 2019 18:12:35 +0200 Subject: [PATCH 3/5] start with single line short notation --- testdata/short_task_notation/Taskfile.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/testdata/short_task_notation/Taskfile.yml b/testdata/short_task_notation/Taskfile.yml index c930225fd5..25f0c8cbd4 100644 --- a/testdata/short_task_notation/Taskfile.yml +++ b/testdata/short_task_notation/Taskfile.yml @@ -7,9 +7,7 @@ tasks: - task: single-cmd - task: multiple-cmds - single-cmd: - cmds: - - echo "single-line-short-task" + single-cmd: echo "single-line-short-task" multiple-cmds: cmds: From 0ebd182746b5ad0530b4e1cf79647b9156f058d5 Mon Sep 17 00:00:00 2001 From: jaedle Date: Sat, 24 Aug 2019 07:49:11 +0200 Subject: [PATCH 4/5] WIP: multiline short notation --- Taskfile.yml | 5 +- internal/taskfile/task.go | 2 +- internal/taskfile/taskfile.go | 58 +++++++++++++++++++++++ testdata/short_task_notation/Taskfile.yml | 9 ++-- 4 files changed, 65 insertions(+), 9 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 52393d0944..e52dc23672 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,7 +1,4 @@ -version: '3' - -includes: - docs: ./docs +version: '2' vars: GIT_COMMIT: diff --git a/internal/taskfile/task.go b/internal/taskfile/task.go index bc4bf9812b..5dc48956c0 100644 --- a/internal/taskfile/task.go +++ b/internal/taskfile/task.go @@ -20,5 +20,5 @@ type Task struct { Silent bool Method string Prefix string - IgnoreError bool `yaml:"ignore_error"` + IgnoreError bool } diff --git a/internal/taskfile/taskfile.go b/internal/taskfile/taskfile.go index 6da09dd08d..ce04eb1d4c 100644 --- a/internal/taskfile/taskfile.go +++ b/internal/taskfile/taskfile.go @@ -45,3 +45,61 @@ func (tf *Taskfile) UnmarshalYAML(unmarshal func(interface{}) error) error { } return nil } + +func (t *Task) UnmarshalYAML(unmarshal func(interface{}) error) error { + var task struct { + Task string + Cmds []*Cmd + Deps []*Dep + Desc string + Summary string + Sources []string + Generates []string + Status []string + Preconditions []*Precondition + Dir string + Vars Vars + Env Vars + Silent bool + Method string + Prefix string + IgnoreError bool `yaml:"ignore_error"` + } + + err := unmarshal(&task) + if err != nil { + var short []string + err := unmarshal(&short) + if err != nil { + return err + } + + for _, cmd := range short { + t.Cmds = append(t.Cmds, &Cmd{ + Cmd: cmd, + }) + + } + + return nil + } + + t.Task = task.Task + t.Cmds = task.Cmds + t.Deps = task.Deps + t.Desc = task.Desc + t.Summary = task.Summary + t.Sources = task.Sources + t.Generates = task.Generates + t.Status = task.Status + t.Preconditions = task.Preconditions + t.Dir = task.Dir + t.Vars = task.Vars + t.Env = task.Env + t.Silent = task.Silent + t.Method = task.Method + t.Prefix = task.Prefix + t.IgnoreError = task.IgnoreError + + return nil +} diff --git a/testdata/short_task_notation/Taskfile.yml b/testdata/short_task_notation/Taskfile.yml index 25f0c8cbd4..06738dff0c 100644 --- a/testdata/short_task_notation/Taskfile.yml +++ b/testdata/short_task_notation/Taskfile.yml @@ -7,9 +7,10 @@ tasks: - task: single-cmd - task: multiple-cmds - single-cmd: echo "single-line-short-task" + single-cmd: + cmds: + - echo "single-line-short-task" multiple-cmds: - cmds: - - echo "multiple-cmds-short-tasks-1" - - echo "multiple-cmds-short-tasks-2" + - echo "multiple-cmds-short-tasks-1" + - echo "multiple-cmds-short-tasks-2" From 5897dbbc0688f7f05af1af6e0af15f9f49375509 Mon Sep 17 00:00:00 2001 From: jaedle Date: Sat, 24 Aug 2019 07:53:57 +0200 Subject: [PATCH 5/5] revert taskfile changes --- Taskfile.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Taskfile.yml b/Taskfile.yml index e52dc23672..52393d0944 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,4 +1,7 @@ -version: '2' +version: '3' + +includes: + docs: ./docs vars: GIT_COMMIT: