1
0
mirror of https://github.com/go-task/task.git synced 2025-04-13 11:50:50 +02:00

print only task name if summary

This commit is contained in:
jaedle 2019-02-24 18:20:59 +01:00
parent e252972c7f
commit 845b88a193
2 changed files with 50 additions and 13 deletions

View File

@ -6,11 +6,19 @@ import (
"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 Print(l *logger.Logger, t *taskfile.Task) {
printTaskName(l, t)
if hasSummary(t) {
printTaskSummary(l, t)
} else {
printTaskDescription(l, t)
}
printTaskDependencies(l, t)
printTaskCommands(l, t)
}
func hasSummary(task *taskfile.Task) bool {
return task.Summary != ""
}
func printTaskName(Logger *logger.Logger, task *taskfile.Task) {
@ -18,12 +26,12 @@ func printTaskName(Logger *logger.Logger, task *taskfile.Task) {
Logger.Outf("")
}
func printTaskCommands(cmds []*taskfile.Cmd, logger *logger.Logger) {
hasCommands := len(cmds) > 0
func printTaskCommands(logger *logger.Logger, task *taskfile.Task) {
hasCommands := len(task.Cmds) > 0
if hasCommands {
logger.Outf("")
logger.Outf("commands:")
for _, c := range cmds {
for _, c := range task.Cmds {
isCommand := c.Cmd != ""
if isCommand {
logger.Outf(" - %s", c.Cmd)
@ -34,20 +42,20 @@ func printTaskCommands(cmds []*taskfile.Cmd, logger *logger.Logger) {
}
}
func printTaskDependencies(deps []*taskfile.Dep, logger *logger.Logger) {
hasDependencies := len(deps) > 0
func printTaskDependencies(logger *logger.Logger, task *taskfile.Task) {
hasDependencies := len(task.Deps) > 0
if hasDependencies {
logger.Outf("")
logger.Outf("dependencies:")
for _, d := range deps {
for _, d := range task.Deps {
logger.Outf(" - %s", d.Task)
}
}
}
func printTaskSummary(description string, Logger *logger.Logger) {
lines := strings.Split(description, "\n")
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 != "" {
@ -55,3 +63,7 @@ func printTaskSummary(description string, Logger *logger.Logger) {
}
}
}
func printTaskDescription(Logger *logger.Logger, task *taskfile.Task) {
Logger.Outf(task.Desc)
}

View File

@ -138,3 +138,28 @@ commands:
`
return expected
}
func TestPrintDescriptionAsFallback(t *testing.T) {
buffer := &bytes.Buffer{}
l := logger.Logger{
Stdout: buffer,
Stderr: buffer,
Verbose: false,
}
taskWithoutSummary := &taskfile.Task{
Desc: "description",
}
taskWithSummary := &taskfile.Task{
Desc: "description",
Summary: "summary",
}
summary.Print(&l, taskWithoutSummary)
assert.Contains(t, buffer.String(), "description")
buffer.Reset()
summary.Print(&l, taskWithSummary)
assert.NotContains(t, buffer.String(), "description")
}