Documentation
¶
Index ¶
- func Identifiers(str string) ([]string, error)
- func Interpolate(env Env, str string) (string, error)
- type EmptyValueExpansion
- type Env
- type EscapedExpansion
- type Expansion
- type Expression
- type ExpressionItem
- type Parser
- type RequiredExpansion
- type SubstringExpansion
- type UnsetValueExpansion
- type VariableExpansion
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Identifiers ¶
Indentifiers parses the identifiers from any expansions in the provided string
func Interpolate ¶
Interpolate takes a set of environment and interpolates it into the provided string using shell script expansions
Example ¶
package main import ( "fmt" "log" "github.com/buildkite/interpolate" ) func main() { env := interpolate.NewSliceEnv([]string{ "HELLO_WORLD=🦀", }) output, err := interpolate.Interpolate(env, "Buildkite... ${HELLO_WORLD} ${ANOTHER_VAR:-🏖}") if err != nil { log.Fatal(err) } fmt.Println(output) }
Output: Buildkite... 🦀 🏖
Types ¶
type EmptyValueExpansion ¶
type EmptyValueExpansion struct { Identifier string Content Expression }
EmptyValueExpansion returns either the value of an env, or a default value if it's unset or null
func (EmptyValueExpansion) Identifiers ¶
func (e EmptyValueExpansion) Identifiers() []string
type Env ¶
func NewSliceEnv ¶
Creates an Env from a slice of environment variables
type EscapedExpansion ¶
type EscapedExpansion struct { // PotentialIdentifier is an identifier for the purpose of Identifiers, // but not for the purpose of Expand. PotentialIdentifier string }
EscapedExpansion is an expansion that is delayed until later on (usually by a later process)
func (EscapedExpansion) Identifiers ¶
func (e EscapedExpansion) Identifiers() []string
type Expansion ¶
type Expansion interface { // Expand expands the expansion using variables from env. Expand(env Env) (string, error) // Identifiers returns any variable names referenced within the expansion. // Escaped expansions do something special and return identifiers // (starting with $) that *would* become referenced after a round of // unescaping. Identifiers() []string }
An expansion is something that takes in ENV and returns a string or an error
type Expression ¶
type Expression []ExpressionItem
Expression is a collection of either Text or Expansions
func (Expression) Identifiers ¶
func (e Expression) Identifiers() []string
type ExpressionItem ¶
ExpressionItem models either an Expansion or Text. Either/Or, never both.
func (ExpressionItem) String ¶
func (i ExpressionItem) String() string
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser takes a string and parses out a tree of structs that represent text and Expansions
func (*Parser) Parse ¶
func (p *Parser) Parse() (Expression, error)
Parse expansions out of the internal text and return them as a tree of Expressions
type RequiredExpansion ¶
type RequiredExpansion struct { Identifier string Message Expression }
RequiredExpansion returns an env value, or an error if it is unset
func (RequiredExpansion) Identifiers ¶
func (e RequiredExpansion) Identifiers() []string
type SubstringExpansion ¶
SubstringExpansion returns a substring (or slice) of the env
func (SubstringExpansion) Identifiers ¶
func (e SubstringExpansion) Identifiers() []string
type UnsetValueExpansion ¶
type UnsetValueExpansion struct { Identifier string Content Expression }
UnsetValueExpansion returns either the value of an env, or a default value if it's unset
func (UnsetValueExpansion) Identifiers ¶
func (e UnsetValueExpansion) Identifiers() []string
type VariableExpansion ¶
type VariableExpansion struct {
Identifier string
}
VariableExpansion represents either $VAR or ${VAR}, our simplest expansion
func (VariableExpansion) Identifiers ¶
func (e VariableExpansion) Identifiers() []string