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 · 3 comments
Closed

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

fananchong opened this issue Apr 21, 2019 · 3 comments
Labels
Milestone

Comments

@fananchong
Copy link

@fananchong 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
@gopherbot gopherbot added the Proposal label Apr 21, 2019
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Apr 22, 2019

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

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

This comment has been minimized.

Copy link

@beoran 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

This comment has been minimized.

Copy link
Contributor

@rsc 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 Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.