TL;DR: Use a tools.go
file with //go:build tools
to list import _ "github.com/octocat/somedevtool"
to stop go mod tidy
from removing them.
//go:build tools
package tools
import (
_ "github.com/melbahja/got/cmd/got"
_ "github.com/arkady-emelyanov/go-shellparse"
)
π‘ go mod tidy
doesn't care if the package is cmd or lib
Then you can use whatever you list in tools.go
in //go:generate
and task.go
!
package mylib
//go:generate -command got go run github.com/melbahja/got/cmd/got
import (
"fmt"
_ "embed"
)
//go:generate got https://example.org/image.png -o image.png
//go:embed image.png
var imagePNG []byte
// task.go
//go:build ignore
package main
import "github.com/arkady-emelyanov/go-shellparse"
func main() {
// ...
}
π Use task.go for your Go project scripts
Other resources
Top comments (0)