markbates / grift

Go based task runner
MIT License
432 stars 24 forks source link

build fails in go module #29

Closed rrrkren closed 6 years ago

rrrkren commented 6 years ago

Steps to reproduce:

mkdir testgrift && cd "$_"  #(outside of $GOPATH)
git init
git remote add origin git@github.com:rrrkren/testgrift.git
go mod init
grift init
grift hello

gives error:

build github.com/rrrkren/testgrift/.grifter: cannot find module for path testgrift/grifts
exit status 1

when I do this process without the git part everything work fine

rrrkren commented 6 years ago

The problem lies on https://github.com/markbates/grift/blob/master/cmd/grifter.go#L72,

g.GriftsPackagePath = filepath.ToSlash(filepath.Join(path.Base(currentPath), "grifts"))

assumes that the go module name is the same as the package name and the current directory name. In my case the module name was "github.com/rrrkren/testgrift". I'm fairly new to go but since this was generated by go mod I assume it's valid. hardcoding g.GriftsPackagePath to "github.com/rrrkren/testgrift/grifts" makes it run, obviously not a fix but more of a hack which works for us now. I'm going to hack something up for my use case, probably reading it off the go.mod file. Let me know if you are interested.