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:
@@ -10,8 +10,10 @@ func Print(l *logger.Logger, t *taskfile.Task) {
|
|||||||
printTaskName(l, t)
|
printTaskName(l, t)
|
||||||
if hasSummary(t) {
|
if hasSummary(t) {
|
||||||
printTaskSummary(l, t)
|
printTaskSummary(l, t)
|
||||||
} else {
|
} else if hasDescription(t) {
|
||||||
printTaskDescription(l, t)
|
printTaskDescription(l, t)
|
||||||
|
} else {
|
||||||
|
printErrorNoDescriptionOrSummary(l)
|
||||||
}
|
}
|
||||||
printTaskDependencies(l, t)
|
printTaskDependencies(l, t)
|
||||||
printTaskCommands(l, t)
|
printTaskCommands(l, t)
|
||||||
@@ -21,11 +23,45 @@ func hasSummary(task *taskfile.Task) bool {
|
|||||||
return task.Summary != ""
|
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) {
|
func printTaskName(Logger *logger.Logger, task *taskfile.Task) {
|
||||||
Logger.Outf("task: " + task.Task)
|
Logger.Outf("task: " + task.Task)
|
||||||
Logger.Outf("")
|
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) {
|
func printTaskCommands(logger *logger.Logger, task *taskfile.Task) {
|
||||||
hasCommands := len(task.Cmds) > 0
|
hasCommands := len(task.Cmds) > 0
|
||||||
if hasCommands {
|
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)
|
|
||||||
}
|
|
||||||
|
@@ -154,6 +154,7 @@ func TestPrintDescriptionAsFallback(t *testing.T) {
|
|||||||
Desc: "description",
|
Desc: "description",
|
||||||
Summary: "summary",
|
Summary: "summary",
|
||||||
}
|
}
|
||||||
|
taskWithoutSummaryOrDescription := &taskfile.Task{}
|
||||||
|
|
||||||
summary.Print(&l, taskWithoutSummary)
|
summary.Print(&l, taskWithoutSummary)
|
||||||
assert.Contains(t, buffer.String(), "description")
|
assert.Contains(t, buffer.String(), "description")
|
||||||
@@ -162,4 +163,8 @@ func TestPrintDescriptionAsFallback(t *testing.T) {
|
|||||||
summary.Print(&l, taskWithSummary)
|
summary.Print(&l, taskWithSummary)
|
||||||
assert.NotContains(t, buffer.String(), "description")
|
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")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user