Help us shape the future of Go! Take the 2026 Go Developer Survey

foreach

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package foreach provides functionality for executing a command on each branch in a stack.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Action

func Action(ctx *app.Context, opts Options, handler Handler) error

Action executes a command on each branch in the stack with event handling

func HasForeachWork

func HasForeachWork(ctx *app.Context, opts Options) (bool, error)

HasForeachWork reports whether Action would have at least one non-trunk branch to execute the command on. Use this from the CLI to gate TUI initialization — when the answer is no, starting the bubbletea runner only flashes startup/teardown escape codes and races with the deferred Cleanup before the "no branches to process" CompletionEvent can render.

Types

type BranchInfo

type BranchInfo struct {
	Name string
}

BranchInfo contains information about a branch for execution tracking.

type BranchProgressEvent

type BranchProgressEvent struct {
	BranchName string
	Status     BranchStatus
	Output     string // command output (may be truncated)
	Error      error  // set on failure
}

BranchProgressEvent indicates per-branch execution progress.

type BranchResult

type BranchResult struct {
	BranchName string
	Status     BranchStatus
	ExitCode   int
	Output     string
	Error      error
}

BranchResult contains the final result for a branch

type BranchStatus

type BranchStatus string

BranchStatus represents the status of a branch during execution.

const (
	StatusPending BranchStatus = "pending"
	StatusRunning BranchStatus = "running"
	StatusDone    BranchStatus = "done"
	StatusError   BranchStatus = "error"
	StatusSkipped BranchStatus = "skipped"
)

BranchStatus values for tracking execution progress.

type CompletionEvent

type CompletionEvent struct {
	Success bool
	Message string
	Results []BranchResult // Consolidated results for all branches
}

CompletionEvent indicates the action has finished.

type Event

type Event interface {
	// contains filtered or unexported methods
}

Event represents a feedback event from the foreach action. Implementations should use type switches to handle specific event types.

type ExecutionStartEvent

type ExecutionStartEvent struct {
	Branches []BranchInfo
}

ExecutionStartEvent indicates the execution phase is beginning.

type Handler

type Handler interface {
	// OnEvent is called for each event during execution.
	// Handlers should use type switches to handle specific event types.
	OnEvent(event Event)
}

Handler receives events from the foreach action and handles user interaction. Implementations should handle events appropriately for their UI context (interactive terminal, non-interactive, dashboard, etc.)

type JSONBranchResult

type JSONBranchResult struct {
	Branch   string       `json:"branch"`
	Status   BranchStatus `json:"status"`
	ExitCode int          `json:"exit_code"`
	Output   string       `json:"output,omitempty"`
	Error    string       `json:"error,omitempty"`
}

JSONBranchResult represents one branch result in foreach JSON output.

type JSONHandler

type JSONHandler struct {
	Result *JSONResult
	// contains filtered or unexported fields
}

JSONHandler collects foreach events for JSON output.

func NewJSONHandler

func NewJSONHandler() *JSONHandler

NewJSONHandler creates a handler that collects foreach results as JSON data.

func (*JSONHandler) OnEvent

func (h *JSONHandler) OnEvent(e Event)

OnEvent implements Handler.

func (*JSONHandler) SetError

func (h *JSONHandler) SetError(err error)

SetError records an action-level error in the JSON result.

type JSONResult

type JSONResult struct {
	Status       JSONStatus         `json:"status"`
	Error        string             `json:"error,omitempty"`
	Message      string             `json:"message,omitempty"`
	Command      string             `json:"command,omitempty"`
	Results      []JSONBranchResult `json:"results"`
	TotalCount   int                `json:"total_count"`
	SuccessCount int                `json:"success_count"`
	FailureCount int                `json:"failure_count"`
}

JSONResult represents the JSON output for foreach operations.

type JSONStatus

type JSONStatus string

JSONStatus represents the aggregate outcome of a foreach operation.

const (
	JSONStatusSuccess JSONStatus = "success"
	JSONStatusFailure JSONStatus = "failure"
	JSONStatusError   JSONStatus = "error"
)

type Options

type Options struct {
	Command          string
	Args             []string
	BranchName       string
	Scope            engine.StackRange
	AllStacks        bool     // Run across every independent stack rooted at trunk
	StackRoots       []string // Run across the listed independent stack roots only
	FailFast         bool
	Parallel         bool
	FindFirstFailure bool
	Jobs             int
}

Options contains options for the foreach command

type StackDisplayEvent

type StackDisplayEvent struct {
	Stack   StackSnapshot // branch relationships for rendering the stack
	Command string        // command being executed
}

StackDisplayEvent indicates the initial stack visualization phase. Handlers can use this to display the branches that will be processed.

type StackSnapshot added in v0.29.0

type StackSnapshot struct {
	Branches      []string          // branches to process, in order (trunk excluded)
	CurrentBranch string            // currently checked out branch
	TrunkBranch   string            // trunk/main branch name
	ParentMap     map[string]string // branch -> parent (trunk for trunk-rooted branches)
}

StackSnapshot contains the branch relationships needed to render the branches foreach will process. This is action-layer data; adapters decide how to visualize it.

Jump to

Keyboard shortcuts

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