Documentation ¶
Index ¶
- Variables
- 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 SetLocally(s *Scope, locally bool)
- func SetPlatformArgs(s *Scope, platr *platutil.Resolver)
- type Collection
- func (c *Collection) AbsRef() domain.Reference
- func (c *Collection) Args() *Scope
- func (c *Collection) DeclareEnv(name string, value string)
- func (c *Collection) DeclareVar(name string, opts ...DeclareOpt) (string, string, error)
- 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) Get(name string, opts ...ScopeOpt) (string, bool)
- func (c *Collection) Globals() *Scope
- func (c *Collection) Imports() *domain.ImportTracker
- func (c *Collection) IsStackAtBase() bool
- func (c *Collection) Org() string
- func (c *Collection) Overriding() *Scope
- func (c *Collection) Project() string
- func (c *Collection) ResetEnvVars(envs *Scope)
- func (c *Collection) SetArg(name string, value string)
- func (c *Collection) SetGlobals(globals *Scope)
- func (c *Collection) SetLocally(locally bool)
- func (c *Collection) SetOrg(org string)
- func (c *Collection) SetOverriding(overriding *Scope)
- func (c *Collection) SetPlatform(platr *platutil.Resolver)
- func (c *Collection) SetProject(project string)
- func (c *Collection) SortedOverridingVariables() []string
- func (c *Collection) SortedVariables(opts ...ScopeOpt) []string
- func (c *Collection) StackString() string
- func (c *Collection) TopOverriding() *Scope
- func (c *Collection) UnsetArg(name string)
- func (c *Collection) UpdateVar(name, value string, pncvf ProcessNonConstantVariableFunc) (retErr error)
- type DeclareOpt
- 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 CombineScopesInactive(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 RemoveReservedArgsFromScope(scope *Scope) *Scope
- func (s *Scope) Add(name, value string, opts ...ScopeOpt) bool
- func (s *Scope) BuildArgs(opts ...ScopeOpt) []string
- func (s *Scope) Clone() *Scope
- func (s *Scope) DebugString() string
- func (s *Scope) Get(name string, opts ...ScopeOpt) (string, bool)
- func (s *Scope) Map(opts ...ScopeOpt) map[string]string
- func (s *Scope) Remove(name string)
- func (s *Scope) Sorted(opts ...ScopeOpt) []string
- type ScopeOpt
Constants ¶
This section is empty.
Variables ¶
var ( ErrRedeclared = errors.New("this variable was declared twice in the same target") ErrVarNotFound = errors.New("no matching variable found in this scope") ErrInvalidScope = errors.New("this action is not allowed in this scope") ErrSetArg = errors.New("ARG values cannot be reassigned") ShellOutEnvs = map[string]struct{}{ "HOME": {}, "PATH": {}, } )
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 into 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 escaped 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 SetLocally ¶ added in v0.6.30
SetLocally sets the locally built-in arg value
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) Args ¶ added in v0.8.0
func (c *Collection) Args() *Scope
Args returns a copy of the args.
func (*Collection) DeclareEnv ¶ added in v0.6.15
func (c *Collection) DeclareEnv(name string, value string)
DeclareEnv declares an env var.
func (*Collection) DeclareVar ¶ added in v0.7.3
func (c *Collection) DeclareVar(name string, opts ...DeclareOpt) (string, string, error)
DeclareVar declares a variable. The effective value may be different than the default, if the variable has been overridden.
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 perform shelling-out. it will eventually be removed when the ShellOutAnywhere feature is fully-adopted
func (*Collection) Get ¶
func (c *Collection) Get(name string, opts ...ScopeOpt) (string, bool)
Get returns a 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) Org ¶ added in v0.6.21
func (c *Collection) Org() string
Org returns the organization name.
func (*Collection) Overriding ¶ added in v0.6.15
func (c *Collection) Overriding() *Scope
Overriding returns a copy of the overriding args.
func (*Collection) Project ¶ added in v0.6.21
func (c *Collection) Project() string
Project returns the project name.
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) SetLocally ¶ added in v0.6.30
func (c *Collection) SetLocally(locally bool)
SetLocally sets the locally flag, updating the builtin args.
func (*Collection) SetOrg ¶ added in v0.6.21
func (c *Collection) SetOrg(org string)
SetOrg sets the organization name.
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) SetProject ¶ added in v0.6.21
func (c *Collection) SetProject(project string)
SetProject sets the project name.
func (*Collection) SortedOverridingVariables ¶
func (c *Collection) SortedOverridingVariables() []string
SortedOverridingVariables returns the overriding variable names in a sorted slice.
func (*Collection) SortedVariables ¶ added in v0.7.3
func (c *Collection) SortedVariables(opts ...ScopeOpt) []string
SortedVariables returns the current 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) TopOverriding ¶ added in v0.7.5
func (c *Collection) TopOverriding() *Scope
TopOverriding returns a copy of the top-level overriding args, for use in commands that may need to re-parse the base target but have drastically different variable scopes.
func (*Collection) UnsetArg ¶ added in v0.6.15
func (c *Collection) UnsetArg(name string)
UnsetArg removes an arg if it exists.
func (*Collection) UpdateVar ¶ added in v0.7.3
func (c *Collection) UpdateVar(name, value string, pncvf ProcessNonConstantVariableFunc) (retErr error)
UpdateVar updates the value of an existing variable. It will override the value of the variable, regardless of where the value was previously defined.
It returns ErrVarNotFound if the variable was not found.
type DeclareOpt ¶ added in v0.7.3
type DeclareOpt func(declarePrefs) declarePrefs
DeclareOpt is an option function for declaring variables.
func AsArg ¶ added in v0.7.3
func AsArg() DeclareOpt
AsArg is an option function to declare an argument.
func AsGlobal ¶ added in v0.7.3
func AsGlobal() DeclareOpt
AsGlobal is an option function to declare a global variable.
func WithPNCVFunc ¶ added in v0.7.3
func WithPNCVFunc(f ProcessNonConstantVariableFunc) DeclareOpt
WithPNCVFunc is an option function to apply a ProcessNonConstantVariableFunc to ARGs. This supports deprecated functionality and is never used in Earthfiles with `VERSION 0.7` and higher.
func WithValue ¶ added in v0.7.3
func WithValue(val string) DeclareOpt
WithValue is an option function for setting a variable's value. For ARGs, this is only the default value - it can be overridden when calling a target at the CLI.
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 Push bool CI bool EarthlyCIRunner bool PlatformResolver *platutil.Resolver NativePlatform specs.Platform GitMeta *gitutil.GitMetadata BuiltinArgs DefaultArgs OverridingVars *Scope AssignedVars *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, push bool, ci bool, earthlyCIRunner bool) *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 the following precedence:
1. Active variables 2. Inactive variables 3. All other things equal, left-most scopes have precedence
func CombineScopesInactive ¶ added in v0.8.0
CombineScopesInactive combines all scopes (leaving all variables inactive), with left-most scope having 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 RemoveReservedArgsFromScope ¶ added in v0.8.5
RemoveReservedArgsFromScope returns a new scope ommits any builtin arguments
func (*Scope) Add ¶ added in v0.7.3
Add sets a variable to a value within this scope. It returns true if the value was set.
func (*Scope) BuildArgs ¶ added in v0.7.5
BuildArgs returns s as a slice of build args, as they would have been passed in originally at the CLI or in a BUILD command.
func (*Scope) DebugString ¶ added in v0.8.0
DebugString returns a string that can be printed while debugging
func (*Scope) Map ¶ added in v0.7.3
Map returns a name->value variable map of variables in this scope.
type ScopeOpt ¶ added in v0.7.3
type ScopeOpt func(scopeOpts) scopeOpts
ScopeOpt is an option function for setting flags when adding to or getting from a Scope.
func NoOverride ¶ added in v0.7.3
func NoOverride() ScopeOpt
NoOverride only applies to Add. When passed to Add, NoOverride will prevent Add from overriding an existing value.
This will also prevent Add from applying other opts to the existing variable, so if the caller wishes to set options on the existing value, they should update the value on a false return from Add.
func WithActive ¶ added in v0.7.3
func WithActive() ScopeOpt
WithActive is a ScopeOpt for active variables. When passed to Add, it sets the variable to active; when passed to Get or Map, it causes them to only return active variables.