execs

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: Apache-2.0 Imports: 10 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) Exec

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

func (*Command) ExecWithStdin

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

func (*Command) GetEnv

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

GetEnv constructs environment variables for command execution.

func (*Command) SetBaseEnv

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

func (*Command) SetExtraArgs added in v0.21.0

func (e *Command) SetExtraArgs(args ...string)

SetExtraArgs sets additional command arguments.

func (*Command) String

func (e *Command) String() 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 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