1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

print error messsage if no summary or description present

This commit is contained in:
jaedle
2019-02-24 18:26:16 +01:00
parent 845b88a193
commit 3f8ee21849
2 changed files with 42 additions and 27 deletions

View File

@@ -10,8 +10,10 @@ func Print(l *logger.Logger, t *taskfile.Task) {
printTaskName(l, t)
if hasSummary(t) {
printTaskSummary(l, t)
} else {
} else if hasDescription(t) {
printTaskDescription(l, t)
} else {
printErrorNoDescriptionOrSummary(l)
}
printTaskDependencies(l, t)
printTaskCommands(l, t)
@@ -21,11 +23,45 @@ func hasSummary(task *taskfile.Task) bool {
return task.Summary != ""
}
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)
}
}
}
func printTaskName(Logger *logger.Logger, task *taskfile.Task) {
Logger.Outf("task: " + task.Task)
Logger.Outf("")
}
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)")
}
func printTaskDependencies(logger *logger.Logger, task *taskfile.Task) {
hasDependencies := len(task.Deps) > 0
if hasDependencies {
logger.Outf("")
logger.Outf("dependencies:")
for _, d := range task.Deps {
logger.Outf(" - %s", d.Task)
}
}
}
func printTaskCommands(logger *logger.Logger, task *taskfile.Task) {
hasCommands := len(task.Cmds) > 0
if hasCommands {
@@ -41,29 +77,3 @@ func printTaskCommands(logger *logger.Logger, task *taskfile.Task) {
}
}
}
func printTaskDependencies(logger *logger.Logger, task *taskfile.Task) {
hasDependencies := len(task.Deps) > 0
if hasDependencies {
logger.Outf("")
logger.Outf("dependencies:")
for _, d := range task.Deps {
logger.Outf(" - %s", d.Task)
}
}
}
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)
}
}
}
func printTaskDescription(Logger *logger.Logger, task *taskfile.Task) {
Logger.Outf(task.Desc)
}

View File

@@ -154,6 +154,7 @@ func TestPrintDescriptionAsFallback(t *testing.T) {
Desc: "description",
Summary: "summary",
}
taskWithoutSummaryOrDescription := &taskfile.Task{}
summary.Print(&l, taskWithoutSummary)
assert.Contains(t, buffer.String(), "description")
@@ -162,4 +163,8 @@ func TestPrintDescriptionAsFallback(t *testing.T) {
summary.Print(&l, taskWithSummary)
assert.NotContains(t, buffer.String(), "description")
buffer.Reset()
summary.Print(&l, taskWithoutSummaryOrDescription)
assert.Contains(t, buffer.String(), "\n(task does not have description or summary)\n")
}