Documentation ¶
Overview ¶
Package model contains the structs for unmarshaled YAML files.
Index ¶
- func ErrWithPos(pos *ConfigPos, fmtStr string, args ...any) error
- type Bool
- type ConfigPos
- type GoTemplate
- type Include
- type Input
- type Int
- type Print
- type RegexNameLookup
- type RegexNameLookupEntry
- type RegexReplace
- type RegexReplaceEntry
- type Spec
- type Step
- type String
- type StringReplace
- type StringReplacement
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrWithPos ¶
ErrWithPos includes information about the given config line with a given error. One good way to use this is with %w, like:
ErrWithPos(pos, "Foo(): %w", err)
Calling this function with a zero or nil ConfigPos is valid. The resulting error will just omit information about config location.
Types ¶
type Bool ¶
type Bool = valWithPos[bool]
Bool represents a boolean field in a model, together with its location in the input file.
type ConfigPos ¶
ConfigPos stores the position of an config value so error messages post-validation can point to problems. The zero value means "position unknown or there is no position."
This is theoretically agnostic to input format; we could decide to support alternative serialization formats besides YAML in the future.
func (*ConfigPos) AnnotateErr ¶
AnnotateErr prepends the config file location of a parsed value to an error. If the input err is nil, then nil is returned.
type GoTemplate ¶
type GoTemplate struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` Paths []String `yaml:"paths"` }
GoTemplate is an action that executes one more files as a Go template, replacing each one with its template output.
func (*GoTemplate) UnmarshalYAML ¶
func (g *GoTemplate) UnmarshalYAML(n *yaml.Node) error
UnmarshalYAML implements yaml.Unmarshaler.
type Include ¶
type Include struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` Paths []String `yaml:"paths"` As []String `yaml:"as"` StripPrefix String `yaml:"strip_prefix"` AddPrefix String `yaml:"add_prefix"` Skip []String `yaml:"skip"` }
Include is an action that places files into the output directory.
func (*Include) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type Input ¶
type Input struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` Name String `yaml:"name"` Desc String `yaml:"desc"` Default *String `yaml:"default,omitempty"` }
Input represents one of the parsed "input" fields from the spec.yaml file.
func (*Input) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type Int ¶
type Int = valWithPos[int]
Int represents an integer field in a model, together with its location in the input file.
type Print ¶
type Print struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` Message String `yaml:"message"` }
Print is an action that prints a message to standard output.
func (*Print) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type RegexNameLookup ¶
type RegexNameLookup struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` Paths []String `yaml:"paths"` Replacements []*RegexNameLookupEntry `yaml:"replacements"` }
RegexNameLookup is an action that replaces named regex capturing groups with the template variable of the same name.
func (*RegexNameLookup) UnmarshalYAML ¶
func (r *RegexNameLookup) UnmarshalYAML(n *yaml.Node) error
UnmarshalYAML implements yaml.Unmarshaler.
func (*RegexNameLookup) Validate ¶
func (r *RegexNameLookup) Validate() error
Validate implements Validator.
type RegexNameLookupEntry ¶
RegexNameLookupEntry is one of potentially many regex replacements to be applied.
func (*RegexNameLookupEntry) UnmarshalYAML ¶
func (r *RegexNameLookupEntry) UnmarshalYAML(n *yaml.Node) error
func (*RegexNameLookupEntry) Validate ¶
func (r *RegexNameLookupEntry) Validate() error
Validate implements Validator.
type RegexReplace ¶
type RegexReplace struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` Paths []String `yaml:"paths"` Replacements []*RegexReplaceEntry `yaml:"replacements"` }
RegexReplace is an action that replaces a regex match (or a subgroup of it) with a template expression.
func (*RegexReplace) UnmarshalYAML ¶
func (r *RegexReplace) UnmarshalYAML(n *yaml.Node) error
UnmarshalYAML implements yaml.Unmarshaler.
func (*RegexReplace) Validate ¶
func (r *RegexReplace) Validate() error
Validate implements Validator.
type RegexReplaceEntry ¶
type RegexReplaceEntry struct { Pos *ConfigPos `yaml:"-"` Regex String `yaml:"regex"` SubgroupToReplace String `yaml:"subgroup_to_replace"` With String `yaml:"with"` }
RegexReplaceEntry is one of potentially many regex replacements to be applied.
func (*RegexReplaceEntry) UnmarshalYAML ¶
func (r *RegexReplaceEntry) UnmarshalYAML(n *yaml.Node) error
func (*RegexReplaceEntry) Validate ¶
func (r *RegexReplaceEntry) Validate() error
Validate implements Validator.
type Spec ¶
type Spec struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` APIVersion String `yaml:"apiVersion"` Kind String `yaml:"kind"` Desc String `yaml:"desc"` Inputs []*Input `yaml:"inputs"` Steps []*Step `yaml:"steps"` }
Spec represents a parsed spec.yaml file describing a template.
func DecodeSpec ¶
DecodeSpec unmarshals the YAML Spec from r. This function exists so we can validate the Spec model before providing it to the caller; we don't want the caller to forget, and thereby introduce bugs.
If the Spec parses successfully but then fails validation, the spec will be returned along with the validation error.
func (*Spec) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type Step ¶
type Step struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` Desc String `yaml:"desc"` Action String `yaml:"action"` // Each action type has a field below. Only one of these will be set. Print *Print `yaml:"-"` Include *Include `yaml:"-"` RegexReplace *RegexReplace `yaml:"-"` RegexNameLookup *RegexNameLookup `yaml:"-"` StringReplace *StringReplace `yaml:"-"` GoTemplate *GoTemplate `yaml:"-"` }
Step represents one of the work steps involved in rendering a template.
func (*Step) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type String ¶
type String = valWithPos[string]
String represents a string field in a model, together with its location in the input file.
type StringReplace ¶
type StringReplace struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` Paths []String `yaml:"paths"` Replacements []*StringReplacement `yaml:"replacements"` }
StringReplace is an action that replaces a string with a template expression.
func (*StringReplace) UnmarshalYAML ¶
func (s *StringReplace) UnmarshalYAML(n *yaml.Node) error
UnmarshalYAML implements yaml.Unmarshaler.
func (*StringReplace) Validate ¶
func (s *StringReplace) Validate() error
Validate implements Validator.
type StringReplacement ¶
type StringReplacement struct { Pos *ConfigPos `yaml:"-"` ToReplace String `yaml:"to_replace"` With String `yaml:"with"` }
func (*StringReplacement) UnmarshalYAML ¶
func (s *StringReplacement) UnmarshalYAML(n *yaml.Node) error
func (*StringReplacement) Validate ¶
func (s *StringReplacement) Validate() error