1
0
mirror of https://github.com/go-task/task.git synced 2025-07-17 01:43:07 +02:00

refactoring

This commit is contained in:
jaedle
2019-02-24 19:14:15 +01:00
parent c158608255
commit 2a1571a99e

View File

@ -13,66 +13,66 @@ func Print(l *logger.Logger, t *taskfile.Task) {
} else if hasDescription(t) { } else if hasDescription(t) {
printTaskDescription(l, t) printTaskDescription(l, t)
} else { } else {
printErrorNoDescriptionOrSummary(l) printNoDescriptionOrSummary(l)
} }
printTaskDependencies(l, t) printTaskDependencies(l, t)
printTaskCommands(l, t) printTaskCommands(l, t)
} }
func hasSummary(task *taskfile.Task) bool { func hasSummary(t *taskfile.Task) bool {
return task.Summary != "" return t.Summary != ""
} }
func printTaskSummary(Logger *logger.Logger, task *taskfile.Task) { func printTaskSummary(l *logger.Logger, t *taskfile.Task) {
lines := strings.Split(task.Summary, "\n") lines := strings.Split(t.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 != "" {
Logger.Outf(line) l.Outf(line)
} }
} }
} }
func printTaskName(Logger *logger.Logger, task *taskfile.Task) { func printTaskName(l *logger.Logger, t *taskfile.Task) {
Logger.Outf("task: " + task.Task) l.Outf("task: " + t.Task)
Logger.Outf("") l.Outf("")
} }
func hasDescription(task *taskfile.Task) bool { func hasDescription(t *taskfile.Task) bool {
return task.Desc != "" return t.Desc != ""
} }
func printTaskDescription(Logger *logger.Logger, task *taskfile.Task) { func printTaskDescription(l *logger.Logger, t *taskfile.Task) {
Logger.Outf(task.Desc) l.Outf(t.Desc)
} }
func printErrorNoDescriptionOrSummary(l *logger.Logger) { func printNoDescriptionOrSummary(l *logger.Logger) {
l.Outf("(task does not have description or summary)") l.Outf("(task does not have description or summary)")
} }
func printTaskDependencies(logger *logger.Logger, task *taskfile.Task) { func printTaskDependencies(l *logger.Logger, t *taskfile.Task) {
hasDependencies := len(task.Deps) > 0 hasDependencies := len(t.Deps) > 0
if hasDependencies { if hasDependencies {
logger.Outf("") l.Outf("")
logger.Outf("dependencies:") l.Outf("dependencies:")
for _, d := range task.Deps { for _, d := range t.Deps {
logger.Outf(" - %s", d.Task) l.Outf(" - %s", d.Task)
} }
} }
} }
func printTaskCommands(logger *logger.Logger, task *taskfile.Task) { func printTaskCommands(l *logger.Logger, t *taskfile.Task) {
hasCommands := len(task.Cmds) > 0 hasCommands := len(t.Cmds) > 0
if hasCommands { if hasCommands {
logger.Outf("") l.Outf("")
logger.Outf("commands:") l.Outf("commands:")
for _, c := range task.Cmds { for _, c := range t.Cmds {
isCommand := c.Cmd != "" isCommand := c.Cmd != ""
if isCommand { if isCommand {
logger.Outf(" - %s", c.Cmd) l.Outf(" - %s", c.Cmd)
} else { } else {
logger.Outf(" - Task: %s", c.Task) l.Outf(" - Task: %s", c.Task)
} }
} }
} }