Documentation ¶
Index ¶
- Variables
- type Configuration
- type Entry
- type EntryUpdater
- type Index
- type SectionUpdater
- type Selection
- func (s Selection[T]) Configurations() []T
- func (s Selection[T]) Each(iterator func(Entry[T]))
- func (s Selection[T]) Entries() []Entry[T]
- func (s Selection[T]) First() (Entry[T], error)
- func (s Selection[T]) Len() int
- func (s Selection[T]) Update(entryUpdater EntryUpdater[T]) error
- func (s Selection[T]) Where(condition func(Entry[T]) bool) Selection[T]
- func (s Selection[T]) WhereFilePath(p string) Selection[T]
- func (s Selection[T]) WhereName(name string) Selection[T]
- type YAMLASTMutater
Constants ¶
This section is empty.
Variables ¶
var ErrNoEntries = errors.New("no entries in selection")
ErrNoEntries is returned when a Selection has no entries.
var ErrSkip = errors.New("skipping operation for this entry")
ErrSkip is a special sentinel error that signals that the given entry should be skipped during batch processing. When a caller's function returns ErrSkip, the error is not returned back to the caller.
Functions ¶
This section is empty.
Types ¶
type Configuration ¶
type Configuration interface {
Name() string
}
Configuration describes any type that can be named (such as a package configuration struct, where the package has name (e.g. "busybox") that's a meaningful key for indexing the configuration itself.)
type Entry ¶
type Entry[T Configuration] interface { // Update applies the given entryUpdater to the entry. Update(updater EntryUpdater[T]) error // Configuration returns the entry as a decoded configuration. Configuration() *T // contains filtered or unexported methods }
Entry represents an individual item in the Index.
type EntryUpdater ¶
type EntryUpdater[T Configuration] func(*Index[T], Entry[T]) error
An EntryUpdater is a function that takes a configuration Entry and modifies a specific section of the configuration (type T) data. It's meant to be passed into NewTargetedYAMLASTMutater as an argument to update the YAML data that underlies the configuration data.
The EntryUpdater ultimately needs to be passed to an Index to do the actual update operation.
func NewYAMLUpdateFunc ¶
func NewYAMLUpdateFunc[T Configuration](yamlASTMutater YAMLASTMutater[T]) EntryUpdater[T]
NewYAMLUpdateFunc returns a EntryUpdater function that will use the YAMLASTMutater provided to operate on a given Entry.
type Index ¶
type Index[T Configuration] struct { // contains filtered or unexported fields }
An Index is a queryable store of configurations, where each configuration has already been decoded both into the configuration Go type (T) and into a YAML AST.
func NewIndex ¶
func NewIndex[T Configuration](fsys rwfs.FS, cfgDecodeFunc func(string) (*T, error)) (*Index[T], error)
NewIndex returns a new Index of all configurations found within the given filesystem. The provided cfgDecodeFunc should take a path to a YAML file in a fs.FS, decode the file to type T, and return a reference the "type T" data, or an error if there was a problem.
func NewIndexFromPaths ¶
func NewIndexFromPaths[T Configuration](fsys rwfs.FS, cfgDecodeFunc func(string) (*T, error), paths ...string) (*Index[T], error)
NewIndexFromPaths returns a new Index of configurations for each of the given paths. The provided cfgDecodeFunc should take a path to a YAML file in a fs.FS, decode the file to type T, and return a reference the "type T" data, or an error if there was a problem.
func (*Index[T]) Create ¶
Create creates a new configuration file at the given path, with the given cfg. The new configuration is automatically added to the Index.
type SectionUpdater ¶
type SectionUpdater[K any, T Configuration] func(configuration T) (K, error)
A SectionUpdater is a function that takes a Configuration (type T) and returns an updated version of a section (type K) of that Configuration.
type Selection ¶
type Selection[T Configuration] struct { // contains filtered or unexported fields }
A Selection is a view into an Index's configuration (type T) entries. The selection can expose anywhere from zero entries up to all the index's entries. A selection allows the caller to chain methods to further constrain the selection and to perform operations on each item in the selection.
func (Selection[T]) Configurations ¶
func (s Selection[T]) Configurations() []T
Configurations returns the Configuration items included in the current Selection.
func (Selection[T]) Update ¶
func (s Selection[T]) Update(entryUpdater EntryUpdater[T]) error
Update applies the given entryUpdater to all entries currently in the Selection.
func (Selection[T]) Where ¶ added in v0.5.0
Where filters the selection down to entries for which the given condition is true.
func (Selection[T]) WhereFilePath ¶
WhereFilePath filters the selection down to entries whose configuration file path match the given parameter.
type YAMLASTMutater ¶
A YAMLASTMutater is a function that mutates a YAML AST. The function is also given a configuration struct (type T) in case implementations require it for context.
func NewTargetedYAMLASTMutater ¶
func NewTargetedYAMLASTMutater[K any, T Configuration]( sectionName string, updater SectionUpdater[K, T], cfgSectionDataAssigner func(configuration T, sectionData K) T, ) YAMLASTMutater[T]
NewTargetedYAMLASTMutater returns a YAMLASTMutater designed to update a single "section" of the YAML AST. The section is root-level mapping key, the data of which is described by type K.