Description
Summary
When working in a Go module where a version of Task is declared as a tool dependency, transfer execution to go tool task.
Rationale
Since Go 1.24 the Go toolchain has special support for versioning tools in go.mod: https://go.dev/doc/modules/managing-dependencies#tools
As Task is written in Go, it can be installed as a tool (see also #2783).
But for a complete integration, it would be better to ensure that task and go tool task run the same version.
So I propose that the task command running from $PATH would delegate to the version of the task command declared in go.mod.
Proposal
When:
task detects it works from a Go module (a go.mod is found in a directory up to the directory of the Taskfile.yml config)
go env GO111MODULE is not off
- that go.mod declares a version of task (
github.com/go-task/task/v[1-9][0-9]*/cmd/task) in a tool directive: the go tool command lists the declared tools
- there is a single tool named
task declared (avoid ambiguous tool)
task isn't already the exact requested version (matching runtime/debug.BuildInfo): avoid useless recursion
task has been launched as a simple command (os.Args[0] is not an absolute path, and doesn't even contain a path separator): avoid infinite recursion, and let the user override this behavior
Then:
- Pass all the received arguments (
os.Args[1:]) to go tool task and exit
Related issues
Implementation hints
Usefull go commands:
go list tool: list tools declared in the Go module
go list -f '{{.ImportPath}}{{if not .Module.Main}}@{{.Module.Version}}{{end}}' tool: list tools with their versions
go list -f '{{.Module.Version}}' github.com/go-task/task/v3/cmd/task: list the requested version of Task
Description
Summary
When working in a Go module where a version of Task is declared as a tool dependency, transfer execution to
go tool task.Rationale
Since Go 1.24 the Go toolchain has special support for versioning tools in
go.mod: https://go.dev/doc/modules/managing-dependencies#toolsAs
Taskis written in Go, it can be installed as a tool (see also #2783).But for a complete integration, it would be better to ensure that
taskandgo tool taskrun the same version.So I propose that the
taskcommand running from$PATHwould delegate to the version of thetaskcommand declared ingo.mod.Proposal
When:
taskdetects it works from a Go module (a go.mod is found in a directory up to the directory of theTaskfile.ymlconfig)go env GO111MODULEis notoffgithub.com/go-task/task/v[1-9][0-9]*/cmd/task) in atooldirective: thego toolcommand lists the declared toolstaskdeclared (avoid ambiguous tool)taskisn't already the exact requested version (matchingruntime/debug.BuildInfo): avoid useless recursiontaskhas been launched as a simple command (os.Args[0]is not an absolute path, and doesn't even contain a path separator): avoid infinite recursion, and let the user override this behaviorThen:
os.Args[1:]) togo tool taskand exitRelated issues
go toolgolang/go#78673Implementation hints
Usefull
gocommands:go list tool: list tools declared in the Go modulego list -f '{{.ImportPath}}{{if not .Module.Main}}@{{.Module.Version}}{{end}}' tool: list tools with their versionsgo list -f '{{.Module.Version}}' github.com/go-task/task/v3/cmd/task: list the requested version of Task