exec

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 36 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

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() error

WillPodman checks whether Podman is available and responsive on the host.

Types

type DockerExecutor

type DockerExecutor struct {
	Name  string
	Image string
	// contains filtered or unexported fields
}

DockerExecutor runs CLI tools inside a Docker container.

func (*DockerExecutor) Cleanup

func (e *DockerExecutor) Cleanup() error

Cleanup stops and removes the temporary Docker container created during Setup.

func (*DockerExecutor) Exec

func (e *DockerExecutor) Exec(i Instance, filePath string, stdout io.Writer, stderr io.Writer) error

Exec runs the configured command inside the prepared Docker container.

func (*DockerExecutor) Setup

func (e *DockerExecutor) Setup() error

Setup creates and starts a disposable Docker container for executing commands.

type Executor

type Executor interface {
	Setup() error
	Exec(i Instance, filepath string, stdout io.Writer, stderr io.Writer) error
	Cleanup() 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.

type HostExecutor

type HostExecutor struct {
}

HostExecutor runs CLI tools directly on the host operating system.

func (*HostExecutor) Cleanup

func (e *HostExecutor) Cleanup() error

Cleanup releases any resources allocated during host execution setup.

func (*HostExecutor) Exec

func (e *HostExecutor) Exec(i Instance, filePath string, stdout io.Writer, stderr io.Writer) error

Exec runs the configured CLI tool on the host against the provided file.

func (*HostExecutor) Setup

func (e *HostExecutor) Setup() error

Setup performs any required initialization for host execution.

type Instance

type Instance struct {
	Bin   string `json:"bin" yaml:"bin" jsonschema_required:"true" jsonschema_description:"the binary or command to use"`
	Start Par    `` /* 134-byte string literal not displayed */
	End   Par    `json:"end,flow,omitempty" yaml:"end,flow,omitempty" jsonschema_description:"parameters that will be put behind the file path"`
	ChDir bool   `` /* 145-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.

type NoopExecutor

type NoopExecutor struct{}

NoopExecutor is a test/dummy executor that writes fixed strings to stdout and stderr.

func (*NoopExecutor) Cleanup

func (ne *NoopExecutor) Cleanup() error

Cleanup finalizes the NoopExecutor (no-op).

func (*NoopExecutor) Exec

func (ne *NoopExecutor) Exec(_ Instance, _ string, stdout io.Writer, stderr io.Writer) error

Exec writes sample output to stdout and stderr and returns nil.

func (*NoopExecutor) Setup

func (ne *NoopExecutor) Setup() error

Setup initializes the NoopExecutor (no-op).

type Par

type Par []string

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

type PodmanExecutor

type PodmanExecutor struct {
	Name  string
	Image string
	// contains filtered or unexported fields
}

PodmanExecutor runs CLI tools inside a Podman container.

func (*PodmanExecutor) Cleanup

func (e *PodmanExecutor) Cleanup() error

Cleanup stops and removes the temporary Podman container created during Setup.

func (*PodmanExecutor) Exec

func (e *PodmanExecutor) Exec(i Instance, filePath string, stdout io.Writer, stderr io.Writer) error

Exec runs the configured command inside the prepared Podman container.

func (*PodmanExecutor) Setup

func (e *PodmanExecutor) Setup() error

Setup creates and starts a disposable Podman container for executing commands.

Jump to

Keyboard shortcuts

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