Documentation
¶
Overview ¶
Package execs provides utilities for executing external commands, as defined by configuration.
It is primarily designed to be implemented by the `profile` package, and provides a standard implementation for the main profile command as well as any hooks and/or plugins.
Index ¶
- Variables
- type CallerRef
- type Command
- func (e *Command) AddEnvFrom(envFrom []EnvFromSource)
- func (e *Command) AddEnvVar(envVar EnvVar)
- func (e *Command) CompilePatterns() error
- func (e *Command) Exec(ctx context.Context, dir string) (*Result, error)
- func (e *Command) ExecWithStdin(ctx context.Context, dir string, stdin []byte) (*Result, error)
- func (e *Command) GetEnv() []string
- func (e *Command) SetBaseEnv(baseEnv []string)
- func (e *Command) String() string
- type EnvFromSource
- type EnvVar
- type EnvVarSource
- type Result
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCommandExecution is returned when command execution fails. ErrCommandExecution = errors.New("command execution") // ErrEmptyCommand is returned when a command is empty. ErrEmptyCommand = errors.New("empty command") )
Functions ¶
This section is empty.
Types ¶
type CallerRef ¶
type CallerRef struct {
// Pattern is a regex pattern for matching environment variable names.
Pattern string `json:"pattern,omitempty" jsonschema:"title=Pattern,format=regex"`
// Name is the specific environment variable name to inherit.
Name string `json:"name,omitempty" jsonschema:"title=Name"`
// contains filtered or unexported fields
}
CallerRef represents a reference to environment variables from the caller process.
type Command ¶
type Command struct {
// Command is the command to execute.
Command string `json:"command" jsonschema:"title=Command,pattern=^\\S+$"`
// Args contains the command line arguments.
Args []string `json:"args,omitempty" jsonschema:"title=Arguments" yaml:"args,flow,omitempty"`
// Env contains environment variable definitions.
Env []EnvVar `json:"env,omitempty" jsonschema:"title=Environment Variables"`
// EnvFrom contains sources for inheriting environment variables.
EnvFrom []EnvFromSource `json:"envFrom,omitempty" jsonschema:"title=Environment Variables From"`
// contains filtered or unexported fields
}
Command manages common command execution properties.
func NewCommand ¶
NewCommand creates a new Command. It accepts a base environment, which usually will be from os.Environ.
func (*Command) AddEnvFrom ¶
func (e *Command) AddEnvFrom(envFrom []EnvFromSource)
AddEnvFrom adds environment variable sources.
func (*Command) CompilePatterns ¶
CompilePatterns compiles all regex patterns.
func (*Command) ExecWithStdin ¶
func (*Command) SetBaseEnv ¶
type EnvFromSource ¶
type EnvFromSource struct {
// CallerRef specifies how to inherit environment variables from the caller process.
CallerRef *CallerRef `json:"callerRef,omitempty" jsonschema:"title=Caller Reference"`
}
EnvFromSource represents a source for inheriting environment variables.
type EnvVar ¶
type EnvVar struct {
// ValueFrom specifies a source for the environment variable value.
ValueFrom *EnvVarSource `json:"valueFrom,omitempty" jsonschema:"title=Value From"`
// Name is the environment variable name.
Name string `json:"name" jsonschema:"title=Name"`
// Value is the environment variable value.
Value string `json:"value,omitempty" jsonschema:"title=Value"`
}
EnvVar represents an environment variable definition.
type EnvVarSource ¶
type EnvVarSource struct {
// CallerRef specifies how to get the value from the caller process environment.
CallerRef *CallerRef `json:"callerRef,omitempty" jsonschema:"title=Caller Reference"`
}
EnvVarSource represents a source for an environment variable value.