Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go generate steps #37

Open
s00500 opened this issue Sep 9, 2023 · 6 comments
Open

Go generate steps #37

s00500 opened this issue Sep 9, 2023 · 6 comments

Comments

@s00500
Copy link

s00500 commented Sep 9, 2023

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

@mitranim
Copy link
Owner

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.

@s00500
Copy link
Author

s00500 commented Sep 11, 2023

Ok, interesting solution..
hm... adding a flag that allows triggering go generate with a path would do the trick right ?

@mitranim
Copy link
Owner

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.

@s00500
Copy link
Author

s00500 commented Sep 12, 2023

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

@mitranim
Copy link
Owner

Please clarify the intended behavior of gow -g=./.... This flag currenty defines the first argument passed to exec.Command.

@mitranim
Copy link
Owner

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 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants