-
Notifications
You must be signed in to change notification settings - Fork 1
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
Please add a shebang/execution mode #7
Comments
@guilt would you be able to explain a bit or provide an example from other languages? |
An example of how this would look like, is given in here Essentially, this means having # as a comment line in golang, and that too, only required for the very first line. #!/usr/bin/env go run is how the script would be invoked. Scripts are written for routine system maintenance, infrastructure as code and plain old utilities. Many of them could be written as go files and invoked as scripts (as opposed to building and shipping binaries)... A lot of important infrastructure components are written in Go (Docker, k8s, Terraform etc.) and it would make sense to be able to invoke libraries as opposed to commands. See Pulumi examples for this approach. |
So this would let you execute the go file by running |
It makes scripting in go an easy construct, very much like python and perl. The only difference between those languages is that: go has better type safety. When used for infra tooling, this gives folks the ability to start writing/testing their better written utilities in go, and have direct access to the internals of many bespoke commands already written in go. |
@guilt I'm not that strong in scripting procedures per say, I'm sure what are the implications of designing goat as a scripting language and I'd like to get more opinions here. Would there be any follow up requirements? Adding # comments is quite a big fragmentation. Adding only first line support for shebangs seems more reasonable but I'm not sure what the implications are. Also, I didn't really understand if there's anything more than shortening |
Adding support for just the first line should be enough. Imagine this as equivalent to shipping scripts as code and making go as the base for writing systemwide scripts as necessary. I believe this would help with that. When it comes to prototyping scripts or utilities, the shebang mode can certainly help with that. Since the go toolchain is fairly self-contained it may be a great step towards increasing go adoption for system wide scripting as well. |
I'm still not sure about what I asked... shortening I agree that adding |
A shebang is a well known Unix standard that allows folks to put an invocation in the very first line, and what happens is that it allows the file to exec, and the execution takes care of reading the file, and if a shebang is found, uses the shebang line to be executed, and adds the file name as an argument to the end of it, and calls exec. So, if a go already allows people to run a If implemented correcrly, the shebang in the first line of an executable file would look like:
followed by |
Right now, there is a third party utility that has been written to do this, but the proposal asks for inclusion in the standard go interpreter for main files. |
I like the idea, but it's also a bit scary, because "non" developers might up destroying their system and Go gets the blame. I assume that such a "script" has a main function. |
Each go file that is runnable would get a shebang, and should be marked executable (x bits) |
I think @marcelloh was referring to the fact that each go file would need to contain a main function, but it won't compile since main will have already been declared in this package |
Well I think this could work if the executable is done in a tmp dir (like gorun does) |
I would be really interested in trying goat if there could be a shebang mode;
The idea is to write better statically checked scripts than bash/python for a variety of ops tasks.
The text was updated successfully, but these errors were encountered: