execs

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	// ErrCommandExecution is returned when command execution fails.
	ErrCommandExecution = errors.New("run")

	// 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.

func (*CallerRef) Compile

func (c *CallerRef) Compile() error

Compile compiles the caller reference pattern into a regex if a pattern is provided.

type Command

type Command struct {

	// Command is the command to execute.
	Command string `json:"command" jsonschema:"title=Command,pattern=^\\S+$"`
	// Args contains the immutable 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

func NewCommand(baseEnv []string) Command

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) AddEnvVar

func (e *Command) AddEnvVar(envVar EnvVar)

AddEnvVar adds a single environment variable.

func (*Command) CompilePatterns

func (e *Command) CompilePatterns() error

CompilePatterns compiles all regex patterns.

func (*Command) GetEnv

func (e *Command) GetEnv() []string

GetEnv constructs environment variables for command execution.

func (*Command) SetBaseEnv

func (e *Command) SetBaseEnv(baseEnv []string)

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.

type Executor added in v0.24.1

type Executor struct {
	// contains filtered or unexported fields
}

func NewExecutor added in v0.24.1

func NewExecutor(cmd Command, args ...string) Executor

func (Executor) Exec added in v0.24.1

func (e Executor) Exec(ctx context.Context, dir string) (*Result, error)

func (Executor) ExecWithStdin added in v0.24.1

func (e Executor) ExecWithStdin(ctx context.Context, dir string, stdin []byte) (*Result, error)

func (Executor) String added in v0.24.1

func (e Executor) String() string

type LazyRegexp added in v0.26.0

type LazyRegexp struct {
	// contains filtered or unexported fields
}

LazyRegexp provides thread-safe lazy compilation of a regular expression. The pattern is compiled at most once, even when accessed concurrently.

func NewLazyRegexp added in v0.26.0

func NewLazyRegexp(pattern string) *LazyRegexp

NewLazyRegexp creates a new LazyRegexp that will compile the given pattern when Get() is first called.

func (*LazyRegexp) Get added in v0.26.0

func (lr *LazyRegexp) Get() (*regexp.Regexp, error)

Get returns the compiled regular expression, compiling it on the first call. Subsequent calls return the cached result.

func (*LazyRegexp) IsCompiled added in v0.26.0

func (lr *LazyRegexp) IsCompiled() bool

IsCompiled returns true if the pattern has been compiled.

type Result

type Result struct {
	Stdout string
	Stderr string
}

Result represents the result of a command execution.

Jump to

Keyboard shortcuts

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