values

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSlug = "default"

DefaultSlug mirrors schema.DefaultSlug to avoid a dependency cycle.

Variables

This section is empty.

Functions

This section is empty.

Types

type Section added in v1.0.0

type Section interface {
	GetDefinitions() *fields.Definitions
	GetName() string
	GetDescription() string
	GetPrefix() string
	GetSlug() string
}

Section defines the minimal interface needed by values. It intentionally avoids schema.Section to prevent import cycles.

type SectionValues

type SectionValues struct {
	Section Section
	Fields  *fields.FieldValues
}

SectionValues is the result of "parsing" input data using a schema.Section specification. For example, it could be the result of parsing cobra command flags, or a JSON body, or HTTP query fields.

func NewSectionValues added in v1.0.0

func NewSectionValues(section Section, options ...SectionValuesOption) (*SectionValues, error)

func (*SectionValues) Clone added in v1.0.0

func (ppl *SectionValues) Clone() *SectionValues

Clone returns a copy of the SectionValues with a fresh Fields map. However, neither the Section nor the Fields are deep copied.

func (*SectionValues) DecodeInto added in v1.0.0

func (ppl *SectionValues) DecodeInto(s interface{}) error

func (*SectionValues) GetField added in v1.0.0

func (ppl *SectionValues) GetField(k string) (interface{}, bool)

func (*SectionValues) MarshalJSON added in v1.0.0

func (pl *SectionValues) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for SectionValues

func (*SectionValues) MarshalYAML added in v1.0.0

func (pl *SectionValues) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler for SectionValues

func (*SectionValues) MergeFields added in v1.0.0

func (ppl *SectionValues) MergeFields(other *SectionValues) error

MergeFields merges the other SectionValues into this one, overwriting any existing values. This doesn't replace the actual Section pointer.

type SectionValuesOption added in v1.0.0

type SectionValuesOption func(*SectionValues) error

func WithFieldValue added in v1.0.0

func WithFieldValue(
	key string, value interface{},
	options ...fields.ParseOption,
) SectionValuesOption

func WithFields added in v1.0.0

func WithFields(pds *fields.FieldValues) SectionValuesOption

type SerializableSection added in v1.0.0

type SerializableSection struct {
	Name        string              `yaml:"name" json:"name"`
	Slug        string              `yaml:"slug" json:"slug"`
	Description string              `yaml:"description,omitempty" json:"description,omitempty"`
	Prefix      string              `yaml:"prefix,omitempty" json:"prefix,omitempty"`
	Fields      *fields.Definitions `yaml:"fields" json:"fields"`
}

SerializableSection represents a schema section in a format suitable for YAML/JSON serialization.

type SerializableSectionValues added in v1.0.0

type SerializableSectionValues struct {
	Section *SerializableSection            `yaml:"section,omitempty" json:"section,omitempty"`
	Fields  *fields.SerializableFieldValues `yaml:"fields" json:"fields"`
}

SerializableSectionValues represents a parsed section in a format suitable for YAML/JSON serialization.

func ToSerializableSectionValues added in v1.0.0

func ToSerializableSectionValues(pl *SectionValues) *SerializableSectionValues

ToSerializableSectionValues converts a SectionValues to its serializable representation.

type SerializableValues added in v1.0.0

type SerializableValues struct {
	// Using orderedmap to maintain section order while having slug-based access.
	Sections *orderedmap.OrderedMap[string, *SerializableSectionValues] `yaml:"sections" json:"sections"`
}

SerializableValues represents a collection of parsed sections in a format suitable for YAML/JSON serialization, maintaining the order of sections.

func ToSerializableValues added in v1.0.0

func ToSerializableValues(pl *Values) *SerializableValues

ToSerializableValues converts a Values collection to its serializable representation.

func (*SerializableValues) MarshalJSON added in v1.0.0

func (spl *SerializableValues) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for SerializableValues

func (*SerializableValues) MarshalYAML added in v1.0.0

func (spl *SerializableValues) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler for SerializableValues

type Values

type Values struct {
	*orderedmap.OrderedMap[string, *SectionValues]
}

func New

func New(options ...ValuesOption) *Values

func (*Values) AllFieldValues added in v1.0.0

func (p *Values) AllFieldValues() *fields.FieldValues

AllFieldValues returns a new instance of fields.FieldValues that merges the fields from all Values. The returned fields are a deep clone of the values.

func (*Values) Clone added in v1.0.0

func (p *Values) Clone() *Values

func (*Values) DecodeSectionInto added in v1.0.0

func (p *Values) DecodeSectionInto(sectionKey string, dst interface{}) error

DecodeSectionInto decodes a struct with values from a SectionValues specified by the key. If the key is "default", it creates a fresh empty default section for defaults and decodes into the struct with it. If the section specified by the key is not found, it returns an error. The struct must be passed by reference as the s argument.

func (*Values) DefaultSectionValues added in v1.0.0

func (p *Values) DefaultSectionValues() *SectionValues

func (*Values) ForEach added in v1.0.0

func (p *Values) ForEach(fn func(k string, v *SectionValues))

func (*Values) ForEachE added in v1.0.0

func (p *Values) ForEachE(fn func(k string, v *SectionValues) error) error

func (*Values) GetDataMap added in v1.0.0

func (p *Values) GetDataMap() map[string]interface{}

GetDataMap is useful when rendering out templates using all passed in sections.

func (*Values) GetField added in v1.0.0

func (p *Values) GetField(slug string, key string) (*fields.FieldValue, bool)

func (*Values) GetOrCreate added in v1.0.0

func (p *Values) GetOrCreate(section Section) *SectionValues

func (*Values) MarshalJSON added in v1.0.0

func (pl *Values) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler for Values

func (*Values) MarshalYAML added in v1.0.0

func (pl *Values) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler for Values

func (*Values) Merge added in v1.0.0

func (p *Values) Merge(other *Values) error

type ValuesOption

type ValuesOption func(*Values)

func WithSectionValues

func WithSectionValues(slug string, v *SectionValues) ValuesOption

Jump to

Keyboard shortcuts

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