executor

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 46 Imported by: 0

Documentation

Overview

Package executor allows for a CLI tool to be executed in different contexts

Index

Constants

This section is empty.

Variables

View Source
var ErrBadInstance = errors.New("invalid exec options")

ErrBadInstance is returned when an Instance has options that can't be used together

View Source
var ErrNoTargets = errors.New("no targets to execute against")

ErrNoTargets is returned when Exec is called without any target paths

View Source
var ErrRuntimeUnavailable = errors.New("container runtime unavailable")

ErrRuntimeUnavailable is returned when a container runtime is configured but can't be used, callers should stop rather than silently falling back to another executor

Functions

func GetWorkdirAsLinuxPath

func GetWorkdirAsLinuxPath() (string, error)

GetWorkdirAsLinuxPath is useful for consistently mapping any host fs to what is typically in container environments (Linux)

func ToLinuxPath

func ToLinuxPath(p string) string

ToLinuxPath ensures windows paths can be mapped to linux container paths

func WillDocker

func WillDocker() error

WillDocker checks whether Docker is available on the host (via the socket).

func WillHost

func WillHost(bin string) error

WillHost checks whether the given binary can be found on the host PATH.

func WillPodman

func WillPodman(_ context.Context) error

WillPodman checks whether Podman is available and responsive on the host. If Podman is configured (a machine or CONTAINER_HOST exists) but doesn't respond, the error wraps ErrRuntimeUnavailable.

Types

type Executor

type Executor interface {
	Setup(ctx context.Context, i Instance) error
	Exec(ctx context.Context, stdout io.Writer, stderr io.Writer, targets ...string) error
	Cleanup(ctx context.Context) error
}

Executor abstracts how a CLI tool is executed (host, Docker, Podman, etc.). Implementations should prepare resources in Setup, execute the tool in Exec, and free resources in Cleanup. Exec runs the tool once against all targets, more than one target is only expected for a batch Instance.

func NewDocker

func NewDocker(image string) Executor

NewDocker creates an executor using containers managed by the docker client.

func NewHost

func NewHost() Executor

NewHost creates an executor that uses direct exec calls

func NewNoop

func NewNoop() Executor

NewNoop creates an executor that does nothing

func NewPodman

func NewPodman(image string) Executor

NewPodman creates an executor using containers managed by the podman client.

type Instance

type Instance struct {
	Bin        string `json:"bin" yaml:"bin" jsonschema:"the binary or command to use"`
	Start      Par    `json:"start,omitzero" yaml:"start,flow" jsonschema:"parameters that will be put in front of the file path"`
	End        Par    `json:"end,omitzero" yaml:"end,flow" jsonschema:"parameters that will be put behind the file path"`
	ChDir      bool   `json:"chdir,omitzero" yaml:"chdir" jsonschema:"if true the tool will change directory to where the target file is located"`
	WillWrite  bool   `` /* 175-byte string literal not displayed */
	NoFileArg  bool   `` /* 185-byte string literal not displayed */
	Batch      bool   `` /* 278-byte string literal not displayed */
	BatchStart Par    `` /* 238-byte string literal not displayed */
}

Instance describes a single CLI execution configuration for a linter tool. It specifies the binary to run, positional arguments to prepend/append, and whether execution should change to the file's directory first.

func (Instance) Validate added in v1.0.12

func (i Instance) Validate() error

Validate checks the Instance's options can be used together

type Par

type Par []string

Par represents command-line parameters passed to a linter executable.

Jump to

Keyboard shortcuts

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