2019-02-24 17:25:27 +02:00
|
|
|
package summary
|
|
|
|
|
|
|
|
import (
|
2019-03-04 13:03:28 +02:00
|
|
|
"strings"
|
|
|
|
|
2020-08-16 20:48:19 +02:00
|
|
|
"github.com/go-task/task/v3/internal/logger"
|
2023-12-29 22:32:03 +02:00
|
|
|
"github.com/go-task/task/v3/taskfile/ast"
|
2019-02-24 17:25:27 +02:00
|
|
|
)
|
|
|
|
|
2024-01-26 16:34:18 +02:00
|
|
|
func PrintTasks(l *logger.Logger, t *ast.Taskfile, c []*ast.Call) {
|
2019-03-04 13:25:42 +02:00
|
|
|
for i, call := range c {
|
2020-01-20 15:38:18 +02:00
|
|
|
PrintSpaceBetweenSummaries(l, i)
|
2024-02-22 22:52:05 +02:00
|
|
|
PrintTask(l, t.Tasks.Get(call.Task))
|
2019-03-04 13:25:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-20 15:38:18 +02:00
|
|
|
func PrintSpaceBetweenSummaries(l *logger.Logger, i int) {
|
2019-03-04 13:27:10 +02:00
|
|
|
spaceRequired := i > 0
|
|
|
|
if !spaceRequired {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Default, "\n")
|
|
|
|
l.Outf(logger.Default, "\n")
|
2019-03-04 13:27:10 +02:00
|
|
|
}
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func PrintTask(l *logger.Logger, t *ast.Task) {
|
2019-02-24 19:20:59 +02:00
|
|
|
printTaskName(l, t)
|
2019-03-04 14:04:04 +02:00
|
|
|
printTaskDescribingText(t, l)
|
|
|
|
printTaskDependencies(l, t)
|
2022-10-02 00:39:44 +02:00
|
|
|
printTaskAliases(l, t)
|
2019-03-04 14:04:04 +02:00
|
|
|
printTaskCommands(l, t)
|
|
|
|
}
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func printTaskDescribingText(t *ast.Task, l *logger.Logger) {
|
2019-02-24 19:20:59 +02:00
|
|
|
if hasSummary(t) {
|
|
|
|
printTaskSummary(l, t)
|
2019-02-24 19:26:16 +02:00
|
|
|
} else if hasDescription(t) {
|
2019-02-24 19:20:59 +02:00
|
|
|
printTaskDescription(l, t)
|
2019-02-24 19:26:16 +02:00
|
|
|
} else {
|
2019-02-24 20:14:15 +02:00
|
|
|
printNoDescriptionOrSummary(l)
|
2019-02-24 19:20:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func hasSummary(t *ast.Task) bool {
|
2019-02-24 20:14:15 +02:00
|
|
|
return t.Summary != ""
|
2019-02-24 17:26:46 +02:00
|
|
|
}
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func printTaskSummary(l *logger.Logger, t *ast.Task) {
|
2019-02-24 20:14:15 +02:00
|
|
|
lines := strings.Split(t.Summary, "\n")
|
2019-02-24 19:26:16 +02:00
|
|
|
for i, line := range lines {
|
|
|
|
notLastLine := i+1 < len(lines)
|
|
|
|
if notLastLine || line != "" {
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Default, "%s\n", line)
|
2019-02-24 19:26:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func printTaskName(l *logger.Logger, t *ast.Task) {
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Default, "task: ")
|
|
|
|
l.Outf(logger.Green, "%s\n", t.Name())
|
|
|
|
l.Outf(logger.Default, "\n")
|
2019-02-24 17:25:27 +02:00
|
|
|
}
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func printTaskAliases(l *logger.Logger, t *ast.Task) {
|
2022-10-02 00:39:44 +02:00
|
|
|
if len(t.Aliases) == 0 {
|
|
|
|
return
|
|
|
|
}
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Default, "\n")
|
|
|
|
l.Outf(logger.Default, "aliases:\n")
|
2022-10-02 00:39:44 +02:00
|
|
|
for _, alias := range t.Aliases {
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Default, " - ")
|
|
|
|
l.Outf(logger.Cyan, "%s\n", alias)
|
2022-10-02 00:39:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func hasDescription(t *ast.Task) bool {
|
2019-02-24 20:14:15 +02:00
|
|
|
return t.Desc != ""
|
2019-02-24 19:26:16 +02:00
|
|
|
}
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func printTaskDescription(l *logger.Logger, t *ast.Task) {
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Default, "%s\n", t.Desc)
|
2019-02-24 19:26:16 +02:00
|
|
|
}
|
|
|
|
|
2019-02-24 20:14:15 +02:00
|
|
|
func printNoDescriptionOrSummary(l *logger.Logger) {
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Default, "(task does not have description or summary)\n")
|
2019-02-24 17:25:27 +02:00
|
|
|
}
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func printTaskDependencies(l *logger.Logger, t *ast.Task) {
|
2019-03-04 13:46:02 +02:00
|
|
|
if len(t.Deps) == 0 {
|
|
|
|
return
|
|
|
|
}
|
2019-02-24 17:25:27 +02:00
|
|
|
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Default, "\n")
|
|
|
|
l.Outf(logger.Default, "dependencies:\n")
|
2019-03-04 13:46:02 +02:00
|
|
|
|
|
|
|
for _, d := range t.Deps {
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Default, " - %s\n", d.Task)
|
2019-02-24 17:25:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
func printTaskCommands(l *logger.Logger, t *ast.Task) {
|
2019-03-04 13:28:26 +02:00
|
|
|
if len(t.Cmds) == 0 {
|
2019-03-04 13:28:11 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Default, "\n")
|
|
|
|
l.Outf(logger.Default, "commands:\n")
|
2019-03-04 13:28:11 +02:00
|
|
|
for _, c := range t.Cmds {
|
|
|
|
isCommand := c.Cmd != ""
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Default, " - ")
|
2019-03-04 13:28:11 +02:00
|
|
|
if isCommand {
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Yellow, "%s\n", c.Cmd)
|
2019-03-04 13:28:11 +02:00
|
|
|
} else {
|
2023-04-27 02:20:06 +02:00
|
|
|
l.Outf(logger.Green, "Task: %s\n", c.Task)
|
2019-02-24 17:25:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|