diff --git a/CHANGELOG.md b/CHANGELOG.md index 452bfb9121..25cb22d4b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)). diff --git a/cmd/task/task.go b/cmd/task/task.go index 6af1632c11..81eae84bc8 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -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") @@ -156,6 +156,7 @@ func main() { if list { e.ListTasksWithDesc() + return } if listAll { diff --git a/docs/usage.md b/docs/usage.md index ac073cbb0f..780b1f279e 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -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. diff --git a/help.go b/help.go index 01cf4f0c2c..a9ae633bc3 100644 --- a/help.go +++ b/help.go @@ -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:") @@ -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 -} diff --git a/task_test.go b/task_test.go index ce684b32a7..464218ff09 100644 --- a/task_test.go +++ b/task_test.go @@ -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") }