mage
mage copied to clipboard
`mage_output_file.go` fails to compile when default target has arguments
When using the following magefile.go
// +build mage
package main
import (
"fmt"
)
var Default = Build
func Build(version string) error {
fmt.Println("got:", version)
return nil
}
and attempting to run mage build hello
or mage hello
(not sure if this last one would work or not) causes the following error output.
❯ mage --keep build hello
# command-line-arguments
.\mage_output_file.go:348:22: undefined: x
.\mage_output_file.go:349:4: undefined: x
Error: error compiling magefiles
The generated mage_output_file.go
can be found at this Gist.
Commenting out var Default = Build
in the Magefile gives the expected output when run with mage build hello
.
❯ mage build hello
got: hello
Mage version
❯ mage --version
Mage Build Tool v1.11.0-2-g4cf3cfc
Build Date: 2021-03-25T17:39:36Z
Commit: 4cf3cfc
built with: go1.16
I really like the project, by the way ;)
Ooh, thanks for the bug report. I'll take a look tonight and bang out a fix. Evidently that's some combination there's no test for.
Ok, sorry this has sat so long. I think this is probably something that should not be allowed. mage hello
can be ambiguous if you have a default target that takes an argument and a target called "hello". I try pretty hard never to let the CLI be ambiguous.
So I think the trick here is to disallow default targets with arguments, and just give it a better error message.
No worries!
Yeah, disallowing defaults with arguments sounds like the better of the two options, for sure.
I met this issue today. thanks to this issue, I knew what was wrong.
Stumbled on this error today. @natefinch perhaps this should be closed, as it is more than one year old?