Skip to content

Commit

Permalink
Allow adding more tasks to meta tasks (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
chokoswitch authored May 13, 2024
1 parent 5a4b64f commit a301ee0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
24 changes: 24 additions & 0 deletions registry.go
Original file line number Diff line number Diff line change
@@ -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)
}
20 changes: 16 additions & 4 deletions standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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.",
Expand All @@ -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{
Expand Down

0 comments on commit a301ee0

Please sign in to comment.