Documentation
¶
Overview ¶
Package shell provides cross-platform shell execution capabilities.
This package provides Shell instances for executing commands with their own working directory and environment. Each shell execution is independent.
WINDOWS COMPATIBILITY: This implementation provides POSIX shell emulation (mvdan.cc/sh/v3) even on Windows. Commands should use forward slashes (/) as path separators to work correctly on all platforms.
Index ¶
- Constants
- func ExitCode(err error) int
- func IsInterrupt(err error) bool
- type BackgroundShell
- type BackgroundShellInfo
- type BackgroundShellManager
- func (m *BackgroundShellManager) Cleanup() int
- func (m *BackgroundShellManager) Get(id string) (*BackgroundShell, bool)
- func (m *BackgroundShellManager) Kill(id string) error
- func (m *BackgroundShellManager) KillAll()
- func (m *BackgroundShellManager) List() []string
- func (m *BackgroundShellManager) Remove(id string) error
- func (m *BackgroundShellManager) Start(ctx context.Context, workingDir string, blockFuncs []BlockFunc, command string, ...) (*BackgroundShell, error)
- type BlockFunc
- type Logger
- type Options
- type Shell
- func (s *Shell) Exec(ctx context.Context, command string) (string, string, error)
- func (s *Shell) ExecStream(ctx context.Context, command string, stdout, stderr io.Writer) error
- func (s *Shell) GetEnv() []string
- func (s *Shell) GetWorkingDir() string
- func (s *Shell) SetBlockFuncs(blockFuncs []BlockFunc)
- func (s *Shell) SetEnv(key, value string)
- func (s *Shell) SetWorkingDir(dir string) error
- type ShellType
Constants ¶
const ( // MaxBackgroundJobs is the maximum number of concurrent background jobs allowed MaxBackgroundJobs = 50 // CompletedJobRetentionMinutes is how long to keep completed jobs before auto-cleanup (8 hours) CompletedJobRetentionMinutes = 8 * 60 )
Variables ¶
This section is empty.
Functions ¶
func IsInterrupt ¶
IsInterrupt checks if an error is due to interruption
Types ¶
type BackgroundShell ¶
type BackgroundShell struct {
ID string
Command string
Description string
Shell *Shell
WorkingDir string
// contains filtered or unexported fields
}
BackgroundShell represents a shell running in the background.
func (*BackgroundShell) GetOutput ¶
func (bs *BackgroundShell) GetOutput() (stdout string, stderr string, done bool, err error)
GetOutput returns the current output of a background shell.
func (*BackgroundShell) IsDone ¶
func (bs *BackgroundShell) IsDone() bool
IsDone checks if the background shell has finished execution.
func (*BackgroundShell) Wait ¶
func (bs *BackgroundShell) Wait()
Wait blocks until the background shell completes.
type BackgroundShellInfo ¶
BackgroundShellInfo contains information about a background shell.
type BackgroundShellManager ¶
type BackgroundShellManager struct {
// contains filtered or unexported fields
}
BackgroundShellManager manages background shell instances.
func GetBackgroundShellManager ¶
func GetBackgroundShellManager() *BackgroundShellManager
GetBackgroundShellManager returns the singleton background shell manager.
func (*BackgroundShellManager) Cleanup ¶
func (m *BackgroundShellManager) Cleanup() int
Cleanup removes completed jobs that have been finished for more than the retention period
func (*BackgroundShellManager) Get ¶
func (m *BackgroundShellManager) Get(id string) (*BackgroundShell, bool)
Get retrieves a background shell by ID.
func (*BackgroundShellManager) Kill ¶
func (m *BackgroundShellManager) Kill(id string) error
Kill terminates a background shell by ID.
func (*BackgroundShellManager) KillAll ¶
func (m *BackgroundShellManager) KillAll()
KillAll terminates all background shells.
func (*BackgroundShellManager) List ¶
func (m *BackgroundShellManager) List() []string
List returns all background shell IDs.
func (*BackgroundShellManager) Remove ¶
func (m *BackgroundShellManager) Remove(id string) error
Remove removes a background shell from the manager without terminating it. This is useful when a shell has already completed and you just want to clean up tracking.
type BlockFunc ¶
BlockFunc is a function that determines if a command should be blocked
func ArgumentsBlocker ¶
ArgumentsBlocker creates a BlockFunc that blocks specific subcommand
func CommandsBlocker ¶
CommandsBlocker creates a BlockFunc that blocks exact command matches
type Shell ¶
type Shell struct {
// contains filtered or unexported fields
}
Shell provides cross-platform shell execution with optional state persistence
func (*Shell) ExecStream ¶
ExecStream executes a command in the shell with streaming output to provided writers
func (*Shell) GetWorkingDir ¶
GetWorkingDir returns the current working directory
func (*Shell) SetBlockFuncs ¶
SetBlockFuncs sets the command block functions for the shell
func (*Shell) SetWorkingDir ¶
SetWorkingDir sets the working directory