1
0
mirror of https://github.com/go-task/task.git synced 2025-03-19 21:17:46 +02:00

remove output to own package

This commit is contained in:
jaedle 2019-02-24 16:25:27 +01:00
parent a1765e1d33
commit 3ee66ef705
2 changed files with 51 additions and 42 deletions

View File

@ -0,0 +1,48 @@
package summary
import (
"github.com/go-task/task/v2/internal/logger"
"github.com/go-task/task/v2/internal/taskfile"
"strings"
)
func Print(Logger *logger.Logger, task *taskfile.Task) {
Logger.Outf("task: " + task.Task)
Logger.Outf("")
printTaskSummary(task.Summary, Logger)
printTaskDependencies(task.Deps, Logger)
printCommands(task.Cmds, Logger)
}
func printCommands(cmds []*taskfile.Cmd, logger *logger.Logger) {
hasCommands := len(cmds) > 0
if hasCommands {
logger.Outf("")
logger.Outf("commands:")
for _, c := range cmds {
logger.Outf(" - %s", c.Cmd)
}
}
}
func printTaskDependencies(deps []*taskfile.Dep, logger *logger.Logger) {
hasDependencies := len(deps) > 0
if hasDependencies {
logger.Outf("")
logger.Outf("dependencies:")
for _, d := range deps {
logger.Outf(" - %s", d.Task)
}
}
}
func printTaskSummary(description string, Logger *logger.Logger) {
lines := strings.Split(description, "\n")
for i, line := range lines {
notLastLine := i+1 < len(lines)
if notLastLine || line != "" {
Logger.Outf(line)
}
}
}

45
task.go
View File

@ -3,9 +3,9 @@ package task
import (
"context"
"fmt"
"github.com/go-task/task/v2/internal/summary"
"io"
"os"
"strings"
"sync/atomic"
"github.com/go-task/task/v2/internal/compiler"
@ -84,51 +84,12 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
func (e *Executor) printTaskSummary(task string) {
t := e.Taskfile.Tasks[task]
s := t.Summary
if s == "" {
if t.Summary == "" {
e.Logger.Errf("task: There is no summary for task: %s", task)
return
}
e.Logger.Outf("task: " + task)
e.Logger.Outf("")
printTaskSummary(s, e.Logger)
printTaskDependencies(t.Deps, e.Logger)
printCommands(t.Cmds, e.Logger)
}
func printCommands(cmds []*taskfile.Cmd, logger *logger.Logger) {
hasCommands := len(cmds) > 0
if hasCommands {
logger.Outf("")
logger.Outf("commands:")
for _, c := range cmds {
logger.Outf(" - %s", c.Cmd)
}
}
}
func printTaskDependencies(deps []*taskfile.Dep, logger *logger.Logger) {
hasDependencies := len(deps) > 0
if hasDependencies {
logger.Outf("")
logger.Outf("dependencies:")
for _, d := range deps {
logger.Outf(" - %s", d.Task)
}
}
}
func printTaskSummary(description string, Logger *logger.Logger) {
lines := strings.Split(description, "\n")
for i, line := range lines {
notLastLine := i+1 < len(lines)
if notLastLine || line != "" {
Logger.Outf(line)
}
}
summary.Print(e.Logger, t)
}
// Setup setups Executor's internal state