script

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const EntryPoint = "main"

EntryPoint defines the name of the method that will be called when running a script (if it exists) in addition to executing top level statements.

Variables

View Source
var (
	// ErrMalformattedKwarg occurs when a keyword argument passed to a starlark function is malformatted.
	ErrMalformattedKwarg = errors.New("malformatted keyword argument for method call")

	// ErrMissingKwarg occurs when a keyword argument is missing from a starlark function call.
	ErrMissingKwarg = errors.New("missing keyword argument for method call")

	// ErrMissingArg occurs when an argument is missing from a starlark function call.
	ErrMissingArg = errors.New("missing argument for method call")

	// ErrInvalidArgType occurs when an argument provided to a starlark function call has the wrong type.
	ErrInvalidArgType = errors.New("invalid argument type provided to method")

	// ErrMissingLibrary occurs when attempting to load a library that doesn't exist.
	ErrMissingLibrary = errors.New("could not find library to load")

	// ErrInvalidTypeConversion occurs when converting a golang type to a starlark.Value fails.
	ErrInvalidTypeConversion = errors.New("could not convert golang value to starlark.Value")

	// ErrInvalidKwarg occurs when a user incorrectly passes a kwarg to a starlark function
	ErrInvalidKwarg = errors.New("invalid kwarg was passed to the method")
)

Functions

func ConvertToStarlark added in v0.4.0

func ConvertToStarlark(value interface{}) (starlark.Value, error)

ConvertToStarlark provides an exported function for converting starlark values

Types

type ArgParser

type ArgParser interface {
	RestrictKwargs(kwargs ...string) error

	GetParam(index int) (starlark.Value, error)

	GetString(index int) (string, error)
	GetStringByName(name string) (string, error)

	GetInt(index int) (int64, error)
	GetIntByName(name string) (int64, error)

	GetBool(index int) (bool, error)
	GetBoolByName(kwarg string) (bool, error)
}

An ArgParser enables golang function implementations to retrieve the positional and keyword arguments provided to the starlark method call.

type Environment added in v0.3.0

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

An Environment enables script libraries to receive dependencies via dependency injection and register hooks for cleanup after execution.

func (*Environment) Close added in v0.3.0

func (env *Environment) Close() (err error)

Close all handles opened by the environment.

func (*Environment) TrackHandle added in v0.3.0

func (env *Environment) TrackHandle(handle io.Closer)

TrackHandle ensures that the provided handle is closed after script execution.

type Func

type Func func(args ArgParser) (Retval, error)

Func provides a simple wrapper that enables a golang function to be exposed to starlark.

type Library

type Library map[string]Func

Library is a map of identifiers to underlying golang function implementations.

func (Library) Attr added in v0.3.0

func (lib Library) Attr(name string) (starlark.Value, error)

Attr enables dot expressions and returns the starlark method with the provided name if it exists.

func (Library) AttrNames added in v0.3.0

func (lib Library) AttrNames() []string

AttrNames returns the set of methods provided by the library.

func (Library) Freeze added in v0.3.0

func (lib Library) Freeze()

Freeze is a no-op since library methods are expected to be safe for concurrent use.

func (Library) Hash added in v0.3.0

func (lib Library) Hash() (uint32, error)

Hash will error since the library type is not intended to be hashable.

func (Library) String added in v0.3.0

func (lib Library) String() string

String returns a description of the library, used to implement starlark.value

func (Library) Truth added in v0.3.0

func (lib Library) Truth() starlark.Bool

Truth value of a library is True if it is non-empty

func (Library) Type added in v0.3.0

func (lib Library) Type() string

Type returns 'library' to indicate the type of the library within starlark.

type Option

type Option func(*Script)

An Option enables additional customization of script configuration and execution.

func WithLibraries

func WithLibraries(libs map[string]Library) Option

WithLibraries adds one or more libraries to the script's execution environment.

func WithLibrary

func WithLibrary(name string, lib Library) Option

WithLibrary is an option to add a library to the script's execution environment.

func WithOutput

func WithOutput(w io.Writer) Option

WithOutput sets the destination for script execution output.

type Retval

type Retval interface{}

Retval TODO

func WithError added in v0.3.0

func WithError(val Retval, err error) Retval

type Script

type Script struct {
	io.Reader // Read() instructions to execute
	io.Writer // Write() execution output
	ID        string
	Builtins  map[string]Func
	Libraries map[string]Library
	// contains filtered or unexported fields
}

A Script provides metadata and instructions to be executed by the interpreter.

func New

func New(id string, content io.Reader, options ...Option) *Script

New initializes and returns a script with the provided contents.

func (*Script) Call added in v0.4.0

func (script *Script) Call(funcName string, args starlark.Tuple, kwargs ...starlark.Tuple) (starlark.Value, error)

Call a function defined by the script. This will execute all top level statements before calling the function.

func (*Script) Exec

func (script *Script) Exec(ctx context.Context) error

Exec calls the entrypoint method of a script

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
stdlib
assets
Package assets provides functionality to load asset files that were packed into the binary during compilation.
Package assets provides functionality to load asset files that were packed into the binary during compilation.
cdn
env
file
Package file provides the standard file library used to perform common file operations.
Package file provides the standard file library used to perform common file operations.
net
ssh
Package ssh provides functionality to execute commands on remote targets using SSH.
Package ssh provides functionality to execute commands on remote targets using SSH.
sys

Jump to

Keyboard shortcuts

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