Documentation ¶
Overview ¶
Package model contains the structs for unmarshaled YAML files.
Index ¶
- func ErrWithPos(pos *ConfigPos, fmtStr string, args ...any) error
- type Append
- type Bool
- type ConfigPos
- type ForEach
- type ForEachIterator
- 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 Append ¶
type Append struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` Paths []String `yaml:"paths"` With String `yaml:"with"` SkipEnsureNewline Bool `yaml:"skip_ensure_newline"` }
Append is an action that appends some output to the end of the file.
func (*Append) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
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 ForEach ¶
type ForEach struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` Iterator *ForEachIterator `yaml:"iterator"` Steps []*Step `yaml:"steps"` }
func (*ForEach) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type ForEachIterator ¶
type ForEachIterator struct { // Pos is the YAML file location where this object started. Pos *ConfigPos `yaml:"-"` // The name by which the range value is accessed. Key String `yaml:"key"` // Values is a list to range over, e.g. ["dev", "prod"] Values []String `yaml:"values"` // ValuesFrom is a CEL expression returning a list of strings to range over. ValuesFrom *String `yaml:"values_from"` }
func (*ForEachIterator) UnmarshalYAML ¶
func (f *ForEachIterator) UnmarshalYAML(n *yaml.Node) error
UnmarshalYAML implements yaml.Unmarshaler.
func (*ForEachIterator) Validate ¶
func (f *ForEachIterator) Validate() error
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"` From String `yaml:"from"` 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. Append *Append `yaml:"-"` ForEach *ForEach `yaml:"-"` GoTemplate *GoTemplate `yaml:"-"` Include *Include `yaml:"-"` Print *Print `yaml:"-"` RegexNameLookup *RegexNameLookup `yaml:"-"` RegexReplace *RegexReplace `yaml:"-"` StringReplace *StringReplace `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