Skip to content

Commit

Permalink
Add CHANGELOG, documentation and small improvements to go-task#401
Browse files Browse the repository at this point in the history
  • Loading branch information
andreynering committed Jan 4, 2022
1 parent 00a90d1 commit 7e0346d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

## Unreleased

- A new `--list-all` (alias `-a`) flag is now available. It's similar to the
exiting `--list` (`-l`) but prints all tasks, even those without a
description
([#383](https://github.com/go-task/task/issues/383), [#401](https://github.com/go-task/task/pull/401)).
- It's now possible to schedule cleanup commands to run once a task finishes
with the `defer:` keyword
([Documentation](https://taskfile.dev/#/usage?id=doing-task-cleanup-with-defer), [#475](https://github.com/go-task/task/issues/475), [#626](https://github.com/go-task/task/pull/626/files)).
([Documentation](https://taskfile.dev/#/usage?id=doing-task-cleanup-with-defer), [#475](https://github.com/go-task/task/issues/475), [#626](https://github.com/go-task/task/pull/626)).
- Remove long deprecated and undocumented `$` variable prefix and `^` command
prefix
([#642](https://github.com/go-task/task/issues/642), [#644](https://github.com/go-task/task/issues/644), [#645](https://github.com/go-task/task/pull/645)).
Expand Down
3 changes: 2 additions & 1 deletion cmd/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func main() {
pflag.BoolVarP(&helpFlag, "help", "h", false, "shows Task usage")
pflag.BoolVarP(&init, "init", "i", false, "creates a new Taskfile.yaml in the current folder")
pflag.BoolVarP(&list, "list", "l", false, "lists tasks with description of current Taskfile")
pflag.BoolVarP(&listAll, "list-all", "a", false, "list tasks with or without a description")
pflag.BoolVarP(&listAll, "list-all", "a", false, "lists tasks with or without a description")
pflag.BoolVar(&status, "status", false, "exits with non-zero exit code if any of the given tasks is not up-to-date")
pflag.BoolVarP(&force, "force", "f", false, "forces execution even when the task is up-to-date")
pflag.BoolVarP(&watch, "watch", "w", false, "enables watch of the given task")
Expand Down Expand Up @@ -156,6 +156,7 @@ func main() {

if list {
e.ListTasksWithDesc()
return
}

if listAll {
Expand Down
2 changes: 2 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,8 @@ would print the following output:
* test: Run all the go tests.
```

If you want to see all tasks, there's a `--list-all` (alias `-a`) flag as well.

## Display summary of task

Running `task --summary task-name` will show a summary of a task.
Expand Down
38 changes: 19 additions & 19 deletions help.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,32 @@ import (
"github.com/go-task/task/v3/taskfile"
)

// PrintTasksHelp prints tasks' help.
// Behavior is governed by listAll. When false, only tasks with descriptions are reported.
// When true, all tasks are reported with descriptions shown where available.
func (e *Executor) PrintTasksHelp(listAll bool) {
// ListTasksWithDesc reports tasks that have a description spec.
func (e *Executor) ListTasksWithDesc() {
e.pringTasks(false)
return
}

// ListAllTasks reports all tasks, with or without a description spec.
func (e *Executor) ListAllTasks() {
e.pringTasks(true)
return
}

func (e *Executor) pringTasks(listAll bool) {
var tasks []*taskfile.Task
if listAll == true {
if listAll {
tasks = e.allTaskNames()
} else {
tasks = e.tasksWithDesc()
}

if len(tasks) == 0 {
// TODO: This message should be more informative. Maybe a hint to try -la for showing all?
e.Logger.Outf(logger.Yellow, "task: No tasks with description available")
if listAll {
e.Logger.Outf(logger.Yellow, "task: No tasks available")
} else {
e.Logger.Outf(logger.Yellow, "task: No tasks with description available. Try --list-all to list all tasks")
}
return
}
e.Logger.Outf(logger.Default, "task: Available tasks for this project:")
Expand Down Expand Up @@ -58,15 +70,3 @@ func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) {
sort.Slice(tasks, func(i, j int) bool { return tasks[i].Task < tasks[j].Task })
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
}
2 changes: 1 addition & 1 deletion task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func TestLabelInList(t *testing.T) {
Stderr: &buff,
}
assert.NoError(t, e.Setup())
e.PrintTasksHelp(false)
e.ListTasksWithDesc()
assert.Contains(t, buff.String(), "foobar")
}

Expand Down

0 comments on commit 7e0346d

Please sign in to comment.