command

package
v3.16.10 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvNameTerminalSessionEnabled  = "_RUNME_TERMINAL_SESSION_ENABLED"
	EnvNameTerminalSessionPrePath  = "_RUNME_TERMINAL_SESSION_PREPATH"
	EnvNameTerminalSessionPostPath = "_RUNME_TERMINAL_SESSION_POSTPATH"
)

Constants for supporting terminal session via the "beta session" command.

View Source
const DefaultProgramResolverMode = ProgramResolverModeAuto
View Source
const StoreStdoutEnvName = "__"

Variables

This section is empty.

Functions

func CreateEnv

func CreateEnv(key, value string) string

func EnvSliceToString

func EnvSliceToString(env []string) string

func IsShellLanguage

func IsShellLanguage(languageID string) bool

TODO(adamb): this function is used for two quite different inputs: program name and language ID.

func SetEnvDumpCommandForTesting

func SetEnvDumpCommandForTesting()

SetEnvDumpCommandForTesting overrides the default command that dumps the environment variables. It is and should be used only for testing purposes. TODO(adamb): this can be made obsolete. runme must be built in the test environment and put into the PATH.

func SetWinsize

func SetWinsize(cmd Command, winsize *Winsize) (err error)

Types

type Command

type Command interface {
	Interactive() bool
	Pid() int
	Running() bool
	Start(context.Context) error
	Signal(os.Signal) error
	Wait(context.Context) error
}

type CommandOptions

type CommandOptions struct {
	// EnableEcho enables the echo when typing in the terminal.
	// It's respected only by interactive commands, i.e. composed
	// with [virtualCommand].
	EnableEcho bool

	// NoShell, if true, disables detecting whether the program
	// is a shell script.
	NoShell bool

	// Session is used to share the state between commands.
	// If none is provided, an empty one will be used.
	Session *session.Session

	// StdinWriter is used by [terminalCommand].
	StdinWriter io.Writer
	Stdin       io.Reader
	Stdout      io.Writer
	Stderr      io.Writer
}

type ConfigBuilderOption

type ConfigBuilderOption func(*configBuilder) error

func WithInteractiveLegacy

func WithInteractiveLegacy() ConfigBuilderOption

type EnvCollectorFactory

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

func NewEnvCollectorFactory

func NewEnvCollectorFactory() *EnvCollectorFactory

func (*EnvCollectorFactory) Build

func (f *EnvCollectorFactory) Build() (envCollector, error)

func (*EnvCollectorFactory) UseFifo

func (f *EnvCollectorFactory) UseFifo(value bool) *EnvCollectorFactory

func (*EnvCollectorFactory) WithEncryption

func (f *EnvCollectorFactory) WithEncryption(value bool) *EnvCollectorFactory

type EnvDecryptor

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

func NewEnvDecryptor

func NewEnvDecryptor(key []byte, nonce []byte, source io.Reader) (*EnvDecryptor, error)

func (*EnvDecryptor) Read

func (d *EnvDecryptor) Read(p []byte) (n int, err error)

type EnvEncryptor

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

func NewEnvEncryptor

func NewEnvEncryptor(key []byte, nonce []byte, source io.Reader) (*EnvEncryptor, error)

func (*EnvEncryptor) Read

func (e *EnvEncryptor) Read(p []byte) (n int, err error)

type EnvProducer

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

func NewEnvProducerFromEnv

func NewEnvProducerFromEnv() (*EnvProducer, error)

func (*EnvProducer) Read

func (p *EnvProducer) Read(b []byte) (n int, err error)

type Factory

type Factory interface {
	Build(*ProgramConfig, CommandOptions) (Command, error)
}

func NewFactory

func NewFactory(opts ...FactoryOption) Factory

type FactoryOption

type FactoryOption func(*commandFactory)

func WithDebug

func WithDebug() FactoryOption

WithDebug enables additional debug information. For example, for shell commands it prints out commands before execution.

func WithDocker

func WithDocker(docker *dockerexec.Docker) FactoryOption

WithDocker provides a docker client for docker commands.

func WithLogger

func WithLogger(logger *zap.Logger) FactoryOption

func WithProcessLifecycle added in v3.16.5

func WithProcessLifecycle(p ProcessLifecycle) FactoryOption

func WithProject

func WithProject(proj *project.Project) FactoryOption

func WithRuntime

func WithRuntime(r Runtime) FactoryOption

type ProcessLifecycle added in v3.16.5

type ProcessLifecycle int

ProcessLifecycle controls child process group membership and signal propagation behavior.

const (
	// ProcessLifecycleIsolated places the child in its own process
	// group (Setpgid). Signal isolation: children survive when the
	// parent is killed or the context is cancelled.
	ProcessLifecycleIsolated ProcessLifecycle = iota

	// ProcessLifecycleLinked keeps the child in the parent's process
	// group so OS signals propagate naturally. When the parent is
	// killed, children are cleaned up through normal group signal
	// delivery. For virtual (PTY) commands that require session
	// isolation, cmd.Cancel signals the process group on context
	// cancellation instead.
	ProcessLifecycleLinked
)

type ProgramConfig

type ProgramConfig = runnerv2.ProgramConfig

ProgramConfig contains a serializable configuration for a command. It's agnostic to the runtime or particular execution settings.

func NewProgramConfigFromCodeBlock

func NewProgramConfigFromCodeBlock(block *document.CodeBlock, opts ...ConfigBuilderOption) (*ProgramConfig, error)

type ProgramResolver

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

ProgramResolver uses a list of ProgramResolverSource to resolve environment variables found in a shell program.

func NewProgramResolver

func NewProgramResolver(mode ProgramResolverMode, sensitiveEnvNames []string, sources ...ProgramResolverSource) *ProgramResolver

func (*ProgramResolver) IsEnvSensitive

func (r *ProgramResolver) IsEnvSensitive(name string) bool

func (*ProgramResolver) Resolve

func (r *ProgramResolver) Resolve(reader io.Reader, writer io.Writer, retention Retention) (*ProgramResolverResult, error)

Resolve resolves the environment variables found in a shell program. It might modify the program and write it provided writer.

type ProgramResolverMode

type ProgramResolverMode uint8
const (
	// ProgramResolverModeAuto is a default which prompts for all unresolved variables.
	ProgramResolverModeAuto ProgramResolverMode = iota
	// ProgramResolverModePromptAll always prompts even if variables are resolved.
	ProgramResolverModePromptAll
	// ProgramResolverModeSkipAll does not prompt even if variables are unresolved.
	// All variables will be marked as resolved.
	ProgramResolverModeSkipAll
)

type ProgramResolverResult

type ProgramResolverResult struct {
	Variables       []ProgramResolverVarResult
	ModifiedProgram bool
}

type ProgramResolverSource

type ProgramResolverSource func() []string

func ProgramResolverSourceFunc

func ProgramResolverSourceFunc(env []string) ProgramResolverSource

type ProgramResolverStatus

type ProgramResolverStatus uint8
const (
	// ProgramResolverStatusUnresolved indicates a variable is unresolved.
	ProgramResolverStatusUnresolved ProgramResolverStatus = iota
	// ProgramResolverStatusUnresolvedWithMessage indicates a variable is unresolved but it has a message.
	// It typically means that the variable is of form `export FOO=this is a message`.
	ProgramResolverStatusUnresolvedWithMessage
	// ProgramResolverStatusUnresolvedWithPlaceholder indicates a variable is unresolved but it has a placeholder.
	// It typically means that the variable is of form `export FOO="this is a placeholder"`.
	ProgramResolverStatusUnresolvedWithPlaceholder
	// ProgramResolverStatusUnresolvedWithSecret indicates a variable is unresolved and needs to be treated with sensitivity.
	// It typically means that the variable is a password, certificate, or access key.
	ProgramResolverStatusUnresolvedWithSecret
	// ProgramResolverStatusResolved indicates a variable is resolved.
	ProgramResolverStatusResolved
)

type ProgramResolverVarResult

type ProgramResolverVarResult struct {
	// Status indicates the status of the result.
	Status ProgramResolverStatus

	// Name is the name of the variable.
	// It is set always.
	Name string

	// OriginalValue is the original value of the variable.
	// It's either a placeholder (`export FOO="this is a placeholder"`) or
	// a message (`export FOO=this is a message`).
	OriginalValue string

	// Value is the resolved value of the variable.
	// It is set only if Status is ProgramResolverStatusResolved.
	Value string
}

type Retention

type Retention uint8
const (
	RetentionUnspecified Retention = iota
	// RetentionFirstRun means to always retain the resolved values from the first task/block/cell run.
	RetentionFirstRun
	// RetentionLastRun means to always retain the resolved values from the last task/block/cell run.
	RetentionLastRun
)

type Runtime

type Runtime interface {
	Environ() []string
	LookPathUsingPathEnv(file, pathEnv string) (string, error)
}

type ScriptEnvSetter

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

ScriptEnvSetter returns a shell script that installs itself and collects environment variables to provided pre- and post-paths.

func NewScriptEnvSetter

func NewScriptEnvSetter(prePath, postPath string, debug bool) ScriptEnvSetter

func (ScriptEnvSetter) SetOnShell

func (s ScriptEnvSetter) SetOnShell(shell io.Writer) error

type Winsize

type Winsize pty.Winsize

Jump to

Keyboard shortcuts

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