Help us shape the future of Go! Take the 2026 Go Developer Survey

run

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDiff     = errors.New("Diff")
	ErrHook     = errors.New("Hook")
	ErrGenCmd   = errors.New("GenCmd")
	ErrPipeline = errors.New("Pipeline")
)

Errors returned by execution phases.

Functions

func Main

func Main(c *config.Config) error

Types

type DiffRequest added in v0.6.0

type DiffRequest struct {
	// Cmd is the diff command string (e.g. "diff -u").
	Cmd      string
	ExtraEnv []string
	// Labels, if non-empty, are appended as successive --label arguments.
	Labels  []string
	Left    FileRef
	Right   FileRef
	Success bool
}

DiffRequest holds the parameters for the diff step.

type DryRunExecutor added in v0.6.0

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

DryRunExecutor implements Executor by writing a commented, executable shell script to an io.Writer instead of running any commands.

Because it implements Executor, any step routed through the interface is automatically captured in the script — no per-feature dry-run code is needed.

func NewDryRunExecutor added in v0.6.0

func NewDryRunExecutor(shell string, w io.Writer, timeout, processTimeout time.Duration) *DryRunExecutor

NewDryRunExecutor creates a DryRunExecutor and writes the script preamble immediately.

func (*DryRunExecutor) RunDiff added in v0.6.0

func (e *DryRunExecutor) RunDiff(_ context.Context, req DiffRequest) error

func (*DryRunExecutor) RunGenCmd added in v0.6.0

func (e *DryRunExecutor) RunGenCmd(_ context.Context, req GenCmdRequest) (FileRef, error)

func (*DryRunExecutor) RunHook added in v0.6.0

func (e *DryRunExecutor) RunHook(_ context.Context, req HookRequest) error

func (*DryRunExecutor) RunPipeline added in v0.6.0

func (e *DryRunExecutor) RunPipeline(_ context.Context, req PipelineRequest) (FileRef, error)

func (*DryRunExecutor) SetupSnapshot added in v0.8.0

func (*DryRunExecutor) SetupStdin added in v0.8.0

type Executor added in v0.6.0

type Executor interface {
	SetupStdin(ctx context.Context, req SetupInputRequest) (*SetupInputResult, error)
	// SetupSnapshot resolves snapshot inputs for left and right sides.
	// A nil FileRef in the result means no snapshot for that side.
	SetupSnapshot(ctx context.Context, req SetupInputRequest) (*SetupInputResult, error)
	RunHook(ctx context.Context, req HookRequest) error
	RunGenCmd(ctx context.Context, req GenCmdRequest) (FileRef, error)
	RunPipeline(ctx context.Context, req PipelineRequest) (FileRef, error)
	RunDiff(ctx context.Context, req DiffRequest) error
}

Executor abstracts how each execution step in cmdcomp is carried out.

Architecture contract: every command invocation in cmdcomp MUST be expressed through a method on this interface. This guarantees that RealExecutor (actual execution) and DryRunExecutor (shell-script generation) stay in sync automatically. When a new pipeline step is added, routing it through the existing Executor methods grants dry-run support with no additional effort. Adding fields to request structs extends behaviour without breaking callers.

type FileRef added in v0.6.0

type FileRef interface {
	// ShellExpr returns a shell-safe expression for this file:
	// a quoted path in real mode, or a variable reference (e.g. "$_CMDCOMP_LEFT") in dry-run.
	ShellExpr() string
}

FileRef is a handle to command output. RealExecutor wraps real filesystem paths; DryRunExecutor wraps shell variable names. By threading FileRef through pipeline steps, neither the runner nor callers need to know which implementation is active.

type GenCmdRequest added in v0.6.0

type GenCmdRequest struct {
	// Name is used for labelling and variable/path naming.
	Name     string
	ExtraEnv []string
	Args     []string
	// Stdin, if non-nil, provides the input piped into the command.
	Stdin FileRef
}

GenCmdRequest holds the parameters for a command that produces output.

type HookRequest added in v0.6.0

type HookRequest struct {
	// Phase is the hook phase name (startup, interceptor, cleanup).
	Phase string
	// Index is the 0-based position within the phase.
	Index int
	// ExtraEnv holds KEY=VALUE pairs appended to os.Environ().
	ExtraEnv []string
	// Cmd is the shell command string to execute.
	Cmd string
}

HookRequest holds the parameters for a single hook invocation.

type PipelineRequest added in v0.6.0

type PipelineRequest struct {
	Name     string
	ExtraEnv []string
	// Input is the FileRef whose content is piped into the first command.
	Input FileRef
	// Cmds is the list of shell command strings to chain with pipes.
	Cmds []string
}

PipelineRequest holds the parameters for a pipeline of shell commands.

type RealExecutor added in v0.6.0

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

RealExecutor implements Executor by actually running commands.

func (*RealExecutor) RunDiff added in v0.6.0

func (e *RealExecutor) RunDiff(ctx context.Context, req DiffRequest) error

func (*RealExecutor) RunGenCmd added in v0.6.0

func (e *RealExecutor) RunGenCmd(ctx context.Context, req GenCmdRequest) (FileRef, error)

func (*RealExecutor) RunHook added in v0.6.0

func (e *RealExecutor) RunHook(ctx context.Context, req HookRequest) error

func (*RealExecutor) RunPipeline added in v0.6.0

func (e *RealExecutor) RunPipeline(ctx context.Context, req PipelineRequest) (FileRef, error)

func (*RealExecutor) SetupSnapshot added in v0.8.0

func (e *RealExecutor) SetupSnapshot(_ context.Context, req SetupInputRequest) (*SetupInputResult, error)

func (*RealExecutor) SetupStdin added in v0.8.0

type SetupInputRequest added in v0.8.0

type SetupInputRequest struct {
	Left   string
	Right  string
	Reader io.Reader
}

SetupInputRequest holds parameters for setting up input sources (stdin or snapshot).

type SetupInputResult added in v0.8.0

type SetupInputResult struct {
	LeftRef  FileRef
	RightRef FileRef
}

SetupInputResult holds the resolved FileRefs for left and right sides.

Jump to

Keyboard shortcuts

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