This is far from an ideal solution, but you could use a directive of the form
//go:generate -command <alias> <command-with-parameters>
The directive above specifies, for the remainder of the current source file only, that <alias>
is equivalent to the command <command-with-parameters>
.
This method might be useful in your case since you mentioned that you needed to pass a certain number of parameters (I'm assuming lots). You could potentially use it to emulate a single line break. I say single because nested aliases don't work (at least right now).
An example:
//go:generate BAKE "ramen"
// The above go:generate directive does NOT work, unless:
// - You somehow have bake on your path.
// - You did a `//go:generate -command BAKE ...`
/* Now, assuming you have a command `kitchen-tools` with lots of possible parameters... */
//go:generate -command BAKE kitchen-tools -appliance=sun -temp=5800K -time=1ns
//go:generate BAKE -panic=if-burnt -safety=fire_extinguisher,mitts "fresh pizza"
// The previous //go:generate line runs the following command:
// kitchen-tools -appliance=sun -temp=5800K -time=1ns -panic=always -safety=fire_extinguisher,mitts "fresh pizza"
/* BAKE can be used as many times as necessary for the rest of the file. For instance... */
//go:generate BAKE -no-return -unsafe "grand piano"
Furthermore, I suggest you use the build tag generate
(rather than something like ignore
) since the go generate tool sets the build tag generate
when it examines your files:
// +build generate
package main
// ...
go:generate
must be a single line. If your command is too long for your taste you would need to move it to e.g. a shell script, and execute that script viago:generate
. – Pinball