gosh

command module
v0.0.0-...-6905f2b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 8, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

README

gosh: run shell commands embedded in Go comments

Install: go install github.com/mdempsky/gosh@latest

Demo:

$ cat demo.go
package demo

//go:generate gosh -w $GOFILE
//gosh:ok

// % date
$ go generate demo.go
$ cat demo.go
package demo

//go:generate gosh -w $GOFILE
//gosh:ok

/* # date
Mon Apr  8 12:22:29 PM PDT 2024
*/

Documentation

Overview

The gosh command runs shell commands embedded in Go source file comments.

Usage:

gosh [-w] [packages]

Gosh searches source files for comments that start with "// % " or "/* % ". It then runs the first line of the comment as a shell command, and replaces the remaining lines with the output of the command. It also replaces the "%" with "#". Shell commands are run concurrently.

For security, shell commands are disabled by default. The "//gosh:ok" directive enables commands, and the "//gosh:deny" directive disables them again. Both directives only apply to the end of their innermost scope.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL