bass

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: MIT Imports: 54 Imported by: 6

Documentation

Index

Constants

View Source
const (
	ConcurrencyModeShared = iota
	ConcurrencyModePrivate
	ConcurrencyModeLocked
)
View Source
const AtomicSuffix = ".new"

AtomicSuffix is appended to the Write destination to form a path used for atomic writes.

View Source
const Ext = ".bass"

Ext is the canonical file extension for Bass source code.

View Source
const TraceSize = 1000

Variables

View Source
var Bass = NewBass()

Bass is the canonical global session for running Bass scripts.

View Source
var CacheHome string

CacheHome is the directory where Bass stores caches.

Clock is used to determine the current time.

View Source
var ErrBadSyntax = errors.New("bad syntax")
View Source
var ErrEndOfSource = errors.New("end of source")
View Source
var ErrInterrupted = errors.New("interrupted")
View Source
var ErrNoRuntimePool = errors.New("runtime not initialized")

ErrNoRuntimePool is returned when the context.Context does not have a runtime pool set.

View Source
var Ground = NewEmptyScope()

Ground is the scope providing the standard library.

View Source
var Identity = Continue(func(v Value) Value {
	return v
})
View Source
var LinuxPlatform = Platform{
	OS:           "linux",
	Architecture: runtime.GOARCH,
}

LinuxPlatform is the minimum configuration to select a Linux runtime.

View Source
var Protocols = map[Symbol]Protocol{
	"raw":        RawProtocol{},
	"json":       JSONProtocol{},
	"lines":      LineProtocol{},
	"unix-table": UnixTableProtocol{},
	"tar":        TarProtocol{},
}

Protocols defines the set of supported protocols for reading responses.

View Source
var Stdin = &Source{
	NewJSONSource("stdin", os.Stdin),
}
View Source
var Stdout = &Sink{
	NewJSONSink("stdout", os.Stdout),
}

Functions

func BindConst

func BindConst(a, b Value) error

func Cache added in v0.6.0

func Cache(ctx context.Context, cachePath string, rd Readable) (string, error)

Cache exports a readable file path to a local path if it does not already exist.

Does not preserve file permissions and timestamps. Only use for accessing the content of a Readable.

func Details

func Details(val Value) string

func Dump

func Dump(dst io.Writer, val any)

func Each

func Each(list List, cb func(Value) error) error

func EachBindingList

func EachBindingList(binding List, cb func(Symbol, Range) error) error

func EncodeList added in v0.5.0

func EncodeList(list List, enc zapcore.ArrayEncoder) error

func ForkCustodian added in v0.11.0

func ForkCustodian(ctx context.Context) context.Context

func ForkTrace added in v0.5.0

func ForkTrace(ctx context.Context) context.Context

func IsApplicative

func IsApplicative(val Value) bool

IsApplicative returns true iff the value is an Applicative.

func IsList

func IsList(val Value) bool

func IsOperative

func IsOperative(val Value) bool

IsOperative returns true iff the value is an Operative or a Builtin operative.

func IsPathLike added in v0.5.0

func IsPathLike(arg string) bool

func LoggerTo

func LoggerTo(w io.Writer, level zapcore.LevelEnabler) *zap.Logger

func MarshalJSON

func MarshalJSON(val any) ([]byte, error)

func MarshalProto added in v0.6.0

func MarshalProto(val Value) (*proto.Value, error)

func NewEncoder

func NewEncoder(w io.Writer) *json.Encoder

func NewError added in v0.5.0

func NewError(msg string, kv ...Value) error

func NewRawDecoder added in v0.5.0

func NewRawDecoder(r io.Reader) *json.Decoder

func PrintBindingDocs

func PrintBindingDocs(ctx context.Context, scope *Scope, form, val Value)

func RunMain

func RunMain(ctx context.Context, scope *Scope, args ...Value) error

func StdLogger added in v0.8.0

func StdLogger(level zapcore.LevelEnabler) *zap.Logger

func UnmarshalJSON

func UnmarshalJSON(payload []byte, dest any) error

func WithCustodian added in v0.11.0

func WithCustodian(ctx context.Context, custodian *Custodian) context.Context

func WithRuntimePool

func WithRuntimePool(ctx context.Context, pool RuntimePool) context.Context

func WithTrace

func WithTrace(ctx context.Context, trace *Trace) context.Context

Types

type Annotate

type Annotate struct {
	// Value the inner form whose value will be annotated.
	Value

	// Range is the source code location of the inner form.
	Range Range

	// Comment is a literal comment ahead of or following the inner form.
	Comment string

	// Meta is an optional binding form that will be evaluated to attach metadata
	// to the inner form's value.
	Meta *Bind
}

func Caller

func Caller(ctx context.Context, offset int) Annotate

func (Annotate) Decode

func (value Annotate) Decode(dest any) error

func (Annotate) Eval

func (value Annotate) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

func (Annotate) MarshalJSON

func (value Annotate) MarshalJSON() ([]byte, error)

func (Annotate) MetaBind

func (value Annotate) MetaBind() Bind

func (Annotate) String

func (value Annotate) String() string

type AnnotateBinding

type AnnotateBinding struct {
	Bindable
	Range    Range
	MetaBind Bind
}

func (AnnotateBinding) Bind

func (binding AnnotateBinding) Bind(ctx context.Context, scope *Scope, cont Cont, val Value, doc ...Annotated) ReadyCont

func (AnnotateBinding) Decode

func (value AnnotateBinding) Decode(dest any) error

func (AnnotateBinding) EachBinding

func (binding AnnotateBinding) EachBinding(cb func(Symbol, Range) error) error

type Annotated

type Annotated struct {
	// Value is the inner value.
	Value

	// Meta contains metadata about the inner value.
	Meta *Scope
}

func (Annotated) Decode

func (value Annotated) Decode(dest any) error

func (Annotated) MarshalJSON

func (value Annotated) MarshalJSON() ([]byte, error)

func (Annotated) MarshalProto added in v0.7.0

func (value Annotated) MarshalProto() (proto.Message, error)

MarshalProto passes through to its inner value. This is necessary for annotated values like *dir* (a Bass-provided value with docs meta) to be passed in to a Thunk.

type Applicative

type Applicative interface {
	Combiner

	Unwrap() Combiner
}

func Func

func Func(name, formals string, f any) Applicative

func Wrap

func Wrap(comb Combiner) Applicative

type ArityError

type ArityError struct {
	Name     string
	Need     int
	Variadic bool
	Have     int
}

func (ArityError) Error

func (err ArityError) Error() string

type Bind

type Bind []Value

func (Bind) Bind added in v0.5.0

func (bind Bind) Bind(ctx context.Context, bindScope *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (Bind) Decode

func (value Bind) Decode(dest any) error

func (Bind) EachBinding added in v0.5.0

func (bind Bind) EachBinding(cb func(Symbol, Range) error) error

func (Bind) Equal

func (value Bind) Equal(ovalue Value) bool

func (Bind) Eval

func (value Bind) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

func (Bind) MarshalJSON

func (value Bind) MarshalJSON() ([]byte, error)

func (Bind) String

func (value Bind) String() string

type BindMismatchError

type BindMismatchError struct {
	Need Value
	Have Value
}

func (BindMismatchError) Error

func (err BindMismatchError) Error() string

type Bindable

type Bindable interface {
	Value

	// Bind assigns values to symbols in the given scope.
	Bind(context.Context, *Scope, Cont, Value, ...Annotated) ReadyCont

	// EachBinding calls the fn for each symbol that will be bound.
	EachBinding(func(Symbol, Range) error) error
}

Bindable is any value which may be used to destructure a value into bindings in a scope.

type Bindings

type Bindings map[Symbol]Value

Bindings maps Symbols to Values in a scope.

func (Bindings) Scope

func (bindings Bindings) Scope(parents ...*Scope) *Scope

NewScope constructs a new *Scope with initial bindings.

type Bool

type Bool bool

func (Bool) Bind

func (binding Bool) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (Bool) Decode

func (value Bool) Decode(dest any) error

func (Bool) EachBinding

func (Bool) EachBinding(func(Symbol, Range) error) error

func (Bool) Equal

func (value Bool) Equal(other Value) bool

func (Bool) Eval

func (value Bool) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Bool) MarshalProto added in v0.6.0

func (value Bool) MarshalProto() (proto.Message, error)

func (Bool) String

func (value Bool) String() string

type Builtin

type Builtin struct {
	Name      string
	Formals   Value
	Func      reflect.Value
	Operative bool
}

func Op

func Op(name, signature string, f any) *Builtin

func (Builtin) Call

func (builtin Builtin) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (*Builtin) Decode

func (value *Builtin) Decode(dest any) error

func (*Builtin) Equal

func (value *Builtin) Equal(other Value) bool

func (*Builtin) Eval

func (value *Builtin) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*Builtin) MarshalJSON

func (value *Builtin) MarshalJSON() ([]byte, error)

func (*Builtin) String

func (value *Builtin) String() string

type CachePath added in v0.7.0

type CachePath struct {
	ID              string
	ConcurrencyMode ConcurrencyMode
	Path            FileOrDirPath
}

CachePath is a Path within an ephemeral directory managed by the runtime.

func NewCacheDir added in v0.7.0

func NewCacheDir(id string, mode ...ConcurrencyMode) CachePath

func NewCachePath added in v0.7.0

func NewCachePath(id string, path FileOrDirPath) CachePath

func ParseCachePath added in v0.7.0

func ParseCachePath(path string) CachePath

func (CachePath) Call added in v0.7.0

func (combiner CachePath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (CachePath) Decode added in v0.7.0

func (value CachePath) Decode(dest any) error

func (CachePath) Dir added in v0.7.0

func (value CachePath) Dir() CachePath

func (CachePath) Equal added in v0.7.0

func (value CachePath) Equal(other Value) bool

func (CachePath) Eval added in v0.7.0

func (value CachePath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (CachePath) Extend added in v0.7.0

func (path CachePath) Extend(ext Path) (Path, error)

func (CachePath) Hash added in v0.7.0

func (value CachePath) Hash() string

Hash returns a non-cryptographic hash of the cache path's ID.

func (CachePath) MarshalProto added in v0.7.0

func (value CachePath) MarshalProto() (proto.Message, error)

func (CachePath) Name added in v0.7.0

func (path CachePath) Name() string

func (CachePath) String added in v0.7.0

func (value CachePath) String() string

func (*CachePath) UnmarshalProto added in v0.7.0

func (path *CachePath) UnmarshalProto(msg proto.Message) error

func (CachePath) Unwrap added in v0.7.0

func (app CachePath) Unwrap() Combiner

type CannotBindError

type CannotBindError struct {
	Have Value
}

func (CannotBindError) Error

func (err CannotBindError) Error() string

type Combiner

type Combiner interface {
	Value

	Call(context.Context, Value, *Scope, Cont) ReadyCont
}

type CommandPath

type CommandPath struct {
	Command string `json:"command"`
}

CommandPath represents a command path in an abstract runtime environment, typically resolved by consulting $PATH.

func (CommandPath) Bind

func (binding CommandPath) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (CommandPath) Call

func (combiner CommandPath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (CommandPath) Decode

func (value CommandPath) Decode(dest any) error

func (CommandPath) EachBinding

func (CommandPath) EachBinding(func(Symbol, Range) error) error

func (CommandPath) Equal

func (value CommandPath) Equal(other Value) bool

func (CommandPath) Eval

func (value CommandPath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (CommandPath) Extend

func (path CommandPath) Extend(ext Path) (Path, error)

func (CommandPath) MarshalProto added in v0.6.0

func (value CommandPath) MarshalProto() (proto.Message, error)

func (CommandPath) Name

func (value CommandPath) Name() string

func (CommandPath) String

func (value CommandPath) String() string

func (*CommandPath) UnmarshalProto added in v0.6.0

func (path *CommandPath) UnmarshalProto(msg proto.Message) error

func (CommandPath) Unwrap

func (app CommandPath) Unwrap() Combiner

type CompleteOpt

type CompleteOpt struct {
	Binding Symbol
	Value   Annotated
}

type CompleteOpts

type CompleteOpts []CompleteOpt

func (CompleteOpts) Len

func (opts CompleteOpts) Len() int

func (CompleteOpts) Less

func (opts CompleteOpts) Less(i, j int) bool

func (CompleteOpts) Swap

func (opts CompleteOpts) Swap(i, j int)

type ConcurrencyMode added in v0.12.0

type ConcurrencyMode int

type Config

type Config struct {
	Runtimes []RuntimeConfig `json:"runtimes"`
}

Config is set by the user and read by the Bass language and runtimes which run on the same machine.

func LoadConfig

func LoadConfig(defaultConfig Config) (*Config, error)

LoadConfig loads a Config from the JSON file at the given path.

type Cons

type Cons Pair

func (Cons) Bind

func (binding Cons) Bind(ctx context.Context, scope *Scope, cont Cont, value Value, _ ...Annotated) ReadyCont

func (Cons) Decode

func (value Cons) Decode(dest any) error

func (Cons) EachBinding

func (binding Cons) EachBinding(cb func(Symbol, Range) error) error

func (Cons) Equal

func (value Cons) Equal(other Value) bool

func (Cons) Eval

func (value Cons) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

Eval evaluates both values in the pair.

func (Cons) First

func (value Cons) First() Value

func (Cons) MarshalJSON

func (value Cons) MarshalJSON() ([]byte, error)

func (Cons) MarshalLogArray added in v0.5.0

func (cons Cons) MarshalLogArray(enc zapcore.ArrayEncoder) error

func (Cons) Rest

func (value Cons) Rest() Value

func (Cons) String

func (value Cons) String() string

type Cont

type Cont interface {
	Value

	// Call returns a ReadyCont that will return the given value or error when
	// called by the outer trampoline. The returned value may itself be another
	// ReadyCont.
	Call(Value, error) ReadyCont
	// contains filtered or unexported methods
}

Cont is a first-class value representing a continuation.

A continuation is a deferred computation to be called with the result of an evaluation. When called it returns a ReadyCont, a "pre-filled" but still deferred computation which will utimately be called by the outer trampoline.

Bass must be implemented in continuation-passing style in order to support infinite loops. Continuations are however not exposed in the language. They are an internal implementation detail which might not be necessary if Bass were to be implemented in another host language.

The outer trampoline is simply a loop that calls the returned continuation until it stops returning ready continuations and instead returns an inert value. This technique is what keeps the stack from growing.

func Continue

func Continue(cont func(Value) Value) Cont

func WithFrame

func WithFrame(ctx context.Context, frame *Annotate, cont Cont) Cont

type Continuation

type Continuation struct {
	Continue    func(Value) Value
	Trace       *Trace
	TracedDepth int
}

func (*Continuation) Call

func (cont *Continuation) Call(res Value, err error) ReadyCont

func (*Continuation) Decode

func (value *Continuation) Decode(dest any) error

func (*Continuation) Equal

func (value *Continuation) Equal(other Value) bool

func (*Continuation) Eval

func (value *Continuation) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*Continuation) MarshalJSON

func (value *Continuation) MarshalJSON() ([]byte, error)

func (*Continuation) String

func (value *Continuation) String() string

type CrossSource added in v0.5.0

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

func (*CrossSource) Close added in v0.11.0

func (cross *CrossSource) Close() error

func (*CrossSource) Next added in v0.5.0

func (cross *CrossSource) Next(ctx context.Context) (Value, error)

func (*CrossSource) String added in v0.5.0

func (cross *CrossSource) String() string

type Custodian added in v0.11.0

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

func CustodianFrom added in v0.11.0

func CustodianFrom(ctx context.Context) (*Custodian, bool)

func NewCustodian added in v0.11.0

func NewCustodian() *Custodian

func (*Custodian) AddCloser added in v0.11.0

func (c *Custodian) AddCloser(closer io.Closer)

func (*Custodian) Close added in v0.11.0

func (c *Custodian) Close() error

type Decodable

type Decodable interface {
	FromValue(Value) error
}

Decodable types typically implement json.Unmarshaler as well.

type DecodeError

type DecodeError struct {
	Source      Value
	Destination any
}

func (DecodeError) Error

func (err DecodeError) Error() string

type Decoder added in v0.5.0

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

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode added in v0.5.0

func (dec *Decoder) Decode(dest any) error

type DirPath

type DirPath struct {
	Path    string   `json:"dir"`
	Include []string `json:"include,omitempty"`
	Exclude []string `json:"exclude,omitempty"`
}

DirPath represents a directory path in an abstract filesystem.

Its interpretation is context-dependent; it may refer to a path in a runtime environment, or a path on the local machine.

func GlobDir added in v0.12.0

func GlobDir(path string, include, exclude []string) DirPath

func NewDirPath added in v0.11.0

func NewDirPath(p string) DirPath

func (DirPath) Bind

func (binding DirPath) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (DirPath) Call

func (combiner DirPath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (DirPath) Decode

func (value DirPath) Decode(dest any) error

func (DirPath) Dir

func (value DirPath) Dir() DirPath

func (DirPath) EachBinding

func (DirPath) EachBinding(func(Symbol, Range) error) error

func (DirPath) Equal

func (value DirPath) Equal(other Value) bool

func (DirPath) Eval

func (value DirPath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (DirPath) Excludes added in v0.12.0

func (value DirPath) Excludes() []string

func (DirPath) Extend

func (dir DirPath) Extend(ext Path) (Path, error)

func (DirPath) FromSlash

func (value DirPath) FromSlash() string

func (DirPath) Includes added in v0.12.0

func (value DirPath) Includes() []string

func (DirPath) IsDir

func (value DirPath) IsDir() bool

func (DirPath) MarshalProto added in v0.6.0

func (value DirPath) MarshalProto() (proto.Message, error)

func (DirPath) Name

func (value DirPath) Name() string

func (DirPath) Slash added in v0.6.0

func (value DirPath) Slash() string

func (DirPath) String

func (value DirPath) String() string

func (*DirPath) UnmarshalProto added in v0.6.0

func (path *DirPath) UnmarshalProto(msg proto.Message) error

func (DirPath) Unwrap

func (combiner DirPath) Unwrap() Combiner

func (DirPath) WithExclude added in v0.12.0

func (value DirPath) WithExclude(paths ...string) Globbable

func (DirPath) WithInclude added in v0.12.0

func (value DirPath) WithInclude(paths ...string) Globbable

type DiscardFilesystem added in v0.12.0

type DiscardFilesystem struct{}

func (DiscardFilesystem) FS added in v0.12.0

func (DiscardFilesystem) FS(root string) (fs.FS, error)

func (DiscardFilesystem) Write added in v0.12.0

func (DiscardFilesystem) Write(path string, r io.Reader) error

type Empty

type Empty struct{}

func (Empty) Bind

func (binding Empty) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (Empty) Decode

func (value Empty) Decode(dest any) error

func (Empty) EachBinding

func (Empty) EachBinding(func(Symbol, Range) error) error

func (Empty) Equal

func (Empty) Equal(other Value) bool

func (Empty) Eval

func (value Empty) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Empty) First

func (Empty) First() Value

func (Empty) MarshalJSON

func (Empty) MarshalJSON() ([]byte, error)

func (Empty) MarshalLogArray added in v0.5.0

func (Empty) MarshalLogArray(enc zapcore.ArrayEncoder) error

func (Empty) MarshalProto added in v0.6.0

func (Empty) MarshalProto() (proto.Message, error)

func (Empty) Rest

func (Empty) Rest() Value

func (Empty) String

func (Empty) String() string

func (*Empty) UnmarshalJSON

func (*Empty) UnmarshalJSON(payload []byte) error

type Encodable

type Encodable interface {
	ToValue() Value
}

Encodable types typically implement json.Marshaler as well.

type EncodeError

type EncodeError struct {
	Value Value
}

func (EncodeError) Error

func (err EncodeError) Error() string

type Error added in v0.7.0

type Error struct {
	Err error
}

func (Error) Call added in v0.7.0

func (value Error) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (Error) Decode added in v0.7.0

func (value Error) Decode(dest any) error

String returns the error message.

func (Error) Equal added in v0.7.0

func (value Error) Equal(o Value) bool

Eval calls the continuation with the error.

func (Error) Eval added in v0.7.0

func (value Error) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval calls the continuation with the error.

func (Error) String added in v0.7.0

func (value Error) String() string

String returns the error message.

type ExtendError

type ExtendError struct {
	Parent Path
	Child  Path
}

func (ExtendError) Error

func (err ExtendError) Error() string

type ExtendOperative

type ExtendOperative struct {
	Path Path
}

ExtendOperative is an operative which constructs a Extend.

func (ExtendOperative) Call

func (op ExtendOperative) Call(_ context.Context, val Value, _ *Scope, cont Cont) ReadyCont

Call constructs a thunk, passing arguments as values on stdin.

func (ExtendOperative) Decode

func (value ExtendOperative) Decode(dest any) error

func (ExtendOperative) Equal

func (value ExtendOperative) Equal(other Value) bool

func (ExtendOperative) Eval

func (value ExtendOperative) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (ExtendOperative) String

func (value ExtendOperative) String() string

type ExtendPath

type ExtendPath struct {
	Parent Value
	Child  FilesystemPath
}

ExtendPath extends a parent path expression with a child path.

func (ExtendPath) Bind

func (binding ExtendPath) Bind(ctx context.Context, scope *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (ExtendPath) Decode

func (value ExtendPath) Decode(dest any) error

func (ExtendPath) EachBinding

func (ExtendPath) EachBinding(func(Symbol, Range) error) error

func (ExtendPath) Equal

func (value ExtendPath) Equal(other Value) bool

func (ExtendPath) Eval

func (value ExtendPath) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

Eval evaluates the Parent value into a Path and extends it with Child.

func (ExtendPath) String

func (value ExtendPath) String() string

type FSPath

type FSPath struct {
	FS   fs.FS         `json:"-"`
	Path FileOrDirPath `json:"path"`
}

FSPath is a Path representing a file or directory relative to a filesystem.

This type will typically never occur in production code. It is only used for embedded filesystems, i.e. in Bass's stdlib and test suites.

JSON tags are specified just for keeping up appearances - this type needs to be marshalable just to support .SHA256, .Name, .Avatar, etc. on a Thunk that embeds it.

func NewFSDir

func NewFSDir(fs fs.FS) *FSPath

func NewFSPath

func NewFSPath(fs fs.FS, path FileOrDirPath) *FSPath

func NewInMemoryFSDir

func NewInMemoryFSDir(fileContentPairs ...Value) (*FSPath, error)

NewInMemoryFSDir is exposed as (mkfs) - it takes alternating file paths and content and constructs an in-memory filesystem path.

func NewInMemoryFile added in v0.6.0

func NewInMemoryFile(name string, content string) *FSPath

func (*FSPath) CachePath added in v0.6.0

func (fsp *FSPath) CachePath(ctx context.Context, dest string) (string, error)

func (*FSPath) Call

func (combiner *FSPath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (*FSPath) Decode

func (value *FSPath) Decode(dest any) error

func (*FSPath) Dir added in v0.6.0

func (value *FSPath) Dir() *FSPath

func (*FSPath) Equal

func (value *FSPath) Equal(other Value) bool

func (*FSPath) Eval

func (value *FSPath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (*FSPath) Extend

func (path *FSPath) Extend(ext Path) (Path, error)

func (*FSPath) Hash added in v0.7.0

func (value *FSPath) Hash() (string, error)

Hash returns a non-cryptographic hash of the filesystem.

func (*FSPath) MarshalProto added in v0.6.0

func (value *FSPath) MarshalProto() (proto.Message, error)

func (*FSPath) Name

func (path *FSPath) Name() string

func (*FSPath) Open added in v0.6.0

func (fsp *FSPath) Open(ctx context.Context) (io.ReadCloser, error)

func (*FSPath) String

func (value *FSPath) String() string

func (*FSPath) UnmarshalProto added in v0.6.0

func (value *FSPath) UnmarshalProto(msg proto.Message) error

func (*FSPath) Unwrap

func (app *FSPath) Unwrap() Combiner

type FileOrDirPath

type FileOrDirPath struct {
	File *FilePath
	Dir  *DirPath
}

FileOrDirPath is an enum type that accepts a FilePath or a DirPath.

func NewFileOrDirPath

func NewFileOrDirPath(path FilesystemPath) FileOrDirPath

func ParseFileOrDirPath

func ParseFileOrDirPath(arg string) FileOrDirPath

ParseFileOrDirPath parses arg as a path using the host machine's separator convention.

If the path is '.' or has a trailing slash, a DirPath is returned.

Otherwise, a FilePath is returned.

func (FileOrDirPath) Excludes added in v0.12.0

func (value FileOrDirPath) Excludes() []string

func (FileOrDirPath) Extend

func (path FileOrDirPath) Extend(ext Path) (FileOrDirPath, error)

Extend extends the value with the given path and returns it wrapped in another FileOrDirPath.

func (FileOrDirPath) FilesystemPath

func (path FileOrDirPath) FilesystemPath() FilesystemPath

FilesystemPath returns the value present.

func (*FileOrDirPath) FromValue

func (path *FileOrDirPath) FromValue(val Value) error

FromValue decodes val into a FilePath or a DirPath, setting whichever worked as the internal value.

func (FileOrDirPath) Includes added in v0.12.0

func (value FileOrDirPath) Includes() []string

func (FileOrDirPath) MarshalJSON

func (value FileOrDirPath) MarshalJSON() ([]byte, error)

func (FileOrDirPath) MarshalProto added in v0.6.0

func (fod FileOrDirPath) MarshalProto() (proto.Message, error)

func (FileOrDirPath) Slash added in v0.6.0

func (path FileOrDirPath) Slash() string

Slash calls Slash on whichever value is present.

func (FileOrDirPath) String

func (path FileOrDirPath) String() string

String calls String on whichever value is present.

func (FileOrDirPath) ToValue

func (path FileOrDirPath) ToValue() Value

ToValue returns the value present.

func (*FileOrDirPath) UnmarshalJSON

func (value *FileOrDirPath) UnmarshalJSON(b []byte) error

func (*FileOrDirPath) UnmarshalProto added in v0.6.0

func (path *FileOrDirPath) UnmarshalProto(msg proto.Message) error

func (FileOrDirPath) WithExclude added in v0.12.0

func (value FileOrDirPath) WithExclude(paths ...string) Globbable

func (FileOrDirPath) WithInclude added in v0.12.0

func (value FileOrDirPath) WithInclude(paths ...string) Globbable

type FilePath

type FilePath struct {
	Path string `json:"file"`
}

FilePath represents a file path in an abstract filesystem.

Its interpretation is context-dependent; it may refer to a path in a runtime environment, or a path on the local machine.

func NewFilePath added in v0.11.0

func NewFilePath(p string) FilePath

func (FilePath) Bind

func (binding FilePath) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (FilePath) Call

func (combiner FilePath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (FilePath) Decode

func (value FilePath) Decode(dest any) error

func (FilePath) Dir

func (value FilePath) Dir() DirPath

func (FilePath) EachBinding

func (FilePath) EachBinding(func(Symbol, Range) error) error

func (FilePath) Equal

func (value FilePath) Equal(other Value) bool

func (FilePath) Eval

func (value FilePath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (FilePath) Extend

func (path_ FilePath) Extend(ext Path) (Path, error)

func (FilePath) FileOrDir

func (app FilePath) FileOrDir() FileOrDirPath

func (FilePath) FromSlash

func (value FilePath) FromSlash() string

func (FilePath) IsDir

func (value FilePath) IsDir() bool

func (FilePath) MarshalProto added in v0.6.0

func (value FilePath) MarshalProto() (proto.Message, error)

func (FilePath) Name

func (value FilePath) Name() string

func (FilePath) Slash added in v0.6.0

func (value FilePath) Slash() string

func (FilePath) String

func (value FilePath) String() string

func (*FilePath) UnmarshalProto added in v0.6.0

func (path *FilePath) UnmarshalProto(msg proto.Message) error

func (FilePath) Unwrap

func (app FilePath) Unwrap() Combiner

type Filesystem added in v0.12.0

type Filesystem interface {
	FS(root string) (fs.FS, error)
	Write(path string, r io.Reader) error
}

The filesystem for host paths. Re-assign it to DiscardFilesystem to disable writing to the host.

type FilesystemPath

type FilesystemPath interface {
	Path

	// Slash returns the path representation with forward slash path separators.
	Slash() string

	// FromSlash uses filepath.FromSlash to convert the path to host machine's
	// path separators.
	FromSlash() string

	// IsDir returns true if the path refers to a directory.
	IsDir() bool

	// Dir returns the parent directory of the path, or the same directory if
	// there is no parent.
	Dir() DirPath
}

FilesystemPath is a Path representing a file or directory in a filesystem.

type FlagError added in v0.1.1

type FlagError struct {
	Err   error
	Flags *pflag.FlagSet
}

func (FlagError) Error added in v0.1.1

func (err FlagError) Error() string

func (FlagError) NiceError added in v0.1.1

func (err FlagError) NiceError(w io.Writer, outer error) error

type FormAnalyzer

type FormAnalyzer interface {
	Analyze(context.Context, Annotate)
}

type Globbable added in v0.12.0

type Globbable interface {
	// Includes returns the glob patterns to include. If empty, all files are
	// included.
	Includes() []string

	// WithInclude appends to the list of glob patterns to include.
	WithInclude(...string) Globbable

	// Excludes returns the glob patterns to exclude from the included set.
	Excludes() []string

	// WithExclude appends to the list of glob patterns to exclude.
	WithExclude(...string) Globbable
}

Globbable is a Path that supports include/exclude filters.

type HostFilesystem added in v0.12.0

type HostFilesystem struct{}

func (HostFilesystem) FS added in v0.12.0

func (HostFilesystem) FS(root string) (fs.FS, error)

func (HostFilesystem) Write added in v0.12.0

func (HostFilesystem) Write(path string, r io.Reader) error

type HostPath

type HostPath struct {
	ContextDir string        `json:"context"`
	Path       FileOrDirPath `json:"path"`
}

HostPath is a Path representing an absolute path on the host machine's filesystem.

As of Bass v0.12.0, it is a bit of a misnomer; ContextDir might also be a logical name of a filesystem instead. It will be passed to the global FS instance to produce a fs.FS.

func NewHostDir

func NewHostDir(contextDir string) HostPath

func NewHostPath

func NewHostPath(contextDir string, path FileOrDirPath) HostPath

func ParseHostPath added in v0.6.0

func ParseHostPath(path string) HostPath

func (HostPath) CachePath added in v0.6.0

func (path HostPath) CachePath(ctx context.Context, dest string) (string, error)

func (HostPath) Call

func (combiner HostPath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (HostPath) Decode

func (value HostPath) Decode(dest any) error

func (HostPath) Dir added in v0.7.0

func (value HostPath) Dir() HostPath

func (HostPath) Equal

func (value HostPath) Equal(other Value) bool

func (HostPath) Eval

func (value HostPath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (HostPath) Excludes added in v0.12.0

func (value HostPath) Excludes() []string

func (HostPath) Extend

func (path HostPath) Extend(ext Path) (Path, error)

func (HostPath) FSPath added in v0.12.0

func (path HostPath) FSPath() (*FSPath, error)

func (HostPath) Hash added in v0.7.0

func (value HostPath) Hash() string

Hash returns a non-cryptographic hash of the host path's context dir.

func (HostPath) Includes added in v0.12.0

func (value HostPath) Includes() []string

func (HostPath) MarshalProto added in v0.6.0

func (value HostPath) MarshalProto() (proto.Message, error)

func (HostPath) Name

func (path HostPath) Name() string

func (HostPath) Open added in v0.6.0

func (path HostPath) Open(context.Context) (io.ReadCloser, error)

func (HostPath) String

func (value HostPath) String() string

func (*HostPath) UnmarshalProto added in v0.6.0

func (path *HostPath) UnmarshalProto(msg proto.Message) error

func (HostPath) Unwrap

func (app HostPath) Unwrap() Combiner

func (HostPath) WithExclude added in v0.12.0

func (value HostPath) WithExclude(paths ...string) Globbable

func (HostPath) WithInclude added in v0.12.0

func (value HostPath) WithInclude(paths ...string) Globbable

func (HostPath) Write added in v0.12.0

func (path HostPath) Write(ctx context.Context, src io.Reader) error

type HostPathEscapeError added in v0.6.0

type HostPathEscapeError struct {
	ContextDir string
	Attempted  string
}

HostPathEscapeError is returned when an attempt is made to (read) a host path that traverses outside of its context dir.

func (HostPathEscapeError) Error added in v0.6.0

func (err HostPathEscapeError) Error() string

type Ignore

type Ignore struct{}

func (Ignore) Bind

func (Ignore) Bind(_ context.Context, _ *Scope, cont Cont, _ Value, _ ...Annotated) ReadyCont

func (Ignore) Decode

func (value Ignore) Decode(dest any) error

func (Ignore) EachBinding

func (Ignore) EachBinding(func(Symbol, Range) error) error

func (Ignore) Equal

func (Ignore) Equal(other Value) bool

func (Ignore) Eval

func (value Ignore) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (Ignore) String

func (Ignore) String() string

type ImageArchive added in v0.10.0

type ImageArchive struct {
	// An OCI image archive tarball to load.
	File ImageBuildInput `json:"file"`

	// The platform to target; influences runtime selection.
	Platform Platform `json:"platform"`

	// The tag to use from the archive.
	Tag string `json:"tag,omitempty"`
}

ImageArchive specifies an OCI image tarball.

func (ImageArchive) MarshalProto added in v0.10.0

func (ref ImageArchive) MarshalProto() (proto.Message, error)

func (*ImageArchive) UnmarshalProto added in v0.10.0

func (ref *ImageArchive) UnmarshalProto(msg proto.Message) error

type ImageBuildInput added in v0.12.0

type ImageBuildInput struct {
	Thunk *ThunkPath
	Host  *HostPath
	FS    *FSPath
}

func (*ImageBuildInput) FromValue added in v0.12.0

func (enum *ImageBuildInput) FromValue(val Value) error

func (ImageBuildInput) MarshalJSON added in v0.12.0

func (enum ImageBuildInput) MarshalJSON() ([]byte, error)

func (ImageBuildInput) MarshalProto added in v0.12.0

func (ref ImageBuildInput) MarshalProto() (proto.Message, error)

func (ImageBuildInput) ToPath added in v0.12.0

func (enum ImageBuildInput) ToPath() Path

func (*ImageBuildInput) ToReadable added in v0.12.0

func (enum *ImageBuildInput) ToReadable() Readable

func (ImageBuildInput) ToValue added in v0.12.0

func (enum ImageBuildInput) ToValue() Value

func (*ImageBuildInput) UnmarshalJSON added in v0.12.0

func (enum *ImageBuildInput) UnmarshalJSON(payload []byte) error

func (*ImageBuildInput) UnmarshalProto added in v0.12.0

func (ref *ImageBuildInput) UnmarshalProto(msg proto.Message) error

type ImageDockerBuild added in v0.12.0

type ImageDockerBuild struct {
	// The platform to target; influences runtime selection.
	Platform Platform `json:"platform"`

	// An OCI image archive tarball to load.
	Context ImageBuildInput `json:"docker_build"`

	// Path to a Dockerfile to use within the context.
	Dockerfile *FilePath `json:"dockerfile,omitempty"`

	// Target witin the Dockerfile to build.
	Target string `json:"target,omitempty"`

	// Arbitrary key-value args to pass to the build.
	Args *Scope `json:"args,omitempty"`
}

ImageDockerBuild specifies an OCI image tarball.

func (ImageDockerBuild) MarshalProto added in v0.12.0

func (ref ImageDockerBuild) MarshalProto() (proto.Message, error)

func (*ImageDockerBuild) UnmarshalProto added in v0.12.0

func (ref *ImageDockerBuild) UnmarshalProto(msg proto.Message) error

type ImageRef added in v0.10.0

type ImageRef struct {
	// A reference to an image hosted on a registry.
	Repository ImageRepository `json:"repository"`

	// The platform to target; influences runtime selection.
	Platform Platform `json:"platform,omitempty"`

	// The tag to use, either from the repository or in a multi-tag OCI archive.
	Tag string `json:"tag,omitempty"`

	// An optional digest for maximally reprodicuble builds.
	Digest string `json:"digest,omitempty"`
}

ImageRef specifies an OCI image uploaded to a registry.

func (ImageRef) MarshalProto added in v0.10.0

func (ref ImageRef) MarshalProto() (proto.Message, error)

func (ImageRef) Ref added in v0.10.0

func (ref ImageRef) Ref() (string, error)

func (ImageRef) Thunk added in v0.12.0

func (ref ImageRef) Thunk() Thunk

func (*ImageRef) UnmarshalProto added in v0.10.0

func (ref *ImageRef) UnmarshalProto(msg proto.Message) error

type ImageRepository added in v0.10.0

type ImageRepository struct {
	Static string
	Addr   *ThunkAddr
}

func (*ImageRepository) FromValue added in v0.10.0

func (repo *ImageRepository) FromValue(val Value) error

FromValue decodes val into a FilePath or a DirPath, setting whichever worked as the internal value.

func (ImageRepository) ToValue added in v0.10.0

func (path ImageRepository) ToValue() Value

ToValue returns the value present.

type InMemorySink

type InMemorySink struct {
	Values []Value
}

func NewInMemorySink

func NewInMemorySink() *InMemorySink

func (*InMemorySink) Emit

func (src *InMemorySink) Emit(val Value) error

func (*InMemorySink) Reset

func (sink *InMemorySink) Reset()

func (*InMemorySink) Source

func (sink *InMemorySink) Source() PipeSource

func (*InMemorySink) String

func (src *InMemorySink) String() string

type InMemorySource

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

func NewInMemorySource

func NewInMemorySource(vals ...Value) *InMemorySource

func (*InMemorySource) Close added in v0.11.0

func (src *InMemorySource) Close() error

func (*InMemorySource) Next

func (src *InMemorySource) Next(_ context.Context) (Value, error)

func (*InMemorySource) String

func (src *InMemorySource) String() string

type Int

type Int int

func (Int) Bind

func (binding Int) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (Int) Decode

func (value Int) Decode(dest any) error

func (Int) EachBinding

func (Int) EachBinding(func(Symbol, Range) error) error

func (Int) Equal

func (value Int) Equal(other Value) bool

func (Int) Eval

func (value Int) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Int) MarshalProto added in v0.6.0

func (value Int) MarshalProto() (proto.Message, error)

func (Int) String

func (value Int) String() string

type JSONProtocol

type JSONProtocol struct{}

JSON protocol decodes a values from JSON stream.

func (JSONProtocol) DecodeStream added in v0.11.0

func (JSONProtocol) DecodeStream(ctx context.Context, r io.ReadCloser) (PipeSource, error)

DecodeStream returns a pipe source decoding from r.

type JSONSink

type JSONSink struct {
	Name string
	// contains filtered or unexported fields
}

func NewJSONSink

func NewJSONSink(name string, out io.Writer) *JSONSink

func (*JSONSink) Emit

func (sink *JSONSink) Emit(val Value) error

func (*JSONSink) String

func (sink *JSONSink) String() string

type JSONSource

type JSONSource struct {
	Name string

	io.Closer
	// contains filtered or unexported fields
}

func NewJSONSource

func NewJSONSource(name string, in io.ReadCloser) *JSONSource

func (*JSONSource) Next

func (source *JSONSource) Next(context.Context) (Value, error)

func (*JSONSource) String

func (source *JSONSource) String() string

type Keyword

type Keyword string

Keyword is a value that evaluates to a symbol.

func (Keyword) Bind

func (binding Keyword) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

Bind performs constant value binding; it only succeeds against an equal value and introduces no bindings.

func (Keyword) Decode

func (value Keyword) Decode(dest any) error

Decode coerces the keyword into another compatible type.

func (Keyword) EachBinding

func (Keyword) EachBinding(func(Symbol, Range) error) error

EachBinding does nothing.

func (Keyword) Equal

func (value Keyword) Equal(other Value) bool

Equal returns true if the other value is a Keyword representing the same symbol.

func (Keyword) Eval

func (value Keyword) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the keyword's symbol.

func (Keyword) String

func (value Keyword) String() string

String returns the keyword's symbol in keyword notation.

func (Keyword) Symbol

func (value Keyword) Symbol() Symbol

Symbol converts the keyword to a symbol.

type LineProtocol added in v0.11.0

type LineProtocol struct{}

LineProtocol parse lines of output.

Empty lines correspond to empty arrays.

func (LineProtocol) DecodeStream added in v0.11.0

func (proto LineProtocol) DecodeStream(ctx context.Context, rc io.ReadCloser) (PipeSource, error)

DecodeStream returns a pipe source decoding from r.

type List

type List interface {
	Value
	Bindable

	First() Value
	Rest() Value
}

func NewConsList

func NewConsList(vals ...Value) List

func NewList

func NewList(vals ...Value) List

func ToCons

func ToCons(list List) List

type Lockfile

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

func NewLockfileMemo

func NewLockfileMemo(path string) *Lockfile

func (*Lockfile) Remove

func (file *Lockfile) Remove(thunk Thunk, binding Symbol, input Value) error

func (*Lockfile) Retrieve

func (file *Lockfile) Retrieve(thunk Thunk, binding Symbol, input Value) (Value, bool, error)

func (*Lockfile) Store

func (file *Lockfile) Store(thunk Thunk, binding Symbol, input Value, output Value) error

type Memos

type Memos interface {
	Store(Thunk, Symbol, Value, Value) error
	Retrieve(Thunk, Symbol, Value) (Value, bool, error)
	Remove(Thunk, Symbol, Value) error
}

Memos is where memoized calls are cached.

func OpenMemos

func OpenMemos(ctx context.Context, readable Readable) (Memos, error)

type NiceError

type NiceError interface {
	error

	NiceError(io.Writer, error) error
}

NiceError is an error that is able to provide some extra guidance to the user.

Strive for all errors returned by Bass to become a NiceError.

type Null

type Null struct{}

func (Null) Bind

func (binding Null) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (Null) Decode

func (value Null) Decode(dest any) error

Decode decodes into a Null or into bool (setting false).

func (Null) EachBinding

func (Null) EachBinding(func(Symbol, Range) error) error

func (Null) Equal

func (Null) Equal(other Value) bool

func (Null) Eval

func (value Null) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Null) MarshalJSON

func (Null) MarshalJSON() ([]byte, error)

MarshalJSON marshals as `null`.

func (Null) MarshalProto added in v0.6.0

func (value Null) MarshalProto() (proto.Message, error)

func (Null) String

func (Null) String() string

type Operative

type Operative struct {
	Bindings     Bindable
	ScopeBinding Bindable
	Body         Value
	StaticScope  *Scope
}

func (*Operative) Call

func (combiner *Operative) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (*Operative) Decode

func (value *Operative) Decode(dest any) error

func (*Operative) Equal

func (value *Operative) Equal(other Value) bool

func (*Operative) Eval

func (value *Operative) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*Operative) MarshalJSON

func (value *Operative) MarshalJSON() ([]byte, error)

func (*Operative) String

func (value *Operative) String() string

type Pair

type Pair struct {
	A Value
	D Value
}

func (Pair) Bind

func (binding Pair) Bind(ctx context.Context, scope *Scope, cont Cont, value Value, _ ...Annotated) ReadyCont

func (Pair) Decode

func (value Pair) Decode(dest any) error

func (Pair) EachBinding

func (binding Pair) EachBinding(cb func(Symbol, Range) error) error

func (Pair) Equal

func (value Pair) Equal(other Value) bool

func (Pair) Eval

func (value Pair) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

Pair combines the first operand with the second operand.

If the first value is not a Combiner, an error is returned.

func (Pair) First

func (value Pair) First() Value

func (Pair) MarshalJSON

func (value Pair) MarshalJSON() ([]byte, error)

func (Pair) MarshalLogArray added in v0.5.0

func (pair Pair) MarshalLogArray(enc zapcore.ArrayEncoder) error

func (Pair) MarshalProto added in v0.6.0

func (value Pair) MarshalProto() (proto.Message, error)

func (Pair) Rest

func (value Pair) Rest() Value

func (Pair) String

func (value Pair) String() string

func (*Pair) UnmarshalJSON

func (value *Pair) UnmarshalJSON(payload []byte) error

type Path

type Path interface {
	// All Paths are Values.
	Value

	// Name returns the unqualified name for the path, i.e. the base name of a
	// file or directory, or the name of a command.
	Name() string

	// Extend returns a path referring to the given path relative to the parent
	// Path.
	Extend(Path) (Path, error)
}

Path is an abstract location identifier for files, directories, or executable commands.

type PipeSink

type PipeSink interface {
	String() string
	Emit(Value) error
}

type PipeSource

type PipeSource interface {
	String() string
	Next(context.Context) (Value, error)
	Close() error
}

func DecodeProto

func DecodeProto(ctx context.Context, name Symbol, r io.ReadCloser) (PipeSource, error)

DecodeProto uses the named protocol to decode values from r into the sink.

type Platform

type Platform ocispecs.Platform

Platform configures an OCI image platform.

func (Platform) CanSelect

func (platform Platform) CanSelect(given Platform) bool

CanSelect returns true if the given platform (from a runtime) matches.

func (*Platform) FromValue added in v0.12.0

func (platform *Platform) FromValue(val Value) error

func (Platform) String

func (platform Platform) String() string

func (*Platform) UnmarshalProto added in v0.6.0

func (platform *Platform) UnmarshalProto(msg proto.Message) error

type Position added in v0.6.0

type Position struct {
	Ln, Col int
}

type ProtoMarshaler added in v0.6.0

type ProtoMarshaler interface {
	MarshalProto() (proto.Message, error)
}

type ProtoUnmarshaler added in v0.6.0

type ProtoUnmarshaler interface {
	UnmarshalProto(proto.Message) error
}

type Protocol

type Protocol interface {
	// DecodeStream decodes values from the reader.
	DecodeStream(context.Context, io.ReadCloser) (PipeSource, error)
}

Protocol determines how response data is parsed from a thunk's response.

type PruneOpts

type PruneOpts struct {
	// Prune everything.
	All bool

	// Keep data last used within the duration.
	KeepDuration time.Duration

	// Keep
	KeepBytes int64
}

PruneOpts contains parameters to fine-tune the pruning behavior. These parameters are best-effort; not all runtimes are expected to support every option.

type Range

type Range struct {
	File Readable

	Start, End Position
}

func (*Range) FromMeta

func (r *Range) FromMeta(meta *Scope) error

func (Range) IsWithin

func (inner Range) IsWithin(outer Range) bool

func (Range) String

func (r Range) String() string

func (Range) ToMeta

func (r Range) ToMeta(meta *Scope)

type RawProtocol

type RawProtocol struct{}

Raw protocol buffers the entire stream and writes it as a single JSON string on flush.

func (RawProtocol) DecodeStream added in v0.11.0

func (RawProtocol) DecodeStream(ctx context.Context, rc io.ReadCloser) (PipeSource, error)

DecodeStream returns a pipe source decoding from r.

type ReadError

type ReadError struct {
	Err   reader.Error
	Range Range
}

ReadError is returned when the reader trips on a syntax token.

func (ReadError) Error

func (err ReadError) Error() string

func (ReadError) Unwrap added in v0.4.0

func (err ReadError) Unwrap() error

type Readable

type Readable interface {
	Value

	// CachePath returns a local file path to the content for caching purposes.
	//
	// Caches may be created under the given dest if needed. Implementations must
	// take care not to clobber each other's caches.
	CachePath(ctx context.Context, dest string) (string, error)

	// Open opens the resource for reading.
	Open(context.Context) (io.ReadCloser, error)
}

Readable is any Value that can be (read).

type Reader

type Reader struct {
	File Readable

	Analyzer FormAnalyzer
	Context  context.Context
	// contains filtered or unexported fields
}

func NewReader

func NewReader(src io.Reader, file Readable) *Reader

func (*Reader) Next

func (reader *Reader) Next() (Value, error)

type ReadonlyMemos

type ReadonlyMemos struct {
	Content *proto.Memosphere
}

func (ReadonlyMemos) Remove

func (file ReadonlyMemos) Remove(thunk Thunk, binding Symbol, input Value) error

func (ReadonlyMemos) Retrieve

func (file ReadonlyMemos) Retrieve(thunk Thunk, binding Symbol, input Value) (Value, bool, error)

func (ReadonlyMemos) Store

func (file ReadonlyMemos) Store(thunk Thunk, binding Symbol, input Value, output Value) error

type ReadyCont

type ReadyCont interface {
	Value

	// Go either returns the predestined error or calls the inner continuation
	Go() (Value, error)
}

ReadyCont is a continuation with a predestined intermediate value or error. It is valled by the trampoline.

func BindList

func BindList(ctx context.Context, scope *Scope, cont Cont, binding List, value Value) ReadyCont

func EvalPair

func EvalPair(ctx context.Context, scope *Scope, pair Pair, cont Cont) ReadyCont

func PrintDocs

func PrintDocs(ctx context.Context, cont Cont, scope *Scope, forms ...Value) ReadyCont

type ReadyContinuation

type ReadyContinuation struct {
	Cont *Continuation

	Result Value
	Err    error
}

func (*ReadyContinuation) Decode

func (value *ReadyContinuation) Decode(dest any) error

func (*ReadyContinuation) Equal

func (value *ReadyContinuation) Equal(other Value) bool

func (*ReadyContinuation) Eval

func (value *ReadyContinuation) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*ReadyContinuation) Go

func (cont *ReadyContinuation) Go() (Value, error)

func (*ReadyContinuation) MarshalJSON

func (value *ReadyContinuation) MarshalJSON() ([]byte, error)

func (*ReadyContinuation) String

func (cont *ReadyContinuation) String() string

type RunState added in v0.6.0

type RunState struct {
	Dir    Path
	Env    *Scope
	Stdin  *Source
	Stdout *Sink
}

type Runs added in v0.6.0

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

func RunsFromContext added in v0.6.0

func RunsFromContext(ctx context.Context) *Runs

func TrackRuns added in v0.6.0

func TrackRuns(ctx context.Context) (context.Context, *Runs)

func (*Runs) Err added in v0.10.0

func (runs *Runs) Err() error

func (*Runs) Go added in v0.6.0

func (runs *Runs) Go(stop func(), f func() error)

func (*Runs) Stop added in v0.10.0

func (runs *Runs) Stop()

func (*Runs) StopAndWait added in v0.10.0

func (runs *Runs) StopAndWait() error

func (*Runs) Wait added in v0.6.0

func (runs *Runs) Wait() error

type Runtime

func RuntimeFromContext

func RuntimeFromContext(ctx context.Context, platform Platform) (Runtime, error)

type RuntimeConfig

type RuntimeConfig struct {
	Platform Platform `json:"platform"`
	Runtime  string   `json:"runtime"`
	Config   *Scope   `json:"config,omitempty"`
}

RuntimeConfig associates a platform object to a runtime command to run.

Additional configuration may be specified; it will be read from the runtime by finding the config associated to the platform on the thunk it receives.

type RuntimePool

type RuntimePool interface {
	Select(Platform) (Runtime, error)
	All() ([]Runtime, error)
}

func RuntimePoolFromContext

func RuntimePoolFromContext(ctx context.Context) (RuntimePool, error)

type Scope

type Scope struct {
	// an optional name for the scope, used to prettify .String on 'standard'
	// environments
	Name string

	Parents  []*Scope
	Bindings Bindings
	Order    []Symbol
}

Scope contains bindings from symbols to values, and parent scopes to delegate to during symbol lookup.

var Internal *Scope = NewEmptyScope()

func Assoc added in v0.5.0

func Assoc(obj *Scope, kv ...Value) (*Scope, error)

func ImportSystemEnv

func ImportSystemEnv() *Scope

ImportSystemEnv converts the system env into a scope.

func NewEmptyScope

func NewEmptyScope(parents ...*Scope) *Scope

NewEmptyScope constructs a new scope with no bindings and optional parents.

func NewRunScope added in v0.6.0

func NewRunScope(parent *Scope, state RunState) *Scope

func NewScope

func NewScope(bindings Bindings, parents ...*Scope) *Scope

NewScope constructs a new scope with the given bindings and optional parents.

func NewStandardScope

func NewStandardScope() *Scope

NewStandardScope returns a new empty scope with Ground as its sole parent.

func (*Scope) Binds added in v0.7.0

func (scope *Scope) Binds(binding Symbol) bool

Binds returns true if the scope provides the given binding.

func (*Scope) Complete

func (scope *Scope) Complete(prefix string) []CompleteOpt

Complete queries the scope for bindings beginning with the given prefix.

Local bindings are listed before parent bindings, with shorter binding names listed first.

func (*Scope) Copy

func (value *Scope) Copy() *Scope

func (*Scope) Decode

func (value *Scope) Decode(dest any) error

func (*Scope) Each

func (value *Scope) Each(f func(Symbol, Value) error) error

Reduce calls f for each binding-value pair mapped by the scope.

Note that shadowed bindings will be skipped.

func (*Scope) Equal

func (value *Scope) Equal(o Value) bool

func (*Scope) Eval

func (value *Scope) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (*Scope) Get

func (scope *Scope) Get(binding Symbol) (Value, bool)

Get fetches the given binding.

If a value is set in the local bindings, it is returned.

If not, the parent scopes are queried in order.

If no value is found, false is returned.

func (*Scope) GetDecode

func (scope *Scope) GetDecode(binding Symbol, dest any) error

GetDecode fetches the given binding and Decodes its value.

func (*Scope) IsEmpty

func (value *Scope) IsEmpty() bool

func (*Scope) IsSubsetOf

func (value *Scope) IsSubsetOf(other *Scope) bool

func (*Scope) MarshalJSON

func (value *Scope) MarshalJSON() ([]byte, error)

func (*Scope) MarshalLogObject added in v0.5.0

func (scope *Scope) MarshalLogObject(enc zapcore.ObjectEncoder) error

func (*Scope) MarshalProto added in v0.6.0

func (value *Scope) MarshalProto() (proto.Message, error)

func (*Scope) Set

func (scope *Scope) Set(binding Symbol, value Value, docs ...string)

Set assigns the value in the local bindings.

func (*Scope) String

func (value *Scope) String() string

func (*Scope) UnmarshalJSON

func (value *Scope) UnmarshalJSON(payload []byte) error

type Secret

type Secret struct {
	Name string `json:"secret"`
	// contains filtered or unexported fields
}

func NewSecret

func NewSecret(name string, inner []byte) Secret

func (Secret) Decode

func (value Secret) Decode(dest any) error

Decode only supports decoding into a Secret or Value; it will not reveal the inner secret.

func (Secret) Equal

func (secret Secret) Equal(other Value) bool

Equal returns false; secrets cannot be compared.

func (Secret) Eval

func (secret Secret) Eval(ctx context.Context, scope *Scope, cont Cont) ReadyCont

Eval does nothing and returns the secret.

func (Secret) MarshalJSON added in v0.6.0

func (value Secret) MarshalJSON() ([]byte, error)

func (Secret) MarshalProto added in v0.6.0

func (value Secret) MarshalProto() (proto.Message, error)

func (Secret) Reveal

func (secret Secret) Reveal() []byte

func (Secret) String

func (secret Secret) String() string

func (*Secret) UnmarshalJSON added in v0.6.0

func (value *Secret) UnmarshalJSON(b []byte) error

func (*Secret) UnmarshalProto added in v0.6.0

func (value *Secret) UnmarshalProto(msg proto.Message) error

type Session added in v0.6.0

type Session struct {
	// Root is the base level scope inherited by all modules.
	Root *Scope
	// contains filtered or unexported fields
}

func NewBass added in v0.6.0

func NewBass() *Session

NewBass returns a new session with Ground as its root scope.

func NewSession added in v0.7.0

func NewSession(ground *Scope) *Session

NewSession returns a new session with the specified root scope.

func (*Session) Load added in v0.6.0

func (session *Session) Load(ctx context.Context, thunk Thunk) (*Scope, error)

func (*Session) Run added in v0.6.0

func (session *Session) Run(ctx context.Context, thunk Thunk, state RunState) error

type Sink

type Sink struct {
	PipeSink PipeSink
}

func NewSink

func NewSink(ps PipeSink) *Sink

func (*Sink) Decode

func (value *Sink) Decode(dest any) error

func (*Sink) Equal

func (sink *Sink) Equal(other Value) bool

func (*Sink) Eval

func (value *Sink) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*Sink) MarshalJSON

func (value *Sink) MarshalJSON() ([]byte, error)

func (*Sink) String

func (value *Sink) String() string

type Source

type Source struct {
	PipeSource PipeSource
}

func Across added in v0.5.0

func Across(ctx context.Context, sources ...*Source) *Source

func NewSource

func NewSource(ps PipeSource) *Source

func (*Source) Decode

func (value *Source) Decode(dest any) error

func (*Source) Equal

func (value *Source) Equal(other Value) bool

func (*Source) Eval

func (value *Source) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (*Source) MarshalJSON

func (value *Source) MarshalJSON() ([]byte, error)

func (*Source) String

func (value *Source) String() string

type String

type String string

func (String) Bind

func (binding String) Bind(_ context.Context, _ *Scope, cont Cont, val Value, _ ...Annotated) ReadyCont

func (String) Decode

func (value String) Decode(dest any) error

func (String) EachBinding

func (String) EachBinding(func(Symbol, Range) error) error

func (String) Equal

func (value String) Equal(other Value) bool

func (String) Eval

func (value String) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (String) MarshalProto added in v0.6.0

func (value String) MarshalProto() (proto.Message, error)

func (String) String

func (value String) String() string

type StructuredError added in v0.5.0

type StructuredError struct {
	Message string
	Fields  *Scope
}

func (*StructuredError) Error added in v0.5.0

func (err *StructuredError) Error() string

func (*StructuredError) NiceError added in v0.5.0

func (structured *StructuredError) NiceError(w io.Writer, outer error) error

type Symbol

type Symbol string
const (
	RunBindingStdin  Symbol = "*stdin*"
	RunBindingStdout Symbol = "*stdout*"
	RunBindingDir    Symbol = "*dir*"
	RunBindingEnv    Symbol = "*env*"
	RunBindingMain   Symbol = "main"
)
var (
	// DocMetaBinding is the binding in meta that stores the value's doc string.
	DocMetaBinding Symbol = "doc"

	// FileMetaBinding is the binding in meta that stores the value's definition file.
	FileMetaBinding Symbol = "file"

	// LineMetaBinding is the binding in meta that stores the value's definition line.
	LineMetaBinding Symbol = "line"

	// ColumnMetaBinding is the binding in meta that stores the value's definition column.
	ColumnMetaBinding Symbol = "column"

	// DeprecatedMetaBinding is the binding in meta that indicates that the value is deprecated.
	//
	// It should define a string message indicating the alternative to use.
	DeprecatedMetaBinding Symbol = "deprecated"
)

func Predicates

func Predicates(val Value) []Symbol

Predicates returns a list of all builtin predicates which return true for the given value.

func SymbolFromJSONKey

func SymbolFromJSONKey(key string) Symbol

func (Symbol) Bind

func (binding Symbol) Bind(ctx context.Context, scope *Scope, cont Cont, val Value, doc ...Annotated) ReadyCont

func (Symbol) Call

func (combiner Symbol) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (Symbol) Decode

func (value Symbol) Decode(dest any) error

func (Symbol) EachBinding

func (binding Symbol) EachBinding(cb func(Symbol, Range) error) error

func (Symbol) Equal

func (value Symbol) Equal(other Value) bool

func (Symbol) Eval

func (value Symbol) Eval(_ context.Context, scope *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Symbol) JSONKey

func (value Symbol) JSONKey() string

func (Symbol) Keyword

func (value Symbol) Keyword() Keyword

func (Symbol) String

func (value Symbol) String() string

func (Symbol) Unwrap

func (app Symbol) Unwrap() Combiner

type SymbolOperative

type SymbolOperative struct {
	Symbol Symbol
}

func (SymbolOperative) Call

func (op SymbolOperative) Call(_ context.Context, val Value, _ *Scope, cont Cont) ReadyCont

func (SymbolOperative) Decode

func (value SymbolOperative) Decode(dest any) error

func (SymbolOperative) Equal

func (value SymbolOperative) Equal(other Value) bool

func (SymbolOperative) Eval

func (value SymbolOperative) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (SymbolOperative) String

func (value SymbolOperative) String() string

type TarProtocol added in v0.11.0

type TarProtocol struct{}

func (TarProtocol) DecodeStream added in v0.11.0

func (proto TarProtocol) DecodeStream(ctx context.Context, rc io.ReadCloser) (PipeSource, error)

type Thunk

type Thunk struct {
	// Image specifies the OCI image in which to run the thunk.
	//
	// If not present, the thunk is a native "Bass" thunk representing a module
	// to load.
	Image *ThunkImage `json:"image,omitempty"`

	// Insecure may be set to true to enable running the thunk with elevated
	// privileges. Its meaning is determined by the runtime.
	Insecure bool `json:"insecure,omitempty"`

	// Args is a list of string or path arguments.
	//
	// If left empty, and the thunk is forced to run via (run), (read), or an
	// output path, the parent Entrypoint and DefaultArgs are used.
	Args          []Value `json:"args,omitempty"`
	UseEntrypoint bool    `json:"use_entrypoint,omitempty"`

	// Stdin is a list of arbitrary values, which may contain paths, to pass to
	// the command.
	Stdin []Value `json:"stdin,omitempty"`

	// Env is a mapping from environment variables to their string or path
	// values.
	Env *Scope `json:"env,omitempty"`

	// Dir configures a working directory in which to run the command.
	//
	// Note that a working directory is automatically provided to thunks by
	// the runtime. A relative Dir value will be relative to this working
	// directory, not the OCI image's initial working directory. The OCI image's
	// working directory is ignored.
	//
	// A relative directory path will be relative to the initial working
	// directory. An absolute path will be relative to the OCI image root.
	//
	// A thunk directory path may also be provided. It will be mounted to the
	// container and used as the working directory of the command.
	Dir *ThunkDir `json:"dir,omitempty"`

	// Mounts configures explicit mount points for the thunk, in addition to
	// any provided in Path, Args, Stdin, Env, or Dir.
	Mounts []ThunkMount `json:"mounts,omitempty"`

	// Labels specify arbitrary fields for identifying the thunk, typically
	// used to influence caching behavior.
	//
	// For example, thunks which may return different results over time should
	// embed the current timestamp truncated to a certain amount of granularity,
	// e.g. one minute. Doing so prevents the first call from being cached
	// forever while still allowing some level of caching to take place.
	Labels *Scope `json:"labels,omitempty"`

	// Ports is a mapping from arbitrary names to port numbers on which the
	// command listens.
	//
	// Ports may be referenced by ThunkAddrs. When a ThunkAddr is used by another
	// thunk its embedded thunk will be started and all ports will be polled
	// until they are listening.
	Ports []ThunkPort `json:"ports,omitempty"`

	// TLS configures paths to place generated certificates.
	TLS *ThunkTLS `json:"tls,omitempty"`

	// Entrypoint configures a static command and arguments that will be
	// prepended to any command the published container runs.
	//
	// A null value inherits from the parent. An empty slice removes it.
	//
	// Note that Bass thunks don't actually use the entrypoint themselves.
	Entrypoint      []string `json:"entrypoint,omitempty"`
	ClearEntrypoint bool     `json:"clear_entrypoint,omitempty"`

	// DefaultArgs configures a command and arguments to used when the published
	// container runs.
	//
	// Note that Bass thunks don't actually use the default args themselves.
	DefaultArgs      []string `json:"default_args,omitempty"`
	ClearDefaultArgs bool     `json:"clear_default_args,omitempty"`
}

func MustThunk

func MustThunk(cmd Path, stdin ...Value) Thunk

func (Thunk) Addr added in v0.10.0

func (thunk Thunk) Addr(portName Symbol, format ...string) (ThunkAddr, error)

func (Thunk) AppendArgs added in v0.6.0

func (thunk Thunk) AppendArgs(args ...Value) Thunk

AppendArgs appends to the thunk's arg values.

func (Thunk) Avatar

func (wl Thunk) Avatar() (*invaders.Invader, error)

Avatar returns an ASCII art avatar derived from the thunk.

func (Thunk) CachePath added in v0.6.0

func (thunk Thunk) CachePath(ctx context.Context, dest string) (string, error)

func (Thunk) Call

func (combiner Thunk) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (Thunk) Cmdline

func (thunk Thunk) Cmdline() string

Cmdline returns a human-readable representation of the thunk's command and args.

func (Thunk) Decode

func (thunk Thunk) Decode(dest any) error

func (Thunk) Equal

func (thunk Thunk) Equal(other Value) bool

func (Thunk) Eval

func (value Thunk) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the thunk.

func (Thunk) Export added in v0.11.0

func (thunk Thunk) Export(ctx context.Context, w io.Writer) error

func (Thunk) Extend

func (thunk Thunk) Extend(sub Path) (Path, error)

Extend returns a path referring to the given path relative to the parent Path.

func (Thunk) Hash added in v0.7.0

func (thunk Thunk) Hash() (string, error)

Hash returns a stable, non-cryptographic hash derived from the thunk.

func (Thunk) HashKey added in v0.7.0

func (thunk Thunk) HashKey() (uint64, error)

func (Thunk) MarshalJSON added in v0.6.0

func (thunk Thunk) MarshalJSON() ([]byte, error)

func (Thunk) MarshalProto added in v0.6.0

func (value Thunk) MarshalProto() (proto.Message, error)

func (Thunk) Name

func (thunk Thunk) Name() string

Name returns the unqualified name for the path, i.e. the base name of a file or directory, or the name of a command.

func (Thunk) Open

func (thunk Thunk) Open(ctx context.Context) (io.ReadCloser, error)

func (*Thunk) Platform

func (thunk *Thunk) Platform() *Platform

func (Thunk) Proto added in v0.6.0

func (thunk Thunk) Proto() (*proto.Thunk, error)

func (Thunk) Publish added in v0.12.0

func (thunk Thunk) Publish(ctx context.Context, ref ImageRef) (ImageRef, error)

func (Thunk) Read added in v0.6.1

func (thunk Thunk) Read(ctx context.Context, w io.Writer) error

func (Thunk) Run added in v0.6.0

func (thunk Thunk) Run(ctx context.Context) error

func (Thunk) RunDir added in v0.12.0

func (thunk Thunk) RunDir() Path

func (Thunk) RunState added in v0.7.0

func (thunk Thunk) RunState(stdout io.Writer) RunState

func (Thunk) Start added in v0.6.0

func (thunk Thunk) Start(ctx context.Context, handler Combiner) (Combiner, error)

Start forks a goroutine that runs the thunk and calls handler with a boolean indicating whether it succeeded. It returns a combiner which waits for the thunk to finish and returns the result of the handler.

func (Thunk) String

func (thunk Thunk) String() string

func (*Thunk) UnmarshalJSON

func (thunk *Thunk) UnmarshalJSON(b []byte) error

func (*Thunk) UnmarshalProto added in v0.6.0

func (thunk *Thunk) UnmarshalProto(msg proto.Message) error

func (Thunk) Unwrap

func (combiner Thunk) Unwrap() Combiner

func (Thunk) WithArgs

func (thunk Thunk) WithArgs(args []Value) Thunk

WithArgs does different things depending on the length of the args slice:

If the args slice is empty, it sets the args.

If the args slice is not empty, it keeps the first value and replaces the remainder of the slice with the given values. This is useful for setting or replacing the arguments to a command, rather than replacing the command wholesale.

The goal is to support this:

(with-args (.go) ["test" "./..."])

Which should result in the following command:

go test ./...

Historically the command used to be a separate value, making the implementation straightforward. The advent of ENTRYPOINT and CMD support changed things a bit.

func (Thunk) WithCmd added in v0.4.0

func (thunk Thunk) WithCmd(args []Value) Thunk

WithCmd replaces a thunk's full command and arguments.

func (Thunk) WithDefaultArgs added in v0.12.0

func (thunk Thunk) WithDefaultArgs(args []string) Thunk

WithDefaultArgs sets the thunk's default arguments.

func (Thunk) WithDir

func (thunk Thunk) WithDir(dir ThunkDir) Thunk

WithDir sets the thunk's working directory.

func (Thunk) WithEntrypoint added in v0.12.0

func (thunk Thunk) WithEntrypoint(entrypoint []string) Thunk

WithEntrypoint sets the thunk's entrypoint.

func (Thunk) WithEntrypointArgs added in v0.12.0

func (thunk Thunk) WithEntrypointArgs(args []Value) Thunk

WithEntrypointArgs enables the entrypoint and provides args to it.

func (Thunk) WithEnv

func (thunk Thunk) WithEnv(env *Scope) Thunk

WithEnv sets the thunk's env, replacing any existing values.

func (Thunk) WithImage

func (thunk Thunk) WithImage(image ThunkImage) Thunk

WithImage sets the base image of the thunk, recursing into parent thunks until it reaches the bottom, like a rebase.

func (Thunk) WithInsecure

func (thunk Thunk) WithInsecure(insecure bool) Thunk

WithInsecure sets whether the thunk should be run insecurely.

func (Thunk) WithLabel

func (thunk Thunk) WithLabel(key Symbol, val Value) Thunk

WithLabel adds a label.

func (Thunk) WithMount

func (thunk Thunk) WithMount(src ThunkMountSource, tgt FileOrDirPath) Thunk

WithMount adds a mount.

func (Thunk) WithPort added in v0.10.0

func (thunk Thunk) WithPort(name Symbol, port int) Thunk

WithPorts sets the thunk's ports.

func (Thunk) WithStdin

func (thunk Thunk) WithStdin(stdin []Value) Thunk

WithStdin sets the thunk's stdin values.

func (Thunk) WithTLS added in v0.10.0

func (thunk Thunk) WithTLS(cert, key FilePath) Thunk

WithTLS configures the thunk with TLS.

type ThunkAddr added in v0.10.0

type ThunkAddr struct {
	Thunk  Thunk
	Port   string
	Format string
}

func (ThunkAddr) Decode added in v0.10.0

func (value ThunkAddr) Decode(dest any) error

func (ThunkAddr) Equal added in v0.10.0

func (value ThunkAddr) Equal(other Value) bool

func (ThunkAddr) Eval added in v0.10.0

func (value ThunkAddr) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (ThunkAddr) MarshalJSON added in v0.10.0

func (value ThunkAddr) MarshalJSON() ([]byte, error)

func (ThunkAddr) MarshalProto added in v0.10.0

func (value ThunkAddr) MarshalProto() (proto.Message, error)

func (ThunkAddr) Render added in v0.10.0

func (value ThunkAddr) Render(scope *Scope) (string, error)

func (ThunkAddr) String added in v0.10.0

func (value ThunkAddr) String() string

func (*ThunkAddr) UnmarshalJSON added in v0.10.0

func (value *ThunkAddr) UnmarshalJSON(b []byte) error

func (*ThunkAddr) UnmarshalProto added in v0.10.0

func (value *ThunkAddr) UnmarshalProto(msg proto.Message) error

type ThunkDir

type ThunkDir struct {
	Dir      *DirPath
	ThunkDir *ThunkPath
	HostDir  *HostPath
}

func (*ThunkDir) FromValue

func (path *ThunkDir) FromValue(val Value) error

func (ThunkDir) MarshalJSON

func (path ThunkDir) MarshalJSON() ([]byte, error)

func (ThunkDir) MarshalProto added in v0.6.0

func (dir ThunkDir) MarshalProto() (proto.Message, error)

func (ThunkDir) ToValue

func (path ThunkDir) ToValue() Value

func (*ThunkDir) UnmarshalJSON

func (path *ThunkDir) UnmarshalJSON(payload []byte) error

func (*ThunkDir) UnmarshalProto added in v0.6.0

func (dir *ThunkDir) UnmarshalProto(msg proto.Message) error

type ThunkImage

type ThunkImage struct {
	Ref         *ImageRef
	Archive     *ImageArchive
	Thunk       *Thunk
	DockerBuild *ImageDockerBuild
}

ThunkImage specifies the base image of a thunk - either a reference to be fetched, a thunk path (e.g. of a OCI/Docker tarball), or a lower thunk to run.

func (*ThunkImage) FromValue

func (image *ThunkImage) FromValue(val Value) error

func (ThunkImage) MarshalJSON

func (image ThunkImage) MarshalJSON() ([]byte, error)

func (ThunkImage) MarshalProto added in v0.6.0

func (img ThunkImage) MarshalProto() (proto.Message, error)

func (ThunkImage) Platform

func (img ThunkImage) Platform() *Platform

func (ThunkImage) ToValue

func (image ThunkImage) ToValue() Value

func (*ThunkImage) UnmarshalJSON

func (image *ThunkImage) UnmarshalJSON(payload []byte) error

func (*ThunkImage) UnmarshalProto added in v0.6.0

func (img *ThunkImage) UnmarshalProto(msg proto.Message) error

type ThunkMount

type ThunkMount struct {
	Source ThunkMountSource `json:"source"`
	Target FileOrDirPath    `json:"target"`
}

ThunkMount configures a mount for the thunk.

func (ThunkMount) MarshalProto added in v0.6.0

func (mount ThunkMount) MarshalProto() (proto.Message, error)

func (*ThunkMount) UnmarshalProto added in v0.6.0

func (mount *ThunkMount) UnmarshalProto(msg proto.Message) error

type ThunkMountSource

type ThunkMountSource struct {
	ThunkPath *ThunkPath
	HostPath  *HostPath
	FSPath    *FSPath
	Cache     *CachePath
	Secret    *Secret
}

func (*ThunkMountSource) FromValue

func (enum *ThunkMountSource) FromValue(val Value) error

func (ThunkMountSource) MarshalJSON

func (enum ThunkMountSource) MarshalJSON() ([]byte, error)

func (ThunkMountSource) MarshalProto added in v0.6.0

func (src ThunkMountSource) MarshalProto() (proto.Message, error)

func (ThunkMountSource) ToValue

func (enum ThunkMountSource) ToValue() Value

func (*ThunkMountSource) UnmarshalJSON

func (enum *ThunkMountSource) UnmarshalJSON(payload []byte) error

func (*ThunkMountSource) UnmarshalProto added in v0.6.0

func (mount *ThunkMountSource) UnmarshalProto(msg proto.Message) error

type ThunkOperative

type ThunkOperative struct {
	Cmd Value
}

ThunkOperative is an operative which constructs a Thunk.

func (ThunkOperative) Call

func (op ThunkOperative) Call(_ context.Context, args Value, _ *Scope, cont Cont) ReadyCont

Call constructs a thunk, passing arguments as values on stdin.

func (ThunkOperative) Decode

func (value ThunkOperative) Decode(dest any) error

func (ThunkOperative) Equal

func (value ThunkOperative) Equal(other Value) bool

func (ThunkOperative) Eval

func (value ThunkOperative) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

func (ThunkOperative) String

func (value ThunkOperative) String() string

type ThunkPath

type ThunkPath struct {
	Thunk Thunk         `json:"thunk"`
	Path  FileOrDirPath `json:"path"`
}

A path created by a thunk.

func (ThunkPath) CachePath added in v0.6.0

func (path ThunkPath) CachePath(ctx context.Context, dest string) (string, error)

func (ThunkPath) Call

func (combiner ThunkPath) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

func (ThunkPath) Decode

func (value ThunkPath) Decode(dest any) error

func (ThunkPath) Dir

func (path ThunkPath) Dir() ThunkPath

func (ThunkPath) Equal

func (value ThunkPath) Equal(other Value) bool

func (ThunkPath) Eval

func (value ThunkPath) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (ThunkPath) Excludes added in v0.12.0

func (value ThunkPath) Excludes() []string

func (ThunkPath) Extend

func (path ThunkPath) Extend(ext Path) (Path, error)

func (ThunkPath) Includes added in v0.12.0

func (value ThunkPath) Includes() []string

func (ThunkPath) MarshalJSON added in v0.6.0

func (value ThunkPath) MarshalJSON() ([]byte, error)

func (ThunkPath) MarshalProto added in v0.6.0

func (value ThunkPath) MarshalProto() (proto.Message, error)

func (ThunkPath) Name

func (path ThunkPath) Name() string

func (ThunkPath) Open

func (path ThunkPath) Open(ctx context.Context) (io.ReadCloser, error)

func (ThunkPath) String

func (value ThunkPath) String() string

func (*ThunkPath) UnmarshalJSON

func (value *ThunkPath) UnmarshalJSON(b []byte) error

func (*ThunkPath) UnmarshalProto added in v0.6.0

func (value *ThunkPath) UnmarshalProto(msg proto.Message) error

func (ThunkPath) Unwrap

func (app ThunkPath) Unwrap() Combiner

func (ThunkPath) WithExclude added in v0.12.0

func (value ThunkPath) WithExclude(paths ...string) Globbable

func (ThunkPath) WithInclude added in v0.12.0

func (value ThunkPath) WithInclude(paths ...string) Globbable

type ThunkPort added in v0.10.0

type ThunkPort struct {
	Name string `json:"name"`
	Port int    `json:"port"`
}

type ThunkTLS added in v0.10.0

type ThunkTLS struct {
	Cert FilePath `json:"cert"`
	Key  FilePath `json:"key"`
}

type Trace

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

func TraceFrom added in v0.3.0

func TraceFrom(ctx context.Context) (*Trace, bool)

func (*Trace) Caller

func (trace *Trace) Caller(offset int) *Annotate

func (*Trace) Frames

func (trace *Trace) Frames() []*Annotate

func (*Trace) IsEmpty

func (trace *Trace) IsEmpty() bool

func (*Trace) Pop

func (trace *Trace) Pop(n int)

func (*Trace) Record

func (trace *Trace) Record(frame *Annotate)

func (*Trace) Reset

func (trace *Trace) Reset()

type UnboundError

type UnboundError struct {
	Symbol Symbol
	Scope  *Scope
}

func (UnboundError) Error

func (err UnboundError) Error() string

func (UnboundError) NiceError added in v0.4.0

func (unbound UnboundError) NiceError(w io.Writer, outer error) error

type UnixTableProtocol

type UnixTableProtocol struct{}

UnixTableProtocol parses lines of tabular output with columns separated by whitespace.

Each row is not guaranteed to have the same number of columns. Empty lines correspond to empty arrays.

func (UnixTableProtocol) DecodeStream added in v0.11.0

func (proto UnixTableProtocol) DecodeStream(ctx context.Context, rc io.ReadCloser) (PipeSource, error)

DecodeInto decodes from r and emits lists of strings to the sink.

type UnknownProtocolError

type UnknownProtocolError struct {
	Protocol Symbol
}

UnknownProtocolError is returned when a thunk specifies an unknown response protocol.

func (UnknownProtocolError) Error

func (err UnknownProtocolError) Error() string

type Value

type Value interface {
	fmt.Stringer

	// Eval continues execution with a new value (or the same value, for consts).
	Eval(context.Context, *Scope, Cont) ReadyCont

	// Equal checks whether two values are equal, i.e. same type and equivalent
	// value.
	Equal(Value) bool

	// Decode coerces and assigns the Value into the given type, analogous to
	// unmarshaling.
	//
	// If the given type is a direct implementor of Value, it must only
	// successfully decode from another instance of that type.
	//
	// If the given type is a Go primitive, it must do its best to coerce into
	// that type. For example, null can Decode into bool, but not Bool.
	//
	// TODO: move this to Encodable/Decodable or something (or rename all this if
	// it's so confusing)
	Decode(any) error
}

Value represents any value used by Bass programs.

func EvalFSFile

func EvalFSFile(ctx context.Context, scope *Scope, source *FSPath) (Value, error)

func EvalFile

func EvalFile(ctx context.Context, scope *Scope, filePath string, source Readable) (Value, error)

func EvalReader

func EvalReader(ctx context.Context, e *Scope, r io.Reader, source Readable) (Value, error)

func EvalString

func EvalString(ctx context.Context, e *Scope, str string, source Readable) (Value, error)

func FromProto added in v0.6.0

func FromProto(val *proto.Value) (Value, error)

func Resolve

func Resolve(val Value, r func(Value) (Value, error)) (Value, error)

func ToSlice

func ToSlice(list List) ([]Value, error)

func Trampoline

func Trampoline(ctx context.Context, val Value) (Value, error)

func ValueOf

func ValueOf(src any) (Value, error)

func WithMeta

func WithMeta(val Value, metaVal Value) (Value, error)

type Wrapped

type Wrapped struct {
	Underlying Combiner
}

func (Wrapped) Call

func (combiner Wrapped) Call(ctx context.Context, val Value, scope *Scope, cont Cont) ReadyCont

Call evaluates the value in the scope and calls the underlying combiner with the result.

func (Wrapped) Decode

func (value Wrapped) Decode(dest any) error

func (Wrapped) Equal

func (value Wrapped) Equal(other Value) bool

func (Wrapped) Eval

func (value Wrapped) Eval(_ context.Context, _ *Scope, cont Cont) ReadyCont

Eval returns the value.

func (Wrapped) MarshalJSON

func (value Wrapped) MarshalJSON() ([]byte, error)

func (Wrapped) String

func (value Wrapped) String() string

func (Wrapped) Unwrap

func (app Wrapped) Unwrap() Combiner

type Writable added in v0.12.0

type Writable interface {
	Value

	// Open opens the resource for reading.
	Write(context.Context, io.Reader) error
}

Writable is any Value that can be the destination of (write).

type WriteFlusher

type WriteFlusher interface {
	io.Writer
	Flush() error
}

WriteFlusher is a flushable io.Writer, to support protocols which have to maintain an internal buffer.

Jump to

Keyboard shortcuts

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