Documentation
¶
Index ¶
- func ExpandShell(s string, data map[string]any) string
- func IsSH() booldeprecated
- func Replace[T any](v T, cache *Cache) T
- func ReplaceGlobs(globs []*ast.Glob, cache *Cache) []*ast.Glob
- func ReplaceNoShell[T any](v T, cache *Cache) T
- func ReplaceNoShellWithExtra[T any](v T, cache *Cache, extra map[string]any) T
- func ReplaceVar(v ast.Var, cache *Cache) ast.Var
- func ReplaceVarWithExtra(v ast.Var, cache *Cache, extra map[string]any) ast.Var
- func ReplaceVars(vars *ast.Vars, cache *Cache) *ast.Vars
- func ReplaceVarsWithExtra(vars *ast.Vars, cache *Cache, extra map[string]any) *ast.Vars
- func ReplaceWithExtra[T any](v T, cache *Cache, extra map[string]any) T
- func ResolveRef(ref string, cache *Cache) any
- type Cache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpandShell ¶
ExpandShell expands shell-native variable references in s against data. Recognizes:
- ${NAME} — bracketed form, NAME must be [a-zA-Z_][a-zA-Z0-9_]*
- $NAME — unbracketed form, NAME same charset
- $$ — literal $ (SPEC §Template Syntax)
Unknown references are left literal so the shell can handle them — e.g. `$?`, `$1`, or an env-only var not declared in the Ritefile pass through unchanged for mvdan/sh to interpret downstream. Only refs whose name is a known key in data get substituted.
Quoting honors POSIX shell semantics: `'…'` suppresses expansion entirely, `"…"` keeps expanding, `\$` outside or inside double quotes is a literal `$`. Heredocs participate too — `<<'DELIM'` or `<<\DELIM` disables expansion in the body; bare `<<DELIM` keeps it. Single-quoted strings treat `\` as a literal character (POSIX). This exists so Ritefiles can emit literal `$X` runs (heredoc help text, sed scripts, etc.) without sentinel workarounds — see #121.
func ReplaceNoShell ¶
ReplaceNoShell is like Replace but skips the ExpandShell pass. Use this for strings that will be handed to a shell for interpretation (task cmd.Cmd): the shell resolves `$VAR` against its own env, and until Phase 4's vars/env unification lands, rite vars and the shell env can have different values for the same name. Running ExpandShell on a shell-bound string would pre-empt the shell with rite's var-set answer, which is premature — the endstate is correct but wave 3 hasn't yet collapsed the tiers.
func ReplaceNoShellWithExtra ¶
ReplaceNoShellWithExtra is the for-loop iterator counterpart to ReplaceNoShell — same shell-bypass, but accepts per-iteration extras.
func ReplaceVarWithExtra ¶
func ReplaceVarsWithExtra ¶
func ResolveRef ¶
Types ¶
type Cache ¶
Cache is a help struct that allow us to call "replaceX" funcs multiple times, without having to check for error each time. The first error that happen will be assigned to r.err, and consecutive calls to funcs will just return the zero value.
Safe for concurrent use: internal state is guarded by mu. Concurrent Replace calls from different goroutines (e.g. the output.Group wrappers used by parallel deps) used to race on the cacheMap lazy init — see #52.
func (*Cache) ResetCache ¶
func (r *Cache) ResetCache()