Presently, for go run <arg> to work, the <arg> will need to have a bundle fundamental and a func fundamental. If it has the latter, however not the previous, you get error:
bundle command-line-arguments isn't a fundamental bundle
Why not change go run to permit it to run any bundle that has a func fundamental?
This wants 2 adjustments to the go run <arg> command:
- if resolves to a bundle path and that bundle has a
func fundamental, run that. - in any other case (present conduct), look in for a
fundamentalbundle with afunc fundamentaland run that or, if not discovered, give an error. The error must be modified from:
bundle command-line-arguments isn't a fundamental bundle
to
bundle command-line-arguments doesn't have a fundamental operate and isn't a fundamental bundle
(or phrases to that impact)
Execs:
- makes go toolchain extra common, and, I assert, easier. Removes what seems to be an arbitrary restriction (“
func fundamentalsolely means command entry level if it’s inbundle fundamental”) - is a backward appropriate extension of the API. Doesn’t break any program that was beforehand working.
Cons:
- There is likely to be some current cmd tasks that have already got
fundamental()in non-main packages. This proposal wouldn’t break any current manner of invoking such a mission (since all of them undergobundle fundamental). But it surely may conceivably trigger a take a look at to fail, e.g the mission had an specific take a look at for an error fromgo run <non-main-package>. So there are code adjustments {that a} mission may need to make merely to retain all-tests-pass standing if the proposal had been carried out.
Right here’s my use case:
I’ve a set of documentation samples, every of which is a brief, standalone program (that means reader may run it by a go run command). I wish to preserve the sources in a single mission (i.e. in a single module). How ought to I construction the mission so I can run any chosen pattern?
- I may put every pattern in a separate bundle however with a
func fundamental, then implement a top-level driver that is aware of find out how to invoke every particular person code pattern bundle. The invocation can be one thing likego run driver <pattern>.
There’s the redundancy of getting to offer this driver and likewise of getting to place every pattern program in a separate subdirectory as a result of it’s in a separate bundle. - (What I’m at present doing as a workaround) I preserve every pattern program in a separate supply file (within the mission root). Every file has
bundle fundamentalandfunc fundamental.
I can invoke the chosen pattern by way ofgo run <pattern>.go(word it’s a file path). I can’tgo take a look atorgo constructthe module (due to duplicate definitions offunc fundamental), however I stay with that for now.

