Documentation
¶
Overview ¶
Package executor allows for a CLI tool to be executed in different contexts
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBadInstance = errors.New("invalid exec options")
ErrBadInstance is returned when an Instance has options that can't be used together
var ErrNoTargets = errors.New("no targets to execute against")
ErrNoTargets is returned when Exec is called without any target paths
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 ¶
GetWorkdirAsLinuxPath is useful for consistently mapping any host fs to what is typically in container environments (Linux)
func ToLinuxPath ¶
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 WillPodman ¶
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.
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.