godo icon indicating copy to clipboard operation
godo copied to clipboard

Gododir handling

Open GeertJohan opened this issue 10 years ago • 5 comments

I thought Gododir would become a package providing func Tasks(p *Project) as the main entry point; dropping the need for a Godofile.go and allowing the user to split functionality/tasks across go multiple files. Maybe this is also what you want to do in the end, but v1.2 is still relying on a single file named Gododir/Godofile.go.

I propose to change godo's behaviour concerning Gododir in the following (backwards compatible) way: The godo cmd will use the standard library go/build package to parse the go files in Gododir. If the package is a main package, it is expected that it contains a main() function and is built+executed directly. If the package name is different, a Godofile_main.go is written to tmp and executed with go run (same behaviour as current situation).

If there is a Gododir AND a tasks/Godofile.go, the first one is used.

For non-main packages the func Tasks(p *Project) is defined as godo entry point.

For consistency we could enforce the usage of package tasks instead of package <anything>. This is a breaking change of course, but very easy to update.

I would be happy to implement this.

GeertJohan avatar Nov 06 '14 09:11 GeertJohan

I'm not understanding func Tasks(p *Project as the main entry point. Show a gist of the files of an example having a hello world task and another task that depends on it. I'll understand better. What's important is that there isn't too much magic breaking editor code completion.

mgutz avatar Nov 06 '14 14:11 mgutz

Right now when a Godofile is not a package main you generate a Godofile_main.go file that imports the Godofile.go as a package and runs godo.Godo(pkg.Tasks). https://github.com/go-godo/godo/blob/master/cmd/godo/main.go#L91:L98

I propose that this behaviour stays the same. But instead it checks the complete Gododir directory to be a main or non-main package by using go/build instead of checking just the single Gododir/Godofile.go file with regexp.

GeertJohan avatar Nov 06 '14 15:11 GeertJohan

I've created a gist explaining some of the ideas, please start with reading the README https://gist.github.com/GeertJohan/ffb378b6e6522e2b4661

GeertJohan avatar Nov 17 '14 10:11 GeertJohan

Any thoughts on this? If you agree I can do implementation

GeertJohan avatar Nov 24 '14 14:11 GeertJohan

on holidays. sure!

mgutz avatar Nov 24 '14 16:11 mgutz