figtree

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

README

GoDoc Build

Figtree is a go library to recursively parse and merge yaml based config files.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultSource will be the value of the `Source` property
	// for Option[T] when they are constructed via `NewOption[T]`.
	DefaultSource = NewSource(defaultSource)

	// OverrideSource will be the value of the `Source` property
	// for Option[T] when they are populated via kingpin command
	// line option.
	OverrideSource = NewSource(overrideSource)
)

ideally these would be const if Go supported const structs?

View Source
var NewBoolOption = NewOption[bool]
View Source
var NewByteOption = NewOption[byte]
View Source
var NewComplex128Option = NewOption[complex128]
View Source
var NewComplex64Option = NewOption[complex64]
View Source
var NewErrorOption = NewOption[error]
View Source
var NewFloat32Option = NewOption[float32]
View Source
var NewFloat64Option = NewOption[float64]
View Source
var NewInt16Option = NewOption[int16]
View Source
var NewInt32Option = NewOption[int32]
View Source
var NewInt64Option = NewOption[int64]
View Source
var NewInt8Option = NewOption[int8]
View Source
var NewIntOption = NewOption[int]
View Source
var NewRawTypeOption = NewOption[any]
View Source
var NewRuneOption = NewOption[rune]
View Source
var NewStringOption = NewOption[string]
View Source
var NewUint16Option = NewOption[uint16]
View Source
var NewUint32Option = NewOption[uint32]
View Source
var NewUint64Option = NewOption[uint64]
View Source
var NewUint8Option = NewOption[uint8]
View Source
var NewUintOption = NewOption[uint]
View Source
var NewUintptrOption = NewOption[uintptr]
View Source
var StringifyValue = true

StringifyValue is global variable to indicate if the Option should be serialized as just the value (when value is true) or if the entire Option struct should be serialized. This is a hack, and not recommended for general usage, but can be useful for debugging.

Functions

func CanonicalFieldName

func CanonicalFieldName(sf reflect.StructField) string

CanonicalFieldName will return the the field name that will be used with merging maps and structs where the name casing/formatting may not be consistent. If the field uses tag `figtree:",name=MyName"` then that name will be used instead of the default contention.

func FindParentPaths

func FindParentPaths(homedir, cwd, fileName string) []string

func MakeMergeStruct

func MakeMergeStruct(structs ...interface{}) interface{}

MakeMergeStruct will take multiple structs and return a pointer to a zero value for the anonymous struct that has all the public fields from all the structs merged into one struct. If there are multiple structs with the same field names, the first appearance of that name will be used.

func Merge

func Merge(dst, src interface{}) error

Merge will attempt to merge the data from src into dst. src and dst may each be either a map or a struct. Structs do not need to have the same structure, but any field name that exists in both structs will must be the same type.

Types

type BoolOption

type BoolOption = Option[bool]

type ByteOption

type ByteOption = Option[byte]

type ChangeSetFunc

type ChangeSetFunc func(map[string]*string) error

type Complex128Option

type Complex128Option = Option[complex128]

type Complex64Option

type Complex64Option = Option[complex64]

type ConfigOptions

type ConfigOptions struct {
	Overwrite []string `json:"overwrite,omitempty" yaml:"overwrite,omitempty"`
}

type ConfigSource

type ConfigSource struct {
	Config   *yaml.Node
	Filename string
}

type CreateOption

type CreateOption func(*FigTree)

func WithApplyChangeSet

func WithApplyChangeSet(apply ChangeSetFunc) CreateOption

func WithConfigDir

func WithConfigDir(dir string) CreateOption

func WithCwd

func WithCwd(cwd string) CreateOption

func WithEnvPrefix

func WithEnvPrefix(env string) CreateOption

func WithFilterOut

func WithFilterOut(filt FilterOut) CreateOption

func WithHome

func WithHome(home string) CreateOption

func WithPreProcessor

func WithPreProcessor(pp PreProcessor) CreateOption

func WithoutExec

func WithoutExec() CreateOption

type ErrorOption

type ErrorOption = Option[error]

type FigTree

type FigTree struct {
	// contains filtered or unexported fields
}

func NewFigTree

