gow
gow copied to clipboard
Go generate steps
Hey, this is a really sweet tool
Can I somehow make sure go generate steps are run on reload as well ? If not I might be interested in contributing something like it :-)
Greetings
Currently it requires an additional script. Something like:
touch go.sh
chmod +x go.sh
Content of go.sh:
#!/bin/sh
go generate &&
go $@
Usage:
gow -g=./go.sh -v -c run .
The current implementation of gow runs exactly one subprocess. In principle, it can be generalized to run a sequence of subprocesses, which would be fairly similar to a script, and not necessarily better. Suggestions are welcome.
Ok, interesting solution.. hm... adding a flag that allows triggering go generate with a path would do the trick right ?
Today we'd be adding support for go generate, tomorrow for another subcommand, and so on. Having a flag in gow for every subcommand in go is not a good API for the user and creates more maintenance. The general approach would be to support a sequence of subcommands, as stated above. However, a script already does exactly that. Right now, I'm not sure if gow can provide a multi-command API that's significantly better than a shell script. But I haven't given this much thought yet.
What's unclear is how to pass arguments to go subcommands in a multi-command gow API. They want to share some arguments, such as FS paths. For example, if you want to go run a specific directory, you'd also go generate that specific directory. They also don't share some arguments. If in practice, you have to pass a sequence of subcommands with their own lists of arguments, well, it's just like a shell script. If you have other thoughts, I'd like to hear.
Hm... so I would argue that go generate is a special case here. As it is used to trigger preprocessor steps it is something you definitely want to run before the run or build commands.
Additionally it allows you to specify a sequence of steps in your go files by its own nature, so the only thing we need to add is a path
gow -g=./... run . feels like it would be nice to add. The list of go subcommands is rather limited and unlikely to expand very quickly... so I feel to save the hastle (which is what this tool feels like its all about) having shortcuts would be a benefit. When I go for scripting I could likely also just make me a watcher script myself using fswatch or similar
if you want to add other subcommands for a start you can even include them via the generate option by calling go from within //go:generate
So thats my take on it :-)
Please clarify the intended behavior of gow -g=./.... This flag currenty defines the first argument passed to exec.Command.
If we really wanted multi-command support, the CLI interface could look like this:
gow -c -v -- generate -- run .
Argument terminator could be configurable:
gow -c -v -t=••• ••• generate ••• run .
A slightly more general form would take full command + argument lists without implicitly prepending go, if an empty string is passed to -g:
gow -c -v -g= -- go generate -- go run .