Documentation
¶
Overview ¶
funcs.go
generator.go
registry.go
Index ¶
- func CamelCase(s string) string
- func DefaultFuncMap() template.FuncMap
- func Generate(fsys fs.FS, m *Manifest, outputDir string, vars map[string]any) error
- func KebabCase(s string) string
- func NormalizeKey(s string) string
- func PascalCase(s string) string
- func ReadModulePath(dir string) (string, error)
- func RunHooks(ctx context.Context, m *Manifest, outputDir string) error
- func SnakeCase(s string) string
- func ValidateRegistryModule(module string) error
- type Generator
- type Hooks
- type Manifest
- type PostGenHooks
- type Registry
- type RegistryEntry
- type RegistryStore
- type Substitution
- type SubstitutionResult
- type TemplatizeReport
- type Variable
- type VariableKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultFuncMap ¶ added in v0.3.0
DefaultFuncMap returns the built-in template function map available in every goplt template. Callers may use this to inspect or extend the default set.
func Generate ¶
Generate walks fsys, renders each file with vars using Go text/template, and writes the output tree under outputDir. It is equivalent to NewGenerator().Generate(...) and is kept for backwards compatibility.
func NormalizeKey ¶
NormalizeKey converts hyphen-case, snake_case, or camelCase to PascalCase. "with-connect", "with_connect", and "withConnect" all produce "WithConnect".
func PascalCase ¶ added in v0.9.0
PascalCase, CamelCase, SnakeCase, KebabCase are exported so CLI commands can derive case forms without taking a direct dependency on xstrings.
func ReadModulePath ¶ added in v0.9.0
func RunHooks ¶
RunHooks executes the commands in m.Hooks.PostGenHooks sequentially, with outputDir as the working directory. Stops and returns an error on the first non-zero exit. Cancelling ctx terminates the running hook process.
func ValidateRegistryModule ¶ added in v0.13.0
ValidateRegistryModule enforces the v1 rules for a registered module path: non-empty, no local-path prefix, no @version, hostname must contain a dot.
Types ¶
type Generator ¶ added in v0.3.0
type Generator struct {
// contains filtered or unexported fields
}
Generator renders a template tree into an output directory. Construct one with NewGenerator; customise with WithFuncs.
func NewGenerator ¶ added in v0.3.0
func NewGenerator() *Generator
NewGenerator returns a Generator pre-loaded with the built-in function map.
type Hooks ¶
type Hooks struct {
PostGenHooks PostGenHooks `mapstructure:"post-generate"`
}
Hooks holds the hook commands declared under [hooks] in goplt.toml.
type Manifest ¶
type Manifest struct {
Description string // required one-line summary of what this template generates
Tags []string // optional; informational labels for filtering and discovery
Authors []string // optional; human-readable author names or handles
Variables []Variable
// unrendered path prefix → Go template boolean expression
Conditions map[string]string
Hooks Hooks
// optional Go template expression; rendered against vars to determine output subdirectory
TargetDir string
// template action delimiters; defaults to ["{{", "}}"]
Delimiters [2]string
// path pattern (contains {{.item}}) → [PascalCase varName]; single-element array in v1
Loops map[string][]string
}
Manifest holds the parsed content of a goplt.toml file.
type PostGenHooks ¶
type PostGenHooks []string
PostGenHooks is a list of post-generation shell commands.
type Registry ¶ added in v0.13.0
type Registry struct {
Collections []RegistryEntry `toml:"collections"`
}
Registry is the deserialised form of $XDG_CONFIG_HOME/goplt/registry.toml. The zero value is a valid, empty registry.
func (Registry) Add ¶ added in v0.13.0
Add returns a new Registry with module appended. It validates the module path and rejects duplicates. The receiver is not mutated.
type RegistryEntry ¶ added in v0.13.0
type RegistryEntry struct {
Module string `toml:"module"`
}
RegistryEntry is one registered template-collection root.
type RegistryStore ¶ added in v0.13.0
type RegistryStore struct {
// contains filtered or unexported fields
}
RegistryStore persists a Registry to a TOML file. The zero value is not usable; construct via DefaultRegistryStore or NewRegistryStore.
func DefaultRegistryStore ¶ added in v0.13.0
func DefaultRegistryStore() (*RegistryStore, error)
DefaultRegistryStore returns a RegistryStore pointed at $XDG_CONFIG_HOME/goplt/registry.toml on Linux, ~/Library/Application Support/goplt/registry.toml on macOS, %AppData%\goplt\registry.toml on Windows.
func NewRegistryStore ¶ added in v0.13.0
func NewRegistryStore(path string) *RegistryStore
NewRegistryStore returns a store that reads/writes at path. It is useful for tests and callers that want a non-default location.
func (*RegistryStore) Load ¶ added in v0.13.0
func (s *RegistryStore) Load() (Registry, error)
Load reads and parses the registry file. A missing file returns an empty Registry and nil error. Parse errors are wrapped.
func (*RegistryStore) Path ¶ added in v0.13.0
func (s *RegistryStore) Path() string
Path returns the on-disk location this store reads from and writes to.
func (*RegistryStore) Save ¶ added in v0.13.0
func (s *RegistryStore) Save(r Registry) error
Save writes the registry to disk, creating the parent directory if needed. File permission is 0o644; directory permission is 0o755.
type Substitution ¶ added in v0.9.0
func BuildSubstitutions ¶ added in v0.9.0
func BuildSubstitutions(name, orgPrefix string, skip []string) []Substitution
BuildSubstitutions derives all case forms of name and adds orgPrefix as-is. Skip strings become identity pairs (value == placeholder) so the replacer leaves them untouched. All pairs are sorted by value length descending so longer strings always win over shorter prefix matches.
type SubstitutionResult ¶ added in v0.9.0
type TemplatizeReport ¶ added in v0.9.0
type TemplatizeReport struct {
Results []SubstitutionResult
Skipped map[string]int
BinaryFiles []string
}
func Templatize ¶ added in v0.9.0
func Templatize(fsys fs.FS, outputDir string, subs []Substitution) (*TemplatizeReport, error)
Templatize copies fsys to outputDir, applying subs to every text file's path and content. Binary files (detected by null byte in first 512 bytes) are copied verbatim. The .git directory is always skipped. Returns a TemplatizeReport summarising all substitutions and protected strings.
type Variable ¶
type Variable struct {
Name string // PascalCase
Kind VariableKind
// Typed value: string, bool, []string, int, or []int — depends on Kind.
Value any
Required bool // KindInput and KindStringList: validation fails when user submits empty value
Description string // optional; shown as subtitle in the TUI
Min *int // KindInt only: inclusive lower bound (nil = no constraint)
Max *int // KindInt only: inclusive upper bound (nil = no constraint)
}
Variable describes a single template variable from goplt.toml.
type VariableKind ¶
type VariableKind string
VariableKind represents the type of a template variable.
const ( KindInput VariableKind = "input" // single-line text input; use Required = true for mandatory fields KindBool VariableKind = "bool" // yes/no confirm KindStringChoice VariableKind = "stringChoice" // select from list; first item is selected by default KindStringList VariableKind = "stringList" // comma-separated list of strings KindInt VariableKind = "int" // free integer input KindIntChoice VariableKind = "intChoice" // select from a list of integers; first item is selected by default // KindText is an alias for KindInput kept for backward compatibility with // library consumers that reference the old constant name. KindText = KindInput )
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
goplt
command
|
|
|
goplt/cmd
cmd/goplt/cmd/generate.go
|
cmd/goplt/cmd/generate.go |
|
goplt/inittempl
Package inittempl holds the embedded meta-templates used by goplt init.
|
Package inittempl holds the embedded meta-templates used by goplt init. |
|
Package tui provides an interactive TUI form for collecting goplt template variables.
|
Package tui provides an interactive TUI form for collecting goplt template variables. |