func NewFigTree(opts ...CreateOption) *FigTree

func (*FigTree) Copy

func (f *FigTree) Copy() *FigTree

func (*FigTree) FindParentPaths

func (f *FigTree) FindParentPaths(fileName string) []string

func (*FigTree) LoadAllConfigSources

func (f *FigTree) LoadAllConfigSources(sources []ConfigSource, options interface{}) error

func (*FigTree) LoadAllConfigs

func (f *FigTree) LoadAllConfigs(configFile string, options interface{}) error

func (*FigTree) LoadConfig

func (f *FigTree) LoadConfig(file string, options interface{}) error

func (*FigTree) LoadConfigSource

func (f *FigTree) LoadConfigSource(config *yaml.Node, source string, options interface{}) error

func (*FigTree) PopulateEnv

func (f *FigTree) PopulateEnv(data interface{}) (changeSet map[string]*string)

func (*FigTree) ReadFile

func (f *FigTree) ReadFile(file string) (*ConfigSource, error)

ReadFile will return a ConfigSource for given file path. If the file is executable (and WithoutExec was not used), it will execute the file and return the stdout otherwise it will return the file contents directly.

func (*FigTree) WithApplyChangeSet

func (f *FigTree) WithApplyChangeSet(apply ChangeSetFunc)

func (*FigTree) WithConfigDir

func (f *FigTree) WithConfigDir(dir string)

func (*FigTree) WithCwd

func (f *FigTree) WithCwd(cwd string)

func (*FigTree) WithEnvPrefix

func (f *FigTree) WithEnvPrefix(env string)

func (*FigTree) WithFilterOut

func (f *FigTree) WithFilterOut(filt FilterOut)

func (*FigTree) WithHome

func (f *FigTree) WithHome(home string)

func (*FigTree) WithIgnoreChangeSet

func (f *FigTree) WithIgnoreChangeSet()

func (*FigTree) WithPreProcessor

func (f *FigTree) WithPreProcessor(pp PreProcessor)

func (*FigTree) WithoutExec

func (f *FigTree) WithoutExec()

type FileCoordinate

type FileCoordinate struct {
	Line   int
	Column int
}

FileCoordinate represents the line/column of an option

type FilterOut

type FilterOut func(*yaml.Node) bool

type Float32Option

type Float32Option = Option[float32]

type Float64Option

type Float64Option = Option[float64]

type Int16Option

type Int16Option = Option[int16]

type Int32Option

type Int32Option = Option[int32]

type Int64Option

type Int64Option = Option[int64]

type Int8Option

type Int8Option = Option[int8]

type IntOption

type IntOption = Option[int]

type ListBoolOption

type ListBoolOption = ListOption[bool]

type ListByteOption

type ListByteOption = ListOption[byte]

type ListComplex128Option

type ListComplex128Option = ListOption[complex128]

type ListComplex64Option

type ListComplex64Option = ListOption[complex64]

type ListErrorOption

type ListErrorOption = ListOption[error]

type ListFloat32Option

type ListFloat32Option = ListOption[float32]

type ListFloat64Option

type ListFloat64Option = ListOption[float64]

type ListInt16Option

type ListInt16Option = ListOption[int16]

type ListInt32Option

type ListInt32Option = ListOption[int32]

type ListInt64Option

type ListInt64Option = ListOption[int64]

type ListInt8Option

type ListInt8Option = ListOption[int8]

type ListIntOption

type ListIntOption = ListOption[int]

type ListOption

type ListOption[T any] []Option[T]

func (ListOption[T]) Append

func (o ListOption[T]) Append(values ...T) ListOption[T]

func (ListOption[T]) IsCumulative

func (o ListOption[T]) IsCumulative() bool

IsCumulative implements part of the remainderArg interface as defined by the kingpin command line option library: https://github.com/alecthomas/kingpin/blob/v1.3.4/values.go#L49-L52

func (ListOption[T]) IsDefined

func (o ListOption[T]) IsDefined() bool

func (*ListOption[T]) Set

func (o *ListOption[T]) Set(value string) error

Set implements part of the Value interface as defined by the kingpin command line option library: https://github.com/alecthomas/kingpin/blob/v1.3.4/values.go#L26-L29

func (ListOption[T]) Slice

func (o ListOption[T]) Slice() []T

func (ListOption[T]) String

func (o ListOption[T]) String() string

String implements part of the Value interface as defined by the kingpin command line option library: https://github.com/alecthomas/kingpin/blob/v1.3.4/values.go#L26-L29

func (*ListOption[T]) WriteAnswer

func (o *ListOption[T]) WriteAnswer(name string, value any) error

WriteAnswer implements the Settable interface as defined by the survey prompting library: https://github.com/AlecAivazis/survey/blob/v2.3.5/core/write.go#L15-L18

type ListRawTypeOption

type ListRawTypeOption = ListOption[any]

type ListRuneOption

type ListRuneOption = ListOption[rune]

type ListStringOption

type ListStringOption = ListOption[string]

type ListUint16Option

type ListUint16Option = ListOption[uint16]

type ListUint32Option

type ListUint32Option = ListOption[uint32]

type ListUint64Option

type ListUint64Option = ListOption[uint64]

type ListUint8Option

type ListUint8Option = ListOption[uint8]

type ListUintOption

type ListUintOption = ListOption[uint]

type ListUintptrOption

type ListUintptrOption = ListOption[uintptr]

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
}
var Log Logger = &nullLogger{}

type MapBoolOption

type MapBoolOption = MapOption[bool]

type MapByteOption

type MapByteOption = MapOption[byte]

type MapComplex128Option

type MapComplex128Option = MapOption[complex128]

type MapComplex64Option

type MapComplex64Option = MapOption[complex64]

type MapErrorOption

type MapErrorOption = MapOption[error]

type MapFloat32Option

type MapFloat32Option = MapOption[float32]

type MapFloat64Option

type MapFloat64Option = MapOption[float64]

type MapInt16Option

type MapInt16Option = MapOption[int16]

type MapInt32Option

type MapInt32Option = MapOption[int32]

type MapInt64Option

type MapInt64Option = MapOption[int64]

type MapInt8Option

type MapInt8Option = MapOption[int8]

type MapIntOption

type MapIntOption = MapOption[int]

type MapOption

type MapOption[T any] map[string]Option[T]

func (MapOption[T]) IsCumulative

func (o MapOption[T]) IsCumulative() bool

IsCumulative implements part of the remainderArg interface as defined by the kingpin command line option library: https://github.com/alecthomas/kingpin/blob/v1.3.4/values.go#L49-L52

func (MapOption[T]) IsDefined

func (o MapOption[T]) IsDefined() bool

func (MapOption[T]) Map

func (o MapOption[T]) Map() map[string]T

func (*MapOption[T]) Set

func (o *MapOption[T]) Set(value string) error

Set implements part of the Value interface as defined by the kingpin command line option library: https://github.com/alecthomas/kingpin/blob/v1.3.4/values.go#L26-L29

func (MapOption[T]) String

func (o MapOption[T]) String() string

String implements part of the Value interface as defined by the kingpin command line option library: https://github.com/alecthomas/kingpin/blob/v1.3.4/values.go#L26-L29

func (*MapOption[T]) WriteAnswer

func (o *MapOption[T]) WriteAnswer(name string, value any) error

WriteAnswer implements the Settable interface as defined by the survey prompting library: https://github.com/AlecAivazis/survey/blob/v2.3.5/core/write.go#L15-L18

type MapRawTypeOption

type MapRawTypeOption = MapOption[any]

type MapRuneOption

type MapRuneOption = MapOption[rune]

type MapStringOption

type MapStringOption = MapOption[string]

type MapUint16Option

type MapUint16Option = MapOption[uint16]

type MapUint32Option

type MapUint32Option = MapOption[uint32]

type MapUint64Option

type MapUint64Option = MapOption[uint64]

type MapUint8Option

type MapUint8Option = MapOption[uint8]

type MapUintOption

type MapUintOption = MapOption[uint]

type MapUintptrOption

type MapUintptrOption = MapOption[uintptr]

type MergeOption

type MergeOption func(*Merger)

func PreserveMap

func PreserveMap(keys ...string) MergeOption

func WithSourceFile

func WithSourceFile(source string) MergeOption

type Merger

type Merger struct {
	Config ConfigOptions `json:"config,omitempty" yaml:"config,omitempty"`
	// contains filtered or unexported fields
}

func NewMerger

func NewMerger(options ...MergeOption) *Merger

func (*Merger) MakeMergeStruct

func (m *Merger) MakeMergeStruct(structs ...interface{}) interface{}

type Option

type Option[T any] struct {
	Source  SourceLocation
	Defined bool
	Value   T
}

func NewOption

func NewOption[T any](dflt T) Option[T]

func (*Option[T]) GetSource

func (o *Option[T]) GetSource() SourceLocation

func (Option[T]) GetValue

func (o Option[T]) GetValue() any

func (Option[T]) IsBoolFlag

func (o Option[T]) IsBoolFlag() bool

IsBoolFlag implements part of the boolFlag interface as defined by the kingpin command line option library: https://github.com/alecthomas/kingpin/blob/v1.3.4/values.go#L42-L45

func (*Option[T]) IsDefault

func (o *Option[T]) IsDefault() bool

func (Option[T]) IsDefined

func (o Option[T]) IsDefined() bool

func (*Option[T]) IsOverride

func (o *Option[T]) IsOverride() bool

func (Option[T]) MarshalJSON

func (o Option[T]) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshaler interface as defined by json: https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/encoding/json/encode.go;l=225-227

func (Option[T]) MarshalYAML

func (o Option[T]) MarshalYAML() (any, error)

MarshalYAML implements the Marshaler interface used by the yaml library: https://github.com/go-yaml/yaml/blob/v3.0.1/yaml.go#L50-L52

func (*Option[T]) Set

func (o *Option[T]) Set(s string) error

Set implements part of the Value interface as defined by the kingpin command line option library: https://github.com/alecthomas/kingpin/blob/v1.3.4/values.go#L26-L29

func (*Option[T]) SetSource

func (o *Option[T]) SetSource(source SourceLocation)

func (*Option[T]) SetValue

func (o *Option[T]) SetValue(v any) error

SetValue implements the Settings interface as defined by the kingpin command line option library: https://github.com/alecthomas/kingpin/blob/v1.3.4/parsers.go#L13-L15

func (Option[T]) String

func (o Option[T]) String() string

String implements part of the Value interface as defined by the kingpin command line option library: https://github.com/alecthomas/kingpin/blob/v1.3.4/values.go#L26-L29

func (*Option[T]) UnmarshalJSON

func (o *Option[T]) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the Unmarshaler interface as defined by json: https://cs.opensource.google/go/go/+/refs/tags/go1.18.3:src/encoding/json/decode.go;l=118-120

func (*Option[T]) UnmarshalYAML

func (o *Option[T]) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implement the Unmarshaler interface used by the yaml library: https://github.com/go-yaml/yaml/blob/v3.0.1/yaml.go#L36-L38

func (*Option[T]) WriteAnswer

func (o *Option[T]) WriteAnswer(name string, value any) error

WriteAnswer implements the Settable interface as defined by the survey prompting library: https://github.com/AlecAivazis/survey/blob/v2.3.5/core/write.go#L15-L18

type PreProcessor

type PreProcessor func(*yaml.Node) error

type RawTypeOption

type RawTypeOption = Option[any]

type RuneOption

type RuneOption = Option[rune]

type SourceLocation

type SourceLocation struct {
	Name     string
	Location *FileCoordinate
}

func NewSource

func NewSource(name string, opts ...SourceOption) SourceLocation

func (SourceLocation) String

func (s SourceLocation) String() string

type SourceOption

type SourceOption func(*SourceLocation) *SourceLocation

func WithLocation

func WithLocation(location *FileCoordinate) SourceOption

type StringOption

type StringOption = Option[string]

type Uint16Option

type Uint16Option = Option[uint16]

type Uint32Option

type Uint32Option = Option[uint32]

type Uint64Option

type Uint64Option = Option[uint64]

type Uint8Option

type Uint8Option = Option[uint8]

type UintOption

type UintOption = Option[uint]

type UintptrOption

type UintptrOption = Option[uintptr]

Jump to

Keyboard shortcuts

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