core

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2020 License: LGPL-2.1 Imports: 16 Imported by: 1

Documentation

Overview

This package provides default implementations of commands that can be used when creating modules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Commands

type Commands struct {
	utils.Module
	// contains filtered or unexported fields
}

func New

func New(env utils.Runtime) *Commands

func (*Commands) Env

func (self *Commands) Env(name string, args *EnvArgs) (interface{}, error)

Retrieves a system environment variable and returns the value of it, or a fallback value if the variable does not exist or (optionally) is empty.

#### Examples

##### Get the value of the `USER` environment variable and store it ``` env 'USER' -> $user ```

##### Require the `LANG`, `USER`, and `CI` environment variables; and fail they are not set. ``` env 'LANG' { required: true } env 'USER' { required: true } env 'CI' { required: true } ```

func (*Commands) Fail

func (self *Commands) Fail(message string) error

Immediately exit the script in an error-like fashion with a specific message.

func (*Commands) Log

func (self *Commands) Log(message interface{}) error

Outputs a line to the log.

func (*Commands) Put

func (self *Commands) Put(value interface{}) (interface{}, error)

Store a value in the current scope. Strings will be automatically converted into the appropriate data types (float, int, bool) if possible.

func (*Commands) Run

func (self *Commands) Run(filename string, args *RunArgs) (interface{}, error)

Evaluates another Friendscript loaded from another file. The filename is the absolute path or basename of the file to search for in the FRIENDSCRIPT_PATH environment variable to load and evaluate. The FRIENDSCRIPT_PATH variable behaves like the the traditional *nix PATH variable, wherein multiple paths can be specified as a colon-separated (:) list. The directory of the calling script (if available) will always be checked first.

Returns: The value of the variable named by result_key at the end of the evaluated script's execution.

func (*Commands) Wait

func (self *Commands) Wait(delay interface{}) error

Pauses execution of the current script for the given duration.

type EnvArgs

type EnvArgs struct {
	// The value to return if the environment variable does not exist, or
	// (optionally) is empty.
	Fallback interface{} `json:"fallback"`

	// Whether empty values should be ignored or not.
	Required bool `json:"required" default:"false"`

	// Whether automatic type detection should be performed or not.
	DetectType bool `json:"detect_type" default:"true"`

	// If specified, this string will be used to split matching values into a
	// list of values. This is useful for environment variables that contain
	// multiple values joined by a separator (e.g: the PATH variable.)
	Joiner string `json:"joiner"`
}

type RunArgs

type RunArgs struct {

	// Specifies a key in the scope of the evaluate script that will be used as the result value of this command.
	ResultKey string `json:"result_key"` // result

	// Provides a set of initial variables to the script.
	Data map[string]interface{} `json:"data"` // null

	// If true, the scope of the running script will not be able to modify data in the parent scope.
	Isolated bool `json:"isolated" default:"true"`
}

Jump to

Keyboard shortcuts

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