mirror of
https://github.com/go-task/task.git
synced 2025-11-27 22:38:20 +02:00
committed by
Andrey Nering
parent
06633e2f99
commit
e4c1cc3e77
31
README.md
31
README.md
@@ -268,6 +268,37 @@ printos:
|
|||||||
- echo 'Is SH? {{IsSH}}'
|
- echo 'Is SH? {{IsSH}}'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Help
|
||||||
|
|
||||||
|
Running `task help` lists all tasks with a description. The following taskfile:
|
||||||
|
|
||||||
|
```yml
|
||||||
|
build:
|
||||||
|
desc: Build the go binary.
|
||||||
|
cmds:
|
||||||
|
- go build -v -i main.go
|
||||||
|
|
||||||
|
test:
|
||||||
|
desc: Run all the go tests.
|
||||||
|
cmds:
|
||||||
|
- go test -race ./...
|
||||||
|
|
||||||
|
js:
|
||||||
|
cmds:
|
||||||
|
- npm run buildjs
|
||||||
|
|
||||||
|
css:
|
||||||
|
cmds:
|
||||||
|
- npm run buildcss
|
||||||
|
```
|
||||||
|
|
||||||
|
would print the following output:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
build Build the go binary.
|
||||||
|
test Run all the go tests.
|
||||||
|
```
|
||||||
|
|
||||||
## Alternatives
|
## Alternatives
|
||||||
|
|
||||||
Similar software:
|
Similar software:
|
||||||
|
|||||||
29
task.go
29
task.go
@@ -4,8 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/go-task/task/execext"
|
"github.com/go-task/task/execext"
|
||||||
|
|
||||||
@@ -30,6 +32,7 @@ var (
|
|||||||
type Task struct {
|
type Task struct {
|
||||||
Cmds []string
|
Cmds []string
|
||||||
Deps []string
|
Deps []string
|
||||||
|
Desc string
|
||||||
Sources []string
|
Sources []string
|
||||||
Generates []string
|
Generates []string
|
||||||
Dir string
|
Dir string
|
||||||
@@ -73,6 +76,11 @@ func RunTask(name string) error {
|
|||||||
|
|
||||||
t, ok := Tasks[name]
|
t, ok := Tasks[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
tasks := tasksWithDesc()
|
||||||
|
if len(tasks) > 0 {
|
||||||
|
help(tasks)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return &taskNotFoundError{name}
|
return &taskNotFoundError{name}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,3 +210,24 @@ func (t *Task) runCommand(i int) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func help(tasks []string) {
|
||||||
|
w := new(tabwriter.Writer)
|
||||||
|
// Format in tab-separated columns with a tab stop of 8.
|
||||||
|
w.Init(os.Stdout, 0, 8, 0, '\t', 0)
|
||||||
|
for _, task := range tasks {
|
||||||
|
fmt.Fprintln(w, fmt.Sprintf("%s\t%s", task, Tasks[task].Desc))
|
||||||
|
}
|
||||||
|
w.Flush()
|
||||||
|
}
|
||||||
|
|
||||||
|
func tasksWithDesc() []string {
|
||||||
|
tasks := []string{}
|
||||||
|
for name, task := range Tasks {
|
||||||
|
if len(task.Desc) > 0 {
|
||||||
|
tasks = append(tasks, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sort.Strings(tasks)
|
||||||
|
return tasks
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user