mirror of
https://github.com/go-task/task.git
synced 2025-04-23 12:18:57 +02:00
print only task name if summary
This commit is contained in:
parent
e252972c7f
commit
845b88a193
@ -6,11 +6,19 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Print(Logger *logger.Logger, task *taskfile.Task) {
|
func Print(l *logger.Logger, t *taskfile.Task) {
|
||||||
printTaskName(Logger, task)
|
printTaskName(l, t)
|
||||||
printTaskSummary(task.Summary, Logger)
|
if hasSummary(t) {
|
||||||
printTaskDependencies(task.Deps, Logger)
|
printTaskSummary(l, t)
|
||||||
printTaskCommands(task.Cmds, Logger)
|
} 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) {
|
func printTaskName(Logger *logger.Logger, task *taskfile.Task) {
|
||||||
@ -18,12 +26,12 @@ func printTaskName(Logger *logger.Logger, task *taskfile.Task) {
|
|||||||
Logger.Outf("")
|
Logger.Outf("")
|
||||||
}
|
}
|
||||||
|
|
||||||
func printTaskCommands(cmds []*taskfile.Cmd, logger *logger.Logger) {
|
func printTaskCommands(logger *logger.Logger, task *taskfile.Task) {
|
||||||
hasCommands := len(cmds) > 0
|
hasCommands := len(task.Cmds) > 0
|
||||||
if hasCommands {
|
if hasCommands {
|
||||||
logger.Outf("")
|
logger.Outf("")
|
||||||
logger.Outf("commands:")
|
logger.Outf("commands:")
|
||||||
for _, c := range cmds {
|
for _, c := range task.Cmds {
|
||||||
isCommand := c.Cmd != ""
|
isCommand := c.Cmd != ""
|
||||||
if isCommand {
|
if isCommand {
|
||||||
logger.Outf(" - %s", c.Cmd)
|
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) {
|
func printTaskDependencies(logger *logger.Logger, task *taskfile.Task) {
|
||||||
hasDependencies := len(deps) > 0
|
hasDependencies := len(task.Deps) > 0
|
||||||
if hasDependencies {
|
if hasDependencies {
|
||||||
logger.Outf("")
|
logger.Outf("")
|
||||||
logger.Outf("dependencies:")
|
logger.Outf("dependencies:")
|
||||||
|
|
||||||
for _, d := range deps {
|
for _, d := range task.Deps {
|
||||||
logger.Outf(" - %s", d.Task)
|
logger.Outf(" - %s", d.Task)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func printTaskSummary(description string, Logger *logger.Logger) {
|
func printTaskSummary(Logger *logger.Logger, task *taskfile.Task) {
|
||||||
lines := strings.Split(description, "\n")
|
lines := strings.Split(task.Summary, "\n")
|
||||||
for i, line := range lines {
|
for i, line := range lines {
|
||||||
notLastLine := i+1 < len(lines)
|
notLastLine := i+1 < len(lines)
|
||||||
if notLastLine || line != "" {
|
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)
|
||||||
|
}
|
||||||
|
@ -138,3 +138,28 @@ commands:
|
|||||||
`
|
`
|
||||||
return expected
|
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")
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user