commands

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunTestSuite

func RunTestSuite()

RunTestSuite executes all command system tests

func TestEchoCommand

func TestEchoCommand(builder *CommandBuilder)

TestEchoCommand tests echo with captured output

func TestGitLogWithStreamHandler

func TestGitLogWithStreamHandler(builder *CommandBuilder)

TestGitLogWithStreamHandler tests git log with StreamHandler

func TestGitStatus

func TestGitStatus(ctx context.Context, builder *CommandBuilder)

TestGitStatus tests git status with streaming output

func TestPingStreaming

func TestPingStreaming(ctx context.Context, builder *CommandBuilder)

TestPingStreaming tests ping with real-time streaming

Types

type Command

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

Command represents a shell command to be executed

func (*Command) CaptureOutput

func (c *Command) CaptureOutput() *Command

CaptureOutput enables output capture for return

func (*Command) Kill

func (c *Command) Kill() error

Kill terminates the running process and its children (process group)

func (*Command) OnComplete

func (c *Command) OnComplete(fn func(int)) *Command

OnComplete sets callback for completion

func (*Command) OnError

func (c *Command) OnError(fn func(error)) *Command

OnError sets callback for errors

func (*Command) OnStderr

func (c *Command) OnStderr(fn func(string)) *Command

OnStderr sets callback for stderr lines

func (*Command) OnStdout

func (c *Command) OnStdout(fn func(string)) *Command

OnStdout sets callback for stdout lines

func (*Command) Run

func (c *Command) Run() error

Run executes the command synchronously

func (*Command) RunAndStream

func (c *Command) RunAndStream() error

RunAndStream executes with real-time streaming

func (*Command) RunAsync

func (c *Command) RunAsync() error

RunAsync executes the command asynchronously

func (*Command) RunWithOutput

func (c *Command) RunWithOutput() (*CommandResult, error)

RunWithOutput executes and captures output

func (*Command) StreamOutput

func (c *Command) StreamOutput() *Command

StreamOutput enables real-time output streaming

func (*Command) WithEnv

func (c *Command) WithEnv(vars ...string) *Command

WithEnv adds environment variables

func (*Command) WithWorkingDir

func (c *Command) WithWorkingDir(dir string) *Command

WithWorkingDir sets the working directory

type CommandBuilder

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

CommandBuilder provides a fluent API for building commands

func NewCommandBuilder

func NewCommandBuilder(platform *Platform) *CommandBuilder

NewCommandBuilder creates a new command builder

func (*CommandBuilder) New

func (b *CommandBuilder) New(args ...string) *Command

New creates a command from arguments Example: New("npx", "prisma", "migrate", "dev")

func (*CommandBuilder) NewShell

func (b *CommandBuilder) NewShell(ctx context.Context, cmdStr string) *Command

NewShell creates a command from a shell string Example: NewShell("npx prisma migrate dev --name init")

func (*CommandBuilder) NewWithContext

func (b *CommandBuilder) NewWithContext(ctx context.Context, args ...string) *Command

NewWithContext creates a command with a context for cancellation

type CommandResult

type CommandResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
	Error    error
	Duration time.Duration
}

CommandResult holds the result of command execution

type CommandRunner

type CommandRunner interface {
	Run(cmd *Command) error
	RunWithOutput(cmd *Command) (*CommandResult, error)
	RunAsync(cmd *Command) error
	RunAndStream(cmd *Command) error
}

CommandRunner interface for executing commands

type Platform

type Platform struct {
	OS       string
	Shell    string
	ShellArg string
}

Platform holds platform-specific configurations

func NewPlatform

func NewPlatform() *Platform

NewPlatform creates a platform configuration for the current OS

func (*Platform) GetShell

func (p *Platform) GetShell() (string, string)

GetShell returns the shell and its command argument

type StreamHandler

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

StreamHandler manages real-time output streaming with buffering

func NewStreamHandler

func NewStreamHandler(onUpdate func(stdout, stderr []string)) *StreamHandler

NewStreamHandler creates a new stream handler

func (*StreamHandler) Clear

func (h *StreamHandler) Clear()

Clear clears the buffered output

func (*StreamHandler) GetOutput

func (h *StreamHandler) GetOutput() (stdout, stderr []string)

GetOutput returns the current buffered output

func (*StreamHandler) HandleStderr

func (h *StreamHandler) HandleStderr(line string)

HandleStderr processes a stderr line

func (*StreamHandler) HandleStdout

func (h *StreamHandler) HandleStdout(line string)

HandleStdout processes a stdout line

Jump to

Keyboard shortcuts

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