Documentation
¶
Overview ¶
Package shell provides a cross-platform shell interface for executing commands.
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 ¶
- func EnvironNonInteractive() []string
- func EnvironWithNoPager() []stringdeprecated
- func ExitCode(err error) int
- func IsInterrupt(err error) bool
- type BackgroundShell
- type BackgroundShellManager
- func (m *BackgroundShellManager) Cleanup()
- func (m *BackgroundShellManager) Get(id string) (*BackgroundShell, bool)
- func (m *BackgroundShellManager) Kill(id string) error
- func (m *BackgroundShellManager) List() []*BackgroundShell
- func (m *BackgroundShellManager) Start(ctx context.Context, workingDir string, blockFuncs []BlockFunc, cmd 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 ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvironNonInteractive ¶ added in v1.8.6
func EnvironNonInteractive() []string
EnvironNonInteractive returns a copy of the process environment with [nonInteractiveEnvOverrides] applied (each key replaces an existing entry or is appended).
func EnvironWithNoPager
deprecated
added in
v1.8.6
func EnvironWithNoPager() []string
EnvironWithNoPager is an alias for EnvironNonInteractive.
Deprecated: use EnvironNonInteractive.
func IsInterrupt ¶
IsInterrupt checks if an error is due to interruption
Types ¶
type BackgroundShell ¶
type BackgroundShell struct {
ID string
Cmd string
Args []string
StartedAt time.Time
// contains filtered or unexported fields
}
BackgroundShell represents a running background shell command.
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 BackgroundShellManager ¶
type BackgroundShellManager struct {
// contains filtered or unexported fields
}
BackgroundShellManager manages background shell commands.
func NewBackgroundShellManager ¶
func NewBackgroundShellManager() *BackgroundShellManager
NewBackgroundShellManager creates a new BackgroundShellManager.
func (*BackgroundShellManager) Cleanup ¶
func (m *BackgroundShellManager) Cleanup()
Cleanup removes all background shells.
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.
func (*BackgroundShellManager) List ¶
func (m *BackgroundShellManager) List() []*BackgroundShell
List returns all running background shells.
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