Problem: You have a ./gen.go
script that uses github.com/arkady-emelyanov/go-shellparse
to do some stuff. When you run go mod tidy
it removes github.com/arkady-emelyanov/go-shellparse
from your go.mod
because ./gen.go
has a //go:build ignore
in it... which means go mod tidy
doesn't include it in its checks. 😔
gen.go
//go:build ignore
package main
import (
"github.com/arkady-emelyanov/go-shellparse"
// etc.
)
func main() {
shellparse.ParseVarsFile("file.txt")
exec.Command("go", "run", "github.com/melbahja/got/cmd/got").Run()
}
Solution: Use tools.go
with //go:build tools
which go mod tidy
does scan and add any dependencies to list all the dependencies that ./gen.go
needs.
tools.go
//go:build tools
package tools
import (
_ "github.com/melbahja/got/cmd/got"
_ "github.com/arkady-emelyanov/go-shellparse"
// etc.
)
go run ./gen.go
Further reading 📚