command

package
v0.0.0-...-36c55c0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package command provides command execution capabilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecParams

type ExecParams struct {
	// Command is the executable name or path.
	Command string
	// Args are the command arguments.
	Args []string
	// Cwd is the optional working directory.
	Cwd string
	// Timeout is the timeout in seconds (0 = default 30s).
	Timeout int
}

ExecParams contains parameters for direct command execution.

type Executor

type Executor struct {
	provider.FactsAware
	// contains filtered or unexported fields
}

Executor implements the Provider interface for command execution.

func New

func New(
	logger *slog.Logger,
	em exec.Manager,
) *Executor

New factory to create a new Executor instance.

func (*Executor) Exec

func (c *Executor) Exec(
	params ExecParams,
) (*Result, error)

Exec executes a command directly without a shell.

func (*Executor) Shell

func (c *Executor) Shell(
	params ShellParams,
) (*Result, error)

Shell executes a command through /bin/sh -c.

type Provider

type Provider interface {
	// Exec executes a command directly without a shell.
	Exec(params ExecParams) (*Result, error)
	// Shell executes a command through /bin/sh -c.
	Shell(params ShellParams) (*Result, error)
}

Provider implements the methods to execute commands on the system.

type Result

type Result struct {
	// Stdout is the standard output.
	Stdout string `json:"stdout"`
	// Stderr is the standard error output.
	Stderr string `json:"stderr"`
	// ExitCode is the process exit code.
	ExitCode int `json:"exit_code"`
	// DurationMs is the execution time in milliseconds.
	DurationMs int64 `json:"duration_ms"`
	// Changed indicates whether the command modified system state.
	Changed bool `json:"changed"`
}

Result contains the output of a command execution.

type ShellParams

type ShellParams struct {
	// Command is the full shell command string.
	Command string
	// Cwd is the optional working directory.
	Cwd string
	// Timeout is the timeout in seconds (0 = default 30s).
	Timeout int
}

ShellParams contains parameters for shell command execution.

Directories

Path Synopsis
Package mocks provides mock implementations for testing.
Package mocks provides mock implementations for testing.

Jump to

Keyboard shortcuts

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