command

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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(
	ctx context.Context,
	params ExecParams,
) (*Result, error)

Exec executes a command directly without a shell.

func (*Executor) Shell

func (c *Executor) Shell(
	ctx context.Context,
	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(ctx context.Context, params ExecParams) (*Result, error)
	// Shell executes a command through /bin/sh -c.
	Shell(ctx context.Context, 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