mage icon indicating copy to clipboard operation
mage copied to clipboard

`mage_output_file.go` fails to compile when default target has arguments

Open codemicro opened this issue 3 years ago • 5 comments

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 ;)

codemicro avatar Mar 27 '21 13:03 codemicro

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.

natefinch avatar Mar 27 '21 14:03 natefinch

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.

natefinch avatar May 18 '21 16:05 natefinch

No worries!

Yeah, disallowing defaults with arguments sounds like the better of the two options, for sure.

codemicro avatar May 19 '21 07:05 codemicro

I met this issue today. thanks to this issue, I knew what was wrong.

vvakame avatar Dec 16 '21 06:12 vvakame

Stumbled on this error today. @natefinch perhaps this should be closed, as it is more than one year old?

spolab avatar Dec 09 '22 06:12 spolab