mirror of
https://github.com/go-task/task.git
synced 2025-06-06 23:46:46 +02:00
Minor improvements for tasks description
This commit is contained in:
parent
e4c1cc3e77
commit
2054a1bc34
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
|
||||||
|
}
|
38
task.go
38
task.go
@ -4,10 +4,8 @@ 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"
|
||||||
|
|
||||||
@ -57,6 +55,16 @@ func Run() {
|
|||||||
log.Fatal(err)
|
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 {
|
for _, a := range args {
|
||||||
if err = RunTask(a); err != nil {
|
if err = RunTask(a); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -76,11 +84,6 @@ 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}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,24 +213,3 @@ 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
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user