Documentation
¶
Overview ¶
Package cueutils provides helpers to work with Cue
Index ¶
- Variables
- func BuildOverlay(configs []CueConfigFile, overlayRootDir, virtualCueModuleName string) (map[string]load.Source, []string, error)
- func FillPaths(value *cue.Value, fillMap map[string]any) error
- func GetValue(configs []CueConfigFile, dir, packageName, virtualCueModuleName string, ...) error
- func NewValue() *cue.Value
- func Unmarshal(configs []CueConfigFile, dir, packageName, virtualCueModuleName string, ...) error
- func Validate(value *cue.Value) error
- type CueConfigFile
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func BuildOverlay ¶ added in v0.5.0
func BuildOverlay(configs []CueConfigFile, overlayRootDir, virtualCueModuleName string) (map[string]load.Source, []string, error)
BuildOverlay - Builds an overlay of cue configs files. If virtualCueModuleName is not empty, it will add a module overlay with the given name. Returns an overlay map and the package paths found. Initially the package paths are set to the current directory but hidden files will be added so that they can be read.
func FillPaths ¶ added in v0.5.0
Fill multiple paths in a cue.Value with the given data. The fillMap is a map of paths and data to fill.
func GetValue ¶ added in v0.5.0
func GetValue(configs []CueConfigFile, dir, packageName, virtualCueModuleName string, value *cue.Value) error
Given a set of cue files, it will aggregate them into a single cue config and update the given cue.Value. This allows for incomplete configuration that can be completed by the caller.
If dir == "" it will default to the current directory. packageName can be set to _ to load files without a package. virtualCueModuleName can be set to a module name to add a module overlay or blank if the dir has a module already. Because CUE doesn't support hidden files, hidden files need to be passed as configs so that they can be loaded as an overlay.
Completing the value can be done in a couple of ways:
Using a go struct:
p := &GoStruct{} c := cuecontext.New() targetCue := c.Encode(p) *value = (*value).Unify(targetCue)
Using value.Fillpath (or cueutils.FillPaths):
data := "some data" *value = value.FillPath(cue.ParsePath("path.in.cue"), data)
func Unmarshal ¶
func Unmarshal(configs []CueConfigFile, dir, packageName, virtualCueModuleName string, value *cue.Value, target any) error
Given a set of cue files, it will aggregate them into a single cue config and then Unmarshal it unto the given data structure. If dir == "" it will default to the current directory. packageName can be set to _ to load files without a package. virtualCueModuleName can be set to a module name to add a module overlay or blank if the dir has a module already. Because CUE doesn't support hidden files, hidden files need to be passed as configs. value is a pointer receiver to a cue.Value and can be used on the caller side to print the cue values. Initialize with cueutils.NewValue()