mirror of
https://github.com/go-task/task.git
synced 2025-08-08 22:36:57 +02:00
Merge branch 'pull-10'
This commit is contained in:
31
README.md
31
README.md
@ -268,6 +268,37 @@ printos:
|
||||
- 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
|
||||
|
||||
Similar software:
|
||||
|
@ -1,20 +1,24 @@
|
||||
# compiles current source code and make "task" executable available on
|
||||
# $GOPATH/bin/task{.exe}
|
||||
install:
|
||||
desc: Installs Task
|
||||
cmds:
|
||||
- go install -v ./...
|
||||
|
||||
lint:
|
||||
desc: Runs golint
|
||||
cmds:
|
||||
- golint .
|
||||
- golint ./cmd/task
|
||||
|
||||
test:
|
||||
desc: Runs test suite
|
||||
deps: [install]
|
||||
cmds:
|
||||
- go test -v
|
||||
|
||||
# https://github.com/goreleaser/goreleaser
|
||||
release:
|
||||
desc: Release Task
|
||||
cmds:
|
||||
- goreleaser
|
||||
|
33
help.go
Normal file
33
help.go
Normal file
@ -0,0 +1,33 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"text/tabwriter"
|
||||
)
|
||||
|
||||
func printExistingTasksHelp() {
|
||||
tasks := tasksWithDesc()
|
||||
if len(tasks) == 0 {
|
||||
return
|
||||
}
|
||||
fmt.Println("Available tasks for this project:")
|
||||
|
||||
// Format in tab-separated columns with a tab stop of 8.
|
||||
w := tabwriter.NewWriter(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() (tasks []string) {
|
||||
for name, task := range Tasks {
|
||||
if task.Desc != "" {
|
||||
tasks = append(tasks, name)
|
||||
}
|
||||
}
|
||||
sort.Strings(tasks)
|
||||
return
|
||||
}
|
11
task.go
11
task.go
@ -30,6 +30,7 @@ var (
|
||||
type Task struct {
|
||||
Cmds []string
|
||||
Deps []string
|
||||
Desc string
|
||||
Sources []string
|
||||
Generates []string
|
||||
Dir string
|
||||
@ -54,6 +55,16 @@ func Run() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// check if given tasks exist
|
||||
for _, a := range args {
|
||||
if _, ok := Tasks[a]; !ok {
|
||||
var err error = &taskNotFoundError{taskName: a}
|
||||
fmt.Println(err)
|
||||
printExistingTasksHelp()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
for _, a := range args {
|
||||
if err = RunTask(a); err != nil {
|
||||
log.Fatal(err)
|
||||
|
Reference in New Issue
Block a user