Help us shape the future of Go! Take the 2026 Go Developer Survey

tmpl

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package tmpl provides template rendering utilities for shell commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShellQuote added in v0.60.0

func ShellQuote(s string) string

ShellQuote quotes s as one POSIX shell word: single quotes, with each embedded single quote closed, escaped and re-opened. Templates reach it as shq.

func UntrustedFuncs added in v0.60.0

func UntrustedFuncs() template.FuncMap

UntrustedFuncs returns the helpers that fence outside content (a PR body, a webhook payload) in a prompt:

  • untrustedStart renders the opening tag. It takes optional key/value pairs that become attributes: {{ untrustedStart "source" "github" }}.
  • untrustedEnd renders the closing tag.
  • untrustedNotice renders a sentence telling the agent what the tags mean.

The id is part of the tag name rather than an attribute because a closing tag cannot carry attributes, and a bare closer would be trivial to forge. It is drawn fresh for each call, so call this once per render: content written before the render cannot know the id, and a closing tag it carries cannot close the fence.

Types

type Config

type Config struct {
	ScriptPaths  map[string]string // "hive-tmux" -> "/path/to/bin/hive-tmux"
	AgentCommand string            // default profile command (e.g., "claude")
	AgentWindow  string            // default profile key / tmux window name
	AgentFlags   string            // shell-quoted flags string
}

Config holds all template rendering context.

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer renders Go templates with shell-oriented helper functions.

func New

func New(cfg Config) *Renderer

New creates a Renderer with the given config baked into template functions.

func NewValidation

func NewValidation() *Renderer

NewValidation creates a Renderer with safe defaults for template syntax checking. Template functions return placeholder values — output is discarded, only parse errors matter.

func (*Renderer) Render

func (r *Renderer) Render(tmpl string, data any) (string, error)

Render executes a Go template string with the given data.

func (*Renderer) ValidateSyntax added in v0.55.0

func (r *Renderer) ValidateSyntax(tmpl string) error

ValidateSyntax parses tmpl without executing it. Use this instead of Render when the template's data shape includes dynamic map fields (e.g. map[string]any) whose keys can't be known at validation time — executing with missingkey=error would reject valid templates referencing keys that only exist at render time.

func (*Renderer) WithAgent added in v0.49.0

func (r *Renderer) WithAgent(command, window, flags string) *Renderer

WithAgent returns a new Renderer with the agent values overridden. All other config (script paths etc.) is inherited from the receiver.

Jump to

Keyboard shortcuts

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