load

package
v0.0.0-...-2016107 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: Apache-2.0 Imports: 13 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsModFS

func AsModFS(in fs.FS, modname string) fs.FS

AsModFS injects a cue.mod/module.cue file into the provided in fs.FS at its root, preparing it for use by

If a cue.mod already exists in the provided fs.FS, this func is a no-op.

func InstanceWithThema

func InstanceWithThema(modFS fs.FS, dir string, opts ...Option) (*build.Instance, error)

InstanceWithThema wraps CUE's load.Instance in order to allow loading .cue files that directly `import "github.com/grafana/thema"`, as lineages are expected to. This is accomplished by constructing a load.Config.Overlay with the Thema CUE files dynamically injected under cue.mod/pkg/, where CUE searches for mod-external imports.

This loader is opinionated, preferring simple ease-of-use and fewer degrees of freedom to the completeness of load.Instances. Some reasonable use cases may not be achievable. Make your own as needed - all key component parts are exported from elsewhere in the Thema Go module.

The modFS is expected to be an fs.FS containing the cue.mod module metadata, and any lineage(s) to be loaded.

The root of the FS must be an importable CUE module with a path. That is, there must exist cue.mod/module.cue, which must contain a top-level field declaring the module name (aka import prefix/module path), e.g.:

module: "github.com/grafana/thema"

The dir parameter must specify a directory containing .cue files with lineages to be loaded, relative to the module root directory. This is similar to load.Config.Dir, except:

  • The package name of the root dir is the final element of the module name, unless overridden with a Package option.
  • "." and the empty string are a special value that will load the root directory of the modFS.

NOTE - this function is likely to be deprecated and removed in favor of a more generic dependency overlay loader.

func InstancesWithThema

func InstancesWithThema(modFS fs.FS, dir string, opts ...Option) (*build.Instance, error)

InstancesWithThema passes through to InstanceWithThema. DEPRECATED: use InstanceWithThema.

func ToOverlay

func ToOverlay(prefix string, vfs fs.FS, overlay map[string]load.Source) error

ToOverlay maps the provided fs.FS into an Overlay for use in load.Config.

An absolute path prefix must be provided.

Types

type ErrFSNotACueModule

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

ErrFSNotACueModule is a general error that wraps a particular error that explains why a particular fs.FS cannot be used as a CUE module FS as needed by InstancesWithThema.

func (*ErrFSNotACueModule) Error

func (e *ErrFSNotACueModule) Error() string

func (*ErrFSNotACueModule) Unwrap

func (e *ErrFSNotACueModule) Unwrap() error

type Option

type Option loadOption

Option defines optional parameters that may be passed to the loader.

func Package

func Package(name string) Option

Package specifies a custom CUE package name use when loading CUE files. See ["cuelang.org/go/cue/load".Config.Package].

Jump to

Keyboard shortcuts

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