vars

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Variables

type Variables struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Variables stores a variable map that used for variable expansion in parsed commands and other parsed strings.

func New

func New() *Variables

New construction function to create a new Variables

func (*Variables) Envs

func (v *Variables) Envs(variables ...string) *Variables

Envs declares process environment variables with support for variable expansion. Each variable must use the form:

<key-name>=<value>

With no space between key name, equal sign, and value, i.e. Envs(`GOOS=linux`, `GOARCH=amd64`, `INFO="OS: ${GOOS}, ARC: ${GOARCH}"`)

func (*Variables) Err

func (v *Variables) Err() error

Err surfaces Variables error

func (*Variables) Eval

func (v *Variables) Eval(str string) string

Eval returns the string str with its content expanded with variable references i.e. Eval("I am $HOME") returns "I am </user/home/path>"

func (*Variables) ExpandVar

func (v *Variables) ExpandVar(str string, expandFunc func(string) string) string

ExpandVar searches str for $value or ${value} which is then evaluated using os.ExpandEnv. If variable starts with <escapeChar>$, the expansion sequence will be ignored. For instance if the escapeChar is '\', when \$value or \${value} is encountered, the variable expansion is ignored leaving the original values in the string as $value or ${value}.

func (*Variables) SetEnv

func (v *Variables) SetEnv(key, value string) *Variables

SetEnv sets an environment variable key with value.

func (*Variables) SetVar

func (v *Variables) SetVar(name, value string) *Variables

SetVar declares a gexe session variable.

func (*Variables) UnsetVar added in v0.3.0

func (v *Variables) UnsetVar(name string) *Variables

UnsetVar removes a previously set gexe session variable.

func (*Variables) Val

func (v *Variables) Val(key string) string

Val searches for a gexe session variable with provided key, if not found searches for an environment variable with that key.

func (*Variables) Vars

func (v *Variables) Vars(variables ...string) *Variables

Vars declares gexe session variables with support for variable expansion. Each variable must use the form:

<key-name>=<value>

With no space between key name, equal sign, and value, i.e. Vars(`foo=bar`, `fuzz=${foo}`, `dazz="this is ${fuzz}"`)

func (*Variables) WithEscapeChar

func (v *Variables) WithEscapeChar(r rune) *Variables

WithEscapeChar sets the espacape char for the variable

Jump to

Keyboard shortcuts

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