Skip to content

Commit

Permalink
Simplify the inspect command (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
pior committed Jan 12, 2019
1 parent dee3f3a commit 35941fa
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 31 deletions.
4 changes: 3 additions & 1 deletion pkg/cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
2 changes: 1 addition & 1 deletion pkg/tasks/apt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/tasks/custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/tasks/homebrew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
2 changes: 1 addition & 1 deletion pkg/tasks/pip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
4 changes: 2 additions & 2 deletions pkg/tasks/python_develop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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())
}
2 changes: 1 addition & 1 deletion pkg/tasks/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions pkg/tasks/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
16 changes: 0 additions & 16 deletions pkg/tasks/task_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion pkg/tasks/unknown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
5 changes: 2 additions & 3 deletions tests/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 35941fa

Please sign in to comment.