Closed azr closed 4 years ago
Thanks for the suggestion. However, the go generate
command doesn't have any way to notice which inputs files matter to go generate
, so it would have to watch for all changes. I think most people would rather watch just for changes to the file to matter, which would require a custom solution. And for that matter it would be a fairly simple custom solution to wait for any change in a directory and invoke go generate
, which is what go generate -watch
would do. So I tend to think 1) this would not do what most people want; 2) for the people who do want this, it can be done fairly easily. So to me this doesn't seem worth doing in the go tool.
I think another reason not to do this is that we'd probably have to do it consistently for go build
, go test
, and so on. The complexity grows rapidly, in my mind. For example, besides watching for changes in all Go source including dependencies, go test -watch
would need to somehow watch all testdata files and directories too.
Just to add one final comment that it's already possible to use a file watcher (e.g. inotifywait
, fswatch
etc) to run commands (e.g. go generate
) when files change.
Building on @ianlancetaylor's point:
However, the go generate command doesn't have any way to notice which inputs files matter to go generate, so it would have to watch for all changes
This was part of the motivation behind my work on the experimental gogenerate
. That way you amortise the cost of repeatedly running gogenerate
, because if you have a cache hit no work will be done.
I'd be happy to continue discussion/questions in that repo
I understand and agree; closing this one for ya ! Thanks for taking the time to answer ! 🙂
TLDR: add
go generate -watch
to watch for changes in a folder to rungo generate
when a file is changed.I think go generate is really awesome. In the packer repo that I help maintain, a lot of code and docs are "go generated" and I think it would be nice to not have to think about running
go generate
every-time I change a file: making my programming a bit less disrupted; moreover this would make performances ofgo generate
less of a problem. Right now ago generate
is taking 8 minutes for us.My gut feeling tells me that making/maintaining this would be way too complicated for the gain but may be I'm wrong !
In the meantime I'll be using https://github.com/fsnotify/fsnotify