command

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnectionClosed   = errors.New("connection closed")
	ErrCommandNotAllowed  = errors.New("command not allowed")
	ErrArgumentNotAllowed = errors.New("argument not allowed")
)
View Source
var ErrMalformedRequest = errors.New("malformed request")

Functions

func Handler

func Handler(r Runner, options ...HandlerOption) socket.Handler

Handler for receiving and running commands.

Types

type AllowedCommand

type AllowedCommand struct{}

AllowedCommand is a command that the runner is allowed to run.

type Client

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

Client is a socket client to make requests to a command socket server.

func NewClient

func NewClient(address string) *Client

NewClient creates and returns a new client with the provided address.

func (*Client) Close

func (c *Client) Close() error

func (*Client) Run

func (c *Client) Run(ctx context.Context, req Request) <-chan Output

Run makes a request to the command socket server and returns a channel that streams the output.

type Command

type Command struct {
	Path       string            `json:"path,omitempty"`
	Args       []string          `json:"args,omitempty"`
	Env        map[string]string `json:"env,omitempty"`
	WorkingDir string            `json:"working_dir,omitempty"`
	Timeout    time.Duration     `json:"timeout,omitempty"`
}

Command to run.

func (Command) LogValue

func (c Command) LogValue() slog.Value

type HandlerOption

type HandlerOption func(*handlerConfig)

HandlerOption sets options on the handler.

func WithLogger

func WithLogger(logger *slog.Logger) HandlerOption

WithLogger sets logger on the handler:

type Output

type Output struct {
	Type     OutputType `json:"type"`
	Data     string     `json:"data,omitempty"`
	ExitCode int        `json:"exit_code,omitempty"`
	Error    string     `json:"error,omitempty"`
}

Output from command.

type OutputType

type OutputType string

OutputType is the type of output to write to the writer.

const (
	OutputStdout OutputType = "stdout"
	OutputStderr OutputType = "stderr"
	OutputResult OutputType = "result"
	OutputError  OutputType = "error"
)

type Request

type Request struct {
	RequestID string  `json:"request_id,omitempty"`
	ClientID  string  `json:"client_id"`
	Command   Command `json:"command"`
}

Request for the command.

type Response

type Response struct {
	RequestID string `json:"request_id"`
	ClientID  string `json:"client_id"`
	Output    Output `json:"output"`
	Error     string `json:"error,omitempty"`
}

Response with the results from the command.

type Runner

type Runner interface {
	// Run command.
	Run(ctx context.Context, w io.Writer, command Command) error
}

Runner runs the provided command (path to binary, arguments, etc.)

func NewRunner

func NewRunner(options ...RunnerOption) Runner

NewRunner creates and returns a new runner.

type RunnerOption

type RunnerOption func(r *runner)

RunnerOption sets options on the runner.

func WithAllowedCommands

func WithAllowedCommands(commands map[string]AllowedCommand) RunnerOption

WithAllowedCommands sets commands that the runner are allowed to run.

func WithWorkspaceRoot

func WithWorkspaceRoot(root string) RunnerOption

WithWorkspaceRoot sets the workspace root for the runner.

Jump to

Keyboard shortcuts

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