From a301ee03128da05489ceaaea6212cb52aeab0e90 Mon Sep 17 00:00:00 2001 From: Choko Date: Mon, 13 May 2024 18:03:55 +0900 Subject: [PATCH] Allow adding more tasks to meta tasks (#3) --- registry.go | 24 ++++++++++++++++++++++++ standard.go | 20 ++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 registry.go diff --git a/registry.go b/registry.go new file mode 100644 index 0000000..f2b4c63 --- /dev/null +++ b/registry.go @@ -0,0 +1,24 @@ +package build + +import "github.com/goyek/goyek/v2" + +var ( + formatTasks goyek.Deps + generateTasks goyek.Deps + lintTasks goyek.Deps +) + +// RegisterFormatTask adds a task that should be run during the format command. +func RegisterFormatTask(task *goyek.DefinedTask) { + formatTasks = append(formatTasks, task) +} + +// RegisterGenerateTask adds a task that should be run during the generate command. +func RegisterGenerateTask(task *goyek.DefinedTask) { + generateTasks = append(generateTasks, task) +} + +// RegisterLintTask adds a task that should be run during the lint command. +func RegisterLintTask(task *goyek.DefinedTask) { + lintTasks = append(lintTasks, task) +} diff --git a/standard.go b/standard.go index 65b5ab8..bc04b8e 100644 --- a/standard.go +++ b/standard.go @@ -15,9 +15,9 @@ func DefineTasks(opts ...Option) { o.apply(&conf) } - goyek.Define(goyek.Task{ - Name: "format", - Usage: "Formats the code.", + formatGo := goyek.Define(goyek.Task{ + Name: "format-go", + Usage: "Formats Go code.", Action: func(a *goyek.A) { cmd.Exec(a, fmt.Sprintf("go run mvdan.cc/gofumpt@%s -l -w .", verGoFumpt)) @@ -30,6 +30,18 @@ func DefineTasks(opts ...Option) { }, }) + goyek.Define(goyek.Task{ + Name: "format", + Usage: "Format code in various languages.", + Deps: append(goyek.Deps{formatGo}, formatTasks...), + }) + + goyek.Define(goyek.Task{ + Name: "generate", + Usage: "Generates code.", + Deps: generateTasks, + }) + lintGo := goyek.Define(goyek.Task{ Name: "lint-go", Usage: "Lints Go code.", @@ -49,7 +61,7 @@ func DefineTasks(opts ...Option) { lint := goyek.Define(goyek.Task{ Name: "lint", Usage: "Lints code in various languages.", - Deps: goyek.Deps{lintGo, lintYaml}, + Deps: append(goyek.Deps{lintGo, lintYaml}, lintTasks...), }) test := goyek.Define(goyek.Task{