mirror of
https://github.com/go-task/task.git
synced 2025-11-25 22:32:55 +02:00
refactor: wrap PrintTasksHelp with arg-less signatures
provide exported methods for accessing PrintTasksHelp variants.
This commit is contained in:
@@ -150,8 +150,12 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if list || listAll {
|
if list {
|
||||||
e.PrintTasksHelp(listAll)
|
e.ListTasksWithDesc()
|
||||||
|
}
|
||||||
|
|
||||||
|
if listAll {
|
||||||
|
e.ListAllTasks()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
help.go
16
help.go
@@ -15,7 +15,7 @@ import (
|
|||||||
func (e *Executor) PrintTasksHelp(listAll bool) {
|
func (e *Executor) PrintTasksHelp(listAll bool) {
|
||||||
var tasks []*taskfile.Task
|
var tasks []*taskfile.Task
|
||||||
if listAll == true {
|
if listAll == true {
|
||||||
tasks = e.taskNames()
|
tasks = e.allTaskNames()
|
||||||
} else {
|
} else {
|
||||||
tasks = e.tasksWithDesc()
|
tasks = e.tasksWithDesc()
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ func (e *Executor) PrintTasksHelp(listAll bool) {
|
|||||||
w.Flush()
|
w.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Executor) taskNames() (tasks []*taskfile.Task) {
|
func (e *Executor) allTaskNames() (tasks []*taskfile.Task) {
|
||||||
tasks = make([]*taskfile.Task, 0, len(e.Taskfile.Tasks))
|
tasks = make([]*taskfile.Task, 0, len(e.Taskfile.Tasks))
|
||||||
for _, task := range e.Taskfile.Tasks {
|
for _, task := range e.Taskfile.Tasks {
|
||||||
tasks = append(tasks, task)
|
tasks = append(tasks, task)
|
||||||
@@ -58,3 +58,15 @@ func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) {
|
|||||||
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task })
|
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListTasksWithDesc reports tasks that have a description spec.
|
||||||
|
func (e *Executor) ListTasksWithDesc() {
|
||||||
|
e.PrintTasksHelp(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListAllTasks reports all tasks, with or without a description spec.
|
||||||
|
func (e *Executor) ListAllTasks() {
|
||||||
|
e.PrintTasksHelp(true)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
4
task.go
4
task.go
@@ -64,9 +64,7 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
|
|||||||
for _, c := range calls {
|
for _, c := range calls {
|
||||||
if _, ok := e.Taskfile.Tasks[c.Task]; !ok {
|
if _, ok := e.Taskfile.Tasks[c.Task]; !ok {
|
||||||
// FIXME: move to the main package
|
// FIXME: move to the main package
|
||||||
// FIXME: (ard.kevin.84@gmail.com) changed the PrintTasksHelp signature to support show all/some.
|
e.ListTasksWithDesc()
|
||||||
// False preserves original behavior, but should be reviewed.
|
|
||||||
e.PrintTasksHelp(false)
|
|
||||||
return &taskNotFoundError{taskName: c.Task}
|
return &taskNotFoundError{taskName: c.Task}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -492,7 +492,7 @@ func TestListAllShowsNoDesc(t *testing.T) {
|
|||||||
assert.NoError(t, e.Setup())
|
assert.NoError(t, e.Setup())
|
||||||
|
|
||||||
var title string
|
var title string
|
||||||
e.PrintTasksHelp(true)
|
e.ListAllTasks()
|
||||||
for _, title = range []string{
|
for _, title = range []string{
|
||||||
"foo",
|
"foo",
|
||||||
"voo",
|
"voo",
|
||||||
@@ -514,7 +514,7 @@ func TestListCanListDescOnly(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert.NoError(t, e.Setup())
|
assert.NoError(t, e.Setup())
|
||||||
e.PrintTasksHelp(false)
|
e.ListTasksWithDesc()
|
||||||
|
|
||||||
var title string
|
var title string
|
||||||
assert.Contains(t, buff.String(), "foo")
|
assert.Contains(t, buff.String(), "foo")
|
||||||
|
|||||||
Reference in New Issue
Block a user