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

proposal: cmd/go: make go:generate support wildcard patterns #31591

Closed
fananchong opened this issue Apr 21, 2019 · 5 comments
Closed

proposal: cmd/go: make go:generate support wildcard patterns #31591

fananchong opened this issue Apr 21, 2019 · 5 comments

Comments

@fananchong
Copy link

fananchong commented Apr 21, 2019

I execute the following command:

//go:generate cp *.proto ./mydir/

prompt:

+ go generate
cp: cannot stat '*.proto': No such file or directory
main.go:1: running "cp": exit status 1
@odeke-em odeke-em changed the title go generate does not support wildcards proposal: cmd/go: make go:generate support wildcard patterns Apr 21, 2019
@gopherbot gopherbot added this to the Proposal milestone Apr 21, 2019
@ianlancetaylor
Copy link
Contributor

It should be simple to just let the shell expand the wildcard. Write something like

//go:generate sh -c "cp *.proto ./mydir/"

@beoran
Copy link

beoran commented Apr 22, 2019

The shell is not available on some platforms, like Windows. The solution is to implement your own wildcard expansion tool in a subdirectory, let's say gentool of your project and then do

//go:generate go run gentool cp *.proto ./mydir/.

That should work on all platforms. Maybe there is already a tool like gentool out there, if not it's a few hours work to make one that does what you want.

@rsc
Copy link
Contributor

rsc commented Apr 24, 2019

You can already do //go:generate go run anything.go and put the code you need (whether it is glob expansion or something else) in anything.go. Let's do that instead of adding to the complexity of generate itself.

@rsc rsc closed this as completed Apr 24, 2019
@alifarooq0
Copy link

go generate should at least support multiple go files.

//go:generate go run interface_generator/*.go fails with

stat interface_generator/*.go: no such file or directory

@ianlancetaylor
Copy link
Contributor

@ali-farooq0 See the comments above. We've decided not to do this. Do it in the tool invoked by go:generate instead.

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

No branches or pull requests

6 participants