Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 10dcaf4

Browse files
committed
present: document shebang and txtar for .play
The "play" command for present does not only support Go code, which was implicitly documented, but also generic scripts identified by a shebang or txtar-encoded input - enabling Go modules. The locally used implementation for "play" resides in ./playground/socket/socket.go. Mostly undocumented, this code first checks the input for a shebang and, if present, executes input with the shebang interpreter. This code also allows txtar-encoded input, which can be used to "play" Go modules, including external dependencies. Documenting the actual behavior helps users to understand and use the software better. Personally, I initially wanted to patch Go module support in present, just to find out everything is already there - just undocumented.
1 parent 8866876 commit 10dcaf4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

present/doc.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,24 @@ on the displayed source so the program can be run from the browser.
287287
Although only the selected text is shown, all the source is included
288288
in the HTML output so it can be presented to the compiler.
289289
290+
By default, "play" compiles and executes Go code. But it is also
291+
possible to execute generic scripts if they start with a shebang.
292+
293+
When the Go code imports packages, they are expected to be present in
294+
the GOPATH.
295+
296+
However, Go modules are also possible for each "play" instruction if the
297+
input is txtar-encoded. See
298+
299+
https://pkg.go.dev/golang.org/x/tools/txtar
300+
301+
for a format description. The txtar input must contain a valid go.mod
302+
and go.sum file. A minimal Go module project of main.go, go.mod and
303+
go.sum can be txtar'ed like the following in a POSIX Shell:
304+
305+
$ cp main.go demo.txtar
306+
$ for f in go.{mod,sum}; do echo "-- $f --"; cat "$f"; done >> demo.txtar
307+
290308
link:
291309
292310
Create a hyperlink. The syntax is 1 or 2 space-separated arguments.

0 commit comments

Comments
 (0)