diff --git a/internal/summary/summary.go b/internal/summary/summary.go index 8d44ab19..3e811869 100644 --- a/internal/summary/summary.go +++ b/internal/summary/summary.go @@ -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) -} diff --git a/internal/summary/summary_test.go b/internal/summary/summary_test.go index 1b4087be..d198ee26 100644 --- a/internal/summary/summary_test.go +++ b/internal/summary/summary_test.go @@ -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") + }