model

package
v0.0.1-alpha2 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package model contains the structs for unmarshaled YAML files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrWithPos

func ErrWithPos(pos *ConfigPos, fmtStr string, args ...any) error

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

type ConfigPos struct {
	Line   int
	Column int
}

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

func (c *ConfigPos) AnnotateErr(err error) error

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.

func (*GoTemplate) Validate

func (g *GoTemplate) Validate() error

Validate implements Validator.

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

func (i *Include) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler.

func (*Include) Validate

func (i *Include) Validate() error

Validate implements Validator.

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

func (i *Input) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler.

func (*Input) Validate

func (i *Input) Validate() error

Validate implements Validator.

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

func (p *Print) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler.

func (*Print) Validate

func (p *Print) Validate() error

Validate implements Validator.

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

type RegexNameLookupEntry struct {
	Pos   *ConfigPos `yaml:"-"`
	Regex String     `yaml:"regex"`
}

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

func DecodeSpec(r io.Reader) (*Spec, error)

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

func (s *Spec) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler.

func (*Spec) Validate

func (s *Spec) Validate() error

Validate implements Validator.

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

func (s *Step) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler.

func (*Step) Validate

func (s *Step) Validate() error

Validate implements Validator.

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

Jump to

Keyboard shortcuts

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