Documentation ¶
Index ¶
- func AddEnv(envVars []string, key, value string) []string
- func ParseFlagArgs(args []string) ([]string, error)
- func ParseFlagArgsWithNonFlags(args []string) ([]string, []string, error)
- func ParseKeyValue(s string) (string, string, bool)
- func SetPlatformArgs(s *Scope, platr *platutil.Resolver)
- type Collection
- func (c *Collection) AbsRef() domain.Reference
- func (c *Collection) DeclareArg(name string, defaultValue string, global bool, ...) (string, string, error)
- func (c *Collection) DeclareEnv(name string, value string)
- func (c *Collection) EnterFrame(frameName string, absRef domain.Reference, overriding *Scope, globals *Scope, ...)
- func (c *Collection) EnvVars() *Scope
- func (c *Collection) ExitFrame()
- func (c *Collection) Expand(word string, shellOut shell.EvalShellOutFn) (string, error)
- func (c *Collection) ExpandOld(word string) string
- func (c *Collection) GetActive(name string) (string, bool)
- func (c *Collection) Globals() *Scope
- func (c *Collection) Imports() *domain.ImportTracker
- func (c *Collection) IsStackAtBase() bool
- func (c *Collection) Overriding() *Scope
- func (c *Collection) ResetEnvVars(envs *Scope)
- func (c *Collection) SetArg(name string, value string)
- func (c *Collection) SetGlobals(globals *Scope)
- func (c *Collection) SetOverriding(overriding *Scope)
- func (c *Collection) SetPlatform(platr *platutil.Resolver)
- func (c *Collection) SortedActiveVariables() []string
- func (c *Collection) SortedOverridingVariables() []string
- func (c *Collection) StackString() string
- func (c *Collection) UnsetArg(name string)
- type DefaultArgs
- type NewCollectionOpt
- type ProcessNonConstantVariableFunc
- type Scope
- func BuiltinArgs(target domain.Target, platr *platutil.Resolver, gitMeta *gitutil.GitMetadata, ...) *Scope
- func CombineScopes(scopes ...*Scope) *Scope
- func NewScope() *Scope
- func ParseArgs(args []string, pncvf ProcessNonConstantVariableFunc, current *Collection) (*Scope, error)
- func ParseCommandLineArgs(args []string) (*Scope, error)
- func ParseEnvVars(envVars []string) *Scope
- func (s *Scope) ActiveValueMap() map[string]string
- func (s *Scope) AddActive(name string, variable string)
- func (s *Scope) AddInactive(name string, variable string)
- func (s *Scope) AllValueMap() map[string]string
- func (s *Scope) Clone() *Scope
- func (s *Scope) GetActive(name string) (string, bool)
- func (s *Scope) GetAny(name string) (string, bool)
- func (s *Scope) Remove(name string)
- func (s *Scope) SortedActive() []string
- func (s *Scope) SortedAny() []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddEnv ¶
AddEnv takes in a slice of env vars in key-value format and a new key-value string to it, taking care of possible overrides.
func ParseFlagArgs ¶ added in v0.6.15
ParseFlagArgs parses flag-form args. These can be represented as `--arg=value` or `--arg value`. The result is a slice that can be passed in to ParseArgs or to ParseCommandLineArgs.
func ParseFlagArgsWithNonFlags ¶ added in v0.6.15
ParseFlagArgsWithNonFlags parses flag-form args together with any possible optional additional args. e.g. "--flag1=value arg1 --flag2=value --flag3=value arg2 arg3".
func ParseKeyValue ¶
ParseKeyValue pases a key-value type into its parts if a key value needs to contain a = or \, it must be escapped using '\=', and '\\' respectively once an unescaped '=' is found, all remaining chars will be used as-is without the need to be escaped. the key and value are returned, along with a bool that is true if a value was defined (i.e. an equal was found)
e.g. ParseKeyValue("foo") -> `foo`, “, false
ParseKeyValue("foo=") -> `foo`, ``, true ParseKeyValue("foo=bar") -> `foo`, `bar`, true ParseKeyValue(`f\=oo=bar`) -> `f=oo`, `bar`, true ParseKeyValue(`foo=bar=`) -> `foo", `bar=`, true ParseKeyValue(`foo=bar\=`) -> `foo", `bar\=`, true
func SetPlatformArgs ¶ added in v0.6.15
SetPlatformArgs sets the platform-specific built-in args to a specific platform.
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection is a collection of variable scopes used within a single target.
func NewCollection ¶
func NewCollection(opts NewCollectionOpt) *Collection
NewCollection creates a new Collection to be used in the context of a target.
func (*Collection) AbsRef ¶ added in v0.6.15
func (c *Collection) AbsRef() domain.Reference
AbsRef returns a ref that any other reference should be relative to as part of the stack frame.
func (*Collection) DeclareArg ¶ added in v0.6.15
func (c *Collection) DeclareArg(name string, defaultValue string, global bool, pncvf ProcessNonConstantVariableFunc) (string, string, error)
DeclareArg declares an arg. The effective value may be different than the default, if the variable has been overridden.
func (*Collection) DeclareEnv ¶ added in v0.6.15
func (c *Collection) DeclareEnv(name string, value string)
DeclareEnv declares an env var.
func (*Collection) EnterFrame ¶ added in v0.6.15
func (c *Collection) EnterFrame(frameName string, absRef domain.Reference, overriding *Scope, globals *Scope, globalImports map[string]domain.ImportTrackerVal)
EnterFrame creates a new stack frame.
func (*Collection) EnvVars ¶ added in v0.6.15
func (c *Collection) EnvVars() *Scope
EnvVars returns a copy of the env vars.
func (*Collection) ExitFrame ¶ added in v0.6.15
func (c *Collection) ExitFrame()
ExitFrame exits the latest stack frame.
func (*Collection) Expand ¶
func (c *Collection) Expand(word string, shellOut shell.EvalShellOutFn) (string, error)
Expand expands variables within the given word.
func (*Collection) ExpandOld ¶ added in v0.6.15
func (c *Collection) ExpandOld(word string) string
ExpandOld expands variables within the given word, it does not peform shelling-out. it will eventually be removed when the ShellOutAnywhere feature is fully-adopted
func (*Collection) GetActive ¶ added in v0.6.15
func (c *Collection) GetActive(name string) (string, bool)
GetActive returns an active variable by name.
func (*Collection) Globals ¶ added in v0.6.15
func (c *Collection) Globals() *Scope
Globals returns a copy of the globals.
func (*Collection) Imports ¶ added in v0.6.15
func (c *Collection) Imports() *domain.ImportTracker
Imports returns the imports tracker of the current frame.
func (*Collection) IsStackAtBase ¶ added in v0.6.15
func (c *Collection) IsStackAtBase() bool
IsStackAtBase returns whether the stack has size 1.
func (*Collection) Overriding ¶ added in v0.6.15
func (c *Collection) Overriding() *Scope
Overriding returns a copy of the overriding args.
func (*Collection) ResetEnvVars ¶ added in v0.6.15
func (c *Collection) ResetEnvVars(envs *Scope)
ResetEnvVars resets the collection's env vars.
func (*Collection) SetArg ¶ added in v0.6.15
func (c *Collection) SetArg(name string, value string)
SetArg sets the value of an arg.
func (*Collection) SetGlobals ¶ added in v0.6.15
func (c *Collection) SetGlobals(globals *Scope)
SetGlobals sets the global variables.
func (*Collection) SetOverriding ¶ added in v0.6.15
func (c *Collection) SetOverriding(overriding *Scope)
SetOverriding sets the overriding args.
func (*Collection) SetPlatform ¶ added in v0.6.15
func (c *Collection) SetPlatform(platr *platutil.Resolver)
SetPlatform sets the platform, updating the builtin args.
func (*Collection) SortedActiveVariables ¶
func (c *Collection) SortedActiveVariables() []string
SortedActiveVariables returns the active variable names in a sorted slice.
func (*Collection) SortedOverridingVariables ¶
func (c *Collection) SortedOverridingVariables() []string
SortedOverridingVariables returns the overriding variable names in a sorted slice.
func (*Collection) StackString ¶ added in v0.6.15
func (c *Collection) StackString() string
StackString returns the stack as a string.
func (*Collection) UnsetArg ¶ added in v0.6.15
func (c *Collection) UnsetArg(name string)
UnsetArg removes an arg if it exists.
type DefaultArgs ¶ added in v0.6.15
DefaultArgs contains additional builtin ARG values which need to be passed in from outside of the scope of this package.
type NewCollectionOpt ¶ added in v0.6.15
type NewCollectionOpt struct { Console conslogging.ConsoleLogger Target domain.Target PlatformResolver *platutil.Resolver NativePlatform specs.Platform GitMeta *gitutil.GitMetadata BuiltinArgs DefaultArgs OverridingVars *Scope Features *features.Features GlobalImports map[string]domain.ImportTrackerVal }
NewCollectionOpt contains supported arguments which the `NewCollection` function may accept.
type ProcessNonConstantVariableFunc ¶
type ProcessNonConstantVariableFunc func(name string, expression string) (value string, argIndex int, err error)
ProcessNonConstantVariableFunc is a function which takes in an expression and turns it into a state, target intput and arg index.
type Scope ¶ added in v0.6.15
type Scope struct {
// contains filtered or unexported fields
}
Scope represents a variable scope.
func BuiltinArgs ¶ added in v0.6.15
func BuiltinArgs(target domain.Target, platr *platutil.Resolver, gitMeta *gitutil.GitMetadata, defaultArgs DefaultArgs, ftrs *features.Features) *Scope
BuiltinArgs returns a scope containing the builtin args.
func CombineScopes ¶ added in v0.6.15
CombineScopes combines all the variables across all scopes, with left precedence.
func ParseArgs ¶ added in v0.6.15
func ParseArgs(args []string, pncvf ProcessNonConstantVariableFunc, current *Collection) (*Scope, error)
ParseArgs parses args passed as --build-arg to an Earthly command, such as BUILD or FROM.
func ParseCommandLineArgs ¶ added in v0.6.15
ParseCommandLineArgs parses a slice of old build args (the ones passed via --build-arg) and returns a new scope.
func ParseEnvVars ¶ added in v0.6.15
ParseEnvVars parses env vars from a slice of strings of the form "key=value".
func (*Scope) ActiveValueMap ¶ added in v0.6.15
ActiveValueMap returns a map of the values of the active variables.
func (*Scope) AddActive ¶ added in v0.6.15
AddActive adds and activates a variable in the collection.
func (*Scope) AddInactive ¶ added in v0.6.15
AddInactive adds an inactive variable in the collection.
func (*Scope) AllValueMap ¶ added in v0.6.15
AllValueMap returns a map of the values of all the variables.
func (*Scope) GetAny ¶ added in v0.6.15
GetAny returns a variable by name, even if it is not active.
func (*Scope) SortedActive ¶ added in v0.6.15
SortedActive returns the active variable names in a sorted slice.