Files
task/internal/summary/summary.go

80 lines
1.7 KiB
Go
Raw Normal View History

2019-02-24 16:25:27 +01:00
package summary
import (
"github.com/go-task/task/v2/internal/logger"
"github.com/go-task/task/v2/internal/taskfile"
"strings"
)
2019-02-24 18:20:59 +01:00
func Print(l *logger.Logger, t *taskfile.Task) {
printTaskName(l, t)
if hasSummary(t) {
printTaskSummary(l, t)
} else if hasDescription(t) {
2019-02-24 18:20:59 +01:00
printTaskDescription(l, t)
} else {
printErrorNoDescriptionOrSummary(l)
2019-02-24 18:20:59 +01:00
}
printTaskDependencies(l, t)
printTaskCommands(l, t)
}
func hasSummary(task *taskfile.Task) bool {
return task.Summary != ""
2019-02-24 16:26:46 +01:00
}
func printTaskSummary(Logger *logger.Logger, task *taskfile.Task) {
lines := strings.Split(task.Summary, "\n")
for i, line := range lines {
notLastLine := i+1 < len(lines)
if notLastLine || line != "" {
Logger.Outf(line)
}
}
}
2019-02-24 16:26:46 +01:00
func printTaskName(Logger *logger.Logger, task *taskfile.Task) {
Logger.Outf("task: " + task.Task)
Logger.Outf("")
2019-02-24 16:25:27 +01:00
}
func hasDescription(task *taskfile.Task) bool {
return task.Desc != ""
}
func printTaskDescription(Logger *logger.Logger, task *taskfile.Task) {
Logger.Outf(task.Desc)
}
func printErrorNoDescriptionOrSummary(l *logger.Logger) {
l.Outf("(task does not have description or summary)")
2019-02-24 16:25:27 +01:00
}
2019-02-24 18:20:59 +01:00
func printTaskDependencies(logger *logger.Logger, task *taskfile.Task) {
hasDependencies := len(task.Deps) > 0
2019-02-24 16:25:27 +01:00
if hasDependencies {
logger.Outf("")
logger.Outf("dependencies:")
2019-02-24 18:20:59 +01:00
for _, d := range task.Deps {
2019-02-24 16:25:27 +01:00
logger.Outf(" - %s", d.Task)
}
}
}
func printTaskCommands(logger *logger.Logger, task *taskfile.Task) {
hasCommands := len(task.Cmds) > 0
if hasCommands {
logger.Outf("")
logger.Outf("commands:")
for _, c := range task.Cmds {
isCommand := c.Cmd != ""
if isCommand {
logger.Outf(" - %s", c.Cmd)
} else {
logger.Outf(" - Task: %s", c.Task)
}
2019-02-24 16:25:27 +01:00
}
}
}