Skip to content

Commit 998935e

Browse files
committed
add --list (or -l) flag to print existing tasks
If an inexixtent task is given, the help also prints as before Also fixing README documentation Closes #51
1 parent e781ac2 commit 998935e

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ print-os:
379379

380380
### Help
381381

382-
Running `task help` lists all tasks with a description. The following taskfile:
382+
Running `task --list` (or `task -l`) lists all tasks with a description.
383+
The following taskfile:
383384

384385
```yml
385386
build:
@@ -404,8 +405,8 @@ css:
404405
would print the following output:
405406

406407
```bash
407-
build Build the go binary.
408-
test Run all the go tests.
408+
* build: Build the go binary.
409+
* test: Run all the go tests.
409410
```
410411

411412
## Watch tasks (experimental)

cmd/task/task.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var (
1414
version = "master"
1515
)
1616

17-
const usage = `Usage: task [-ifwv] [--init] [--force] [--watch] [--verbose] [task...]
17+
const usage = `Usage: task [-ilfwv] [--init] [--list] [--force] [--watch] [--verbose] [task...]
1818
1919
Runs the specified task(s). Falls back to the "default" task if no task name
2020
was specified, or lists all tasks if an unknown task name was specified.
@@ -45,13 +45,15 @@ func main() {
4545
var (
4646
versionFlag bool
4747
init bool
48+
list bool
4849
force bool
4950
watch bool
5051
verbose bool
5152
)
5253

5354
pflag.BoolVar(&versionFlag, "version", false, "show Task version")
5455
pflag.BoolVarP(&init, "init", "i", false, "creates a new Taskfile.yml in the current folder")
56+
pflag.BoolVarP(&list, "list", "l", false, "lists tasks with description of current Taskfile")
5557
pflag.BoolVarP(&force, "force", "f", false, "forces execution even when the task is up-to-date")
5658
pflag.BoolVarP(&watch, "watch", "w", false, "enables watch of the given task")
5759
pflag.BoolVarP(&verbose, "verbose", "v", false, "enables verbose mode")
@@ -86,6 +88,11 @@ func main() {
8688
log.Fatal(err)
8789
}
8890

91+
if list {
92+
e.PrintTasksHelp()
93+
return
94+
}
95+
8996
args := pflag.Args()
9097
if len(args) == 0 {
9198
log.Println("task: No argument given, trying default task")

help.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import (
66
"text/tabwriter"
77
)
88

9-
func (e *Executor) printExistingTasksHelp() {
9+
// PrintTasksHelp prints help os tasks that have a description
10+
func (e *Executor) PrintTasksHelp() {
1011
tasks := e.tasksWithDesc()
1112
if len(tasks) == 0 {
1213
return
@@ -16,7 +17,7 @@ func (e *Executor) printExistingTasksHelp() {
1617
// Format in tab-separated columns with a tab stop of 8.
1718
w := tabwriter.NewWriter(e.Stdout, 0, 8, 0, '\t', 0)
1819
for _, task := range tasks {
19-
fmt.Fprintln(w, fmt.Sprintf("- %s:\t%s", task, e.Tasks[task].Desc))
20+
fmt.Fprintln(w, fmt.Sprintf("* %s:\t%s", task, e.Tasks[task].Desc))
2021
}
2122
w.Flush()
2223
}

task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (e *Executor) Run(args ...string) error {
8585
for _, a := range args {
8686
if _, ok := e.Tasks[a]; !ok {
8787
// FIXME: move to the main package
88-
e.printExistingTasksHelp()
88+
e.PrintTasksHelp()
8989
return &taskNotFoundError{taskName: a}
9090
}
9191
}

0 commit comments

Comments
 (0)