1
0
mirror of https://github.com/go-task/task.git synced 2024-12-14 10:52:43 +02:00
task/internal/summary/summary.go
2019-02-24 16:26:46 +01:00

53 lines
1.2 KiB
Go

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) {
printTaskName(Logger, task)
printTaskSummary(task.Summary, Logger)
printTaskDependencies(task.Deps, Logger)
printTaskCommands(task.Cmds, Logger)
}
func printTaskName(Logger *logger.Logger, task *taskfile.Task) {
Logger.Outf("task: " + task.Task)
Logger.Outf("")
}
func printTaskCommands(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)
}
}
}