shell

package
v0.1.0-dev.20260213054539 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package shell provides audited command execution for lore.

Commands are executed through bash, so pipes, redirects, loops, and variable expansion work exactly as expected. Go orchestrates and audits; bash does the work.

sh := shell.New()
sh.Run("brew install kubectl")
sh.Run("kubectl version --client")
sh.Run("echo $PATH | tr ':' '\\n' | head -5")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Result

type Result struct {
	Command  string        `json:"command"`
	Stdout   string        `json:"stdout,omitempty"`
	Stderr   string        `json:"stderr,omitempty"`
	ExitCode int           `json:"exit_code"`
	Start    time.Time     `json:"start"`
	Duration time.Duration `json:"duration"`
	Error    string        `json:"error,omitempty"`
}

Result captures everything about a command execution.

func (*Result) Failed

func (r *Result) Failed() bool

Failed returns true if the command failed.

func (*Result) JSON

func (r *Result) JSON() string

JSON returns the result as indented JSON.

func (*Result) OK

func (r *Result) OK() bool

OK returns true if the command exited with code 0.

func (*Result) String

func (r *Result) String() string

String returns a human-readable summary.

type Session

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

Session is an audited shell session.

func New

func New() *Session

New creates a new shell session.

func (*Session) Audit

func (s *Session) Audit(w io.Writer) *Session

Audit sets the audit log writer. Each command result is written as JSON.

func (*Session) Dir

func (s *Session) Dir(path string) *Session

Dir sets the working directory for subsequent commands.

func (*Session) History

func (s *Session) History() []*Result

History returns all commands run in this session.

func (*Session) Must

func (s *Session) Must(command string) *Result

Must runs a command and panics if it fails.

func (*Session) Run

func (s *Session) Run(command string) *Result

Run executes a command through bash. Pipes, redirects, loops, and variable expansion work as expected.

func (*Session) RunContext

func (s *Session) RunContext(ctx context.Context, command string) *Result

RunContext executes a command with a context for cancellation/timeout.

func (*Session) Script

func (s *Session) Script(commands ...string) *Result

Script runs multiple commands in sequence, stopping on first failure. Returns the failing result, or the last successful result.

func (*Session) Set

func (s *Session) Set(key, value string) *Session

Set sets an environment variable for subsequent commands.

func (*Session) With

func (s *Session) With(key, value string) *Session

With returns a copy of the session with additional env vars. Useful for one-off commands that need extra context.

Jump to

Keyboard shortcuts

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