From 4f84c3347f629dc7a33f251632d5a3d7720105c2 Mon Sep 17 00:00:00 2001 From: Pior Bastida Date: Fri, 11 Jan 2019 21:48:25 -0500 Subject: [PATCH] Simplify the inspect command --- pkg/cmd/inspect.go | 4 +++- pkg/tasks/apt_test.go | 2 +- pkg/tasks/custom_test.go | 4 ++-- pkg/tasks/homebrew_test.go | 2 +- pkg/tasks/pip_test.go | 2 +- pkg/tasks/python_develop_test.go | 4 ++-- pkg/tasks/python_test.go | 2 +- pkg/tasks/task.go | 8 ++++++-- pkg/tasks/task_list.go | 16 ---------------- pkg/tasks/unknown_test.go | 2 +- tests/test_inspect.py | 5 ++--- 11 files changed, 20 insertions(+), 31 deletions(-) diff --git a/pkg/cmd/inspect.go b/pkg/cmd/inspect.go index d19b2a10..e87cc95c 100644 --- a/pkg/cmd/inspect.go +++ b/pkg/cmd/inspect.go @@ -26,5 +26,7 @@ func inspectRun(cmd *cobra.Command, args []string) { projectTasks, err := tasks.GetTasksFromProject(proj) checkError(err) - fmt.Print(tasks.InspectTasks(projectTasks, proj)) + for _, task := range projectTasks { + fmt.Printf("- %s\n", task.Describe()) + } } diff --git a/pkg/tasks/apt_test.go b/pkg/tasks/apt_test.go index 3705c7ac..5def6c04 100644 --- a/pkg/tasks/apt_test.go +++ b/pkg/tasks/apt_test.go @@ -13,7 +13,7 @@ apt: - git `) - require.Equal(t, "Task Apt (curl, git) has 1 actions", task.Describe()) + require.Equal(t, "Task Apt (curl, git) actions=1", task.Describe()) } func TestAptEmpty(t *testing.T) { diff --git a/pkg/tasks/custom_test.go b/pkg/tasks/custom_test.go index 6e6462d3..0092c8a0 100644 --- a/pkg/tasks/custom_test.go +++ b/pkg/tasks/custom_test.go @@ -13,7 +13,7 @@ custom: meet: custom-command `) - require.Equal(t, "Task Custom (custom-command) has 1 actions", task.Describe()) + require.Equal(t, "Task Custom (custom-command) actions=1", task.Describe()) } func TestCustomName(t *testing.T) { @@ -24,7 +24,7 @@ custom: meet: custom-command `) - require.Equal(t, "Task Custom (NAMENAME) has 1 actions", task.Describe()) + require.Equal(t, "Task Custom (NAMENAME) actions=1", task.Describe()) } func TestCustomWithBoolean(t *testing.T) { diff --git a/pkg/tasks/homebrew_test.go b/pkg/tasks/homebrew_test.go index b1e0e8b2..3914f3a2 100644 --- a/pkg/tasks/homebrew_test.go +++ b/pkg/tasks/homebrew_test.go @@ -12,5 +12,5 @@ homebrew: - file1 - file2 `) - require.Equal(t, "Task Homebrew (file1, file2) has 2 actions", task.Describe()) + require.Equal(t, "Task Homebrew (file1, file2) actions=2", task.Describe()) } diff --git a/pkg/tasks/pip_test.go b/pkg/tasks/pip_test.go index dcfef7cc..86e2436b 100644 --- a/pkg/tasks/pip_test.go +++ b/pkg/tasks/pip_test.go @@ -13,5 +13,5 @@ pip: - file2 `) - require.Equal(t, "Task Pip (file1, file2) has 2 actions", task.Describe()) + require.Equal(t, "Task Pip (file1, file2) required_task=python actions=2", task.Describe()) } diff --git a/pkg/tasks/python_develop_test.go b/pkg/tasks/python_develop_test.go index b23aa1ee..de3f5278 100644 --- a/pkg/tasks/python_develop_test.go +++ b/pkg/tasks/python_develop_test.go @@ -11,7 +11,7 @@ func TestPythonDevelop(t *testing.T) { python_develop `) - require.Equal(t, "Task Python develop () has 1 actions", task.Describe()) + require.Equal(t, "Task Python develop () required_task=python actions=1", task.Describe()) } func TestPythonDevelopWithExtras(t *testing.T) { @@ -20,5 +20,5 @@ python_develop: extras: [dev, test] `) - require.Equal(t, "Task Python develop () has 1 actions", task.Describe()) + require.Equal(t, "Task Python develop () required_task=python actions=1", task.Describe()) } diff --git a/pkg/tasks/python_test.go b/pkg/tasks/python_test.go index 91b89132..dca6aca8 100644 --- a/pkg/tasks/python_test.go +++ b/pkg/tasks/python_test.go @@ -9,7 +9,7 @@ import ( func TestPythonOk(t *testing.T) { task := ensureLoadTestTask(t, `python: 3.6.3`) - require.Equal(t, "Task Python (3.6.3) has feature python:3.6.3 and has 4 actions", task.Describe()) + require.Equal(t, "Task Python (3.6.3) feature=python:3.6.3 actions=4", task.Describe()) } func TestPythonInvalid(t *testing.T) { diff --git a/pkg/tasks/task.go b/pkg/tasks/task.go index 382d6e69..6ea8deed 100644 --- a/pkg/tasks/task.go +++ b/pkg/tasks/task.go @@ -38,11 +38,15 @@ func (t *Task) AddActionWithBuilder(description string, runFunc func(*Context) e func (t *Task) Describe() string { description := fmt.Sprintf("Task %s (%s)", t.Name, t.header) + if t.RequiredTask != "" { + description += fmt.Sprintf(" required_task=%s", t.RequiredTask) + } + if t.feature.Name != "" { - description += fmt.Sprintf(" has feature %s:%s and", t.feature.Name, t.feature.Param) + description += fmt.Sprintf(" feature=%s:%s", t.feature.Name, t.feature.Param) } - description += fmt.Sprintf(" has %d actions", len(t.actions)) + description += fmt.Sprintf(" actions=%d", len(t.actions)) return description } diff --git a/pkg/tasks/task_list.go b/pkg/tasks/task_list.go index d3d38630..70058bc5 100644 --- a/pkg/tasks/task_list.go +++ b/pkg/tasks/task_list.go @@ -81,19 +81,3 @@ func GetFeaturesFromTasks(tasks []*Task) features.FeatureSet { return featureSet } - -func InspectTasks(taskList []*Task, proj *project.Project) (s string) { - for _, task := range taskList { - s += fmt.Sprintf("Task %s (%s)\n", task.Name, task.header) - if task.feature.Name != "" { - s += fmt.Sprintf(" Provides: %s\n", task.feature) - } - if task.RequiredTask != "" { - s += fmt.Sprintf(" Requires: %s\n", task.RequiredTask) - } - for _, action := range task.actions { - s += fmt.Sprintf(" Action: %T %+v\n", action, action) - } - } - return s -} diff --git a/pkg/tasks/unknown_test.go b/pkg/tasks/unknown_test.go index 04dd873e..f1010c8f 100644 --- a/pkg/tasks/unknown_test.go +++ b/pkg/tasks/unknown_test.go @@ -12,5 +12,5 @@ func TestRegistryUnknown(t *testing.T) { require.NoError(t, err) require.NotNil(t, task) - require.Equal(t, "Task Unknown () has 1 actions", task.Describe()) + require.Equal(t, "Task Unknown () actions=1", task.Describe()) } diff --git a/tests/test_inspect.py b/tests/test_inspect.py index f1adf740..30ce6176 100644 --- a/tests/test_inspect.py +++ b/tests/test_inspect.py @@ -12,9 +12,8 @@ def test_invalid_manifest_with_string(cmd, project): """) output = cmd.run('bud inspect') - assert 'Task Custom (Title)' in output - assert 'Task Pip (requirements.txt)' in output - assert 'Requires: python' in output + assert 'Task Custom (Title) actions=1' in output + assert 'Task Pip (requirements.txt) required_task=python actions=1' in output def test_without_manifest(cmd, project):