tortoise

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 6 Imported by: 0

README

Tortoise

Library for asyncronously executing shell commands in Go

Documentation

Index

Constants

View Source
const (
	MAX_RESULTS = 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandResult

type CommandResult struct {
	Command    string
	ReturnCode int
	Output     string
	ErrOutput  string
}

CommandResult holds the result of a shell command execution.

type ShellRunner

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

ShellRunner manages shell command execution.

func NewShellRunner

func NewShellRunner() *ShellRunner

NewShellRunner creates a new ShellRunner instance with the default shell (`sh`).

func NewShellRunnerWithShell

func NewShellRunnerWithShell(shell string) *ShellRunner

NewShellRunnerWithShell creates a new ShellRunner with the specified shell.

func (*ShellRunner) AddCommand

func (sr *ShellRunner) AddCommand(command string, callback func(*CommandResult)) error

AddCommand adds a shell command to be executed with an optional callback. No commands can be added if the runner has been stopped or not yet started. The callback is executed asynchronously after the command has completed. The order of command execution and callback invocation can be expected to be preserved.

func (*ShellRunner) GetResults

func (sr *ShellRunner) GetResults() *CommandResult

GetResults retrieves the next available command result (non-blocking).

func (*ShellRunner) Kill

func (sr *ShellRunner) Kill()

Kill stops the ShellRunner immediately, terminating all running commands.

func (*ShellRunner) KillWithTimeout

func (sr *ShellRunner) KillWithTimeout(timeout time.Duration) error

KillWithTimeout attempts to stop the ShellRunner, killing commands if the duration is exceeded.

func (*ShellRunner) Start

func (sr *ShellRunner) Start()

Start begins processing shell commands asynchronously.

func (*ShellRunner) Stop

func (sr *ShellRunner) Stop()

Stop gracefully stops the ShellRunner, closing the command queue and waiting for all commands to finish.

Jump to

Keyboard shortcuts

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