Documentation
¶
Index ¶
- Variables
- func Main(c *config.Config) error
- type DiffRequest
- type DryRunExecutor
- func (e *DryRunExecutor) RunDiff(_ context.Context, req DiffRequest) error
- func (e *DryRunExecutor) RunGenCmd(_ context.Context, req GenCmdRequest) (FileRef, error)
- func (e *DryRunExecutor) RunHook(_ context.Context, req HookRequest) error
- func (e *DryRunExecutor) RunPipeline(_ context.Context, req PipelineRequest) (FileRef, error)
- type Executor
- type FileRef
- type GenCmdRequest
- type HookRequest
- type PipelineRequest
- type RealExecutor
- func (e *RealExecutor) RunDiff(ctx context.Context, req DiffRequest) error
- func (e *RealExecutor) RunGenCmd(ctx context.Context, req GenCmdRequest) (FileRef, error)
- func (e *RealExecutor) RunHook(ctx context.Context, req HookRequest) error
- func (e *RealExecutor) RunPipeline(ctx context.Context, req PipelineRequest) (FileRef, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrDiff = errors.New("Diff") ErrHook = errors.New("Hook") ErrGenCmd = errors.New("GenCmd") ErrPipeline = errors.New("Pipeline") )
Errors returned by execution phases.
Functions ¶
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
}
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)
type Executor ¶ added in v0.6.0
type Executor interface {
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
}
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)