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

handler

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package handler provides common handler types and base implementations for action handlers throughout the stackit codebase.

All action handlers share common patterns:

  • StepStatus enum for step lifecycle states
  • Cleanup() method for terminal state restoration
  • IsInteractive() method for interactive prompt support
  • NullBase struct embedding for default no-op implementations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoConfirmPromptHandler

type AutoConfirmPromptHandler struct{}

AutoConfirmPromptHandler provides a PromptHandler that always confirms. Use this when you want prompts to auto-confirm (e.g., --yes flag).

func (AutoConfirmPromptHandler) PromptConfirm

func (AutoConfirmPromptHandler) PromptConfirm(string) (bool, error)

PromptConfirm implements PromptHandler. Returns true (auto-confirm).

type Base

type Base interface {
	// Cleanup restores terminal state after the action completes.
	// Called in defer blocks to ensure cleanup on success or failure.
	// May be a no-op for non-interactive handlers.
	Cleanup()

	// IsInteractive returns true if the handler supports interactive prompts.
	// Used to determine whether to show confirmation dialogs, progress UI, etc.
	IsInteractive() bool
}

Base defines the common interface that all action handlers must implement. Embed NullBase in your handler struct to get default no-op implementations.

type ConfirmPromptHandler added in v0.29.0

type ConfirmPromptHandler struct {
	Confirmer  Confirmer
	DefaultYes bool
}

ConfirmPromptHandler adapts a Confirmer to PromptHandler with a fixed default answer.

func (ConfirmPromptHandler) PromptConfirm added in v0.29.0

func (h ConfirmPromptHandler) PromptConfirm(message string) (bool, error)

PromptConfirm implements PromptHandler.

type Confirmer added in v0.29.0

type Confirmer interface {
	// Confirm returns the user's answer. defaultYes is the answer selected
	// when the user just presses Enter.
	Confirm(message string, defaultYes bool) (bool, error)
}

Confirmer asks a yes/no question.

type MultiSelector added in v0.29.0

type MultiSelector interface {
	// MultiSelect returns the chosen options.
	MultiSelect(title string, options []string) ([]string, error)
}

MultiSelector asks the user to pick any number of options.

type NonInteractivePrompter added in v0.29.0

type NonInteractivePrompter struct{}

NonInteractivePrompter is the Prompter used when no adapter supplied one. Every prompt fails with term.ErrInteractiveDisabled, matching what an interactive prompt does under --no-interactive or without a TTY.

func (NonInteractivePrompter) Confirm added in v0.29.0

Confirm implements Confirmer.

func (NonInteractivePrompter) MultiSelect added in v0.29.0

func (NonInteractivePrompter) MultiSelect(string, []string) ([]string, error)

MultiSelect implements MultiSelector.

func (NonInteractivePrompter) Select added in v0.29.0

Select implements Selector.

func (NonInteractivePrompter) TextInput added in v0.29.0

TextInput implements TextInputPrompter.

type NullBase

type NullBase struct{}

NullBase provides no-op implementations of the Base interface. Embed this in handler structs to inherit default implementations.

Example:

type MyNullHandler struct {
    handler.NullBase
}

// MyNullHandler now has Cleanup() and IsInteractive() implemented

func (NullBase) Cleanup

func (NullBase) Cleanup()

Cleanup implements Base. No-op for null handler.

func (NullBase) IsInteractive

func (NullBase) IsInteractive() bool

IsInteractive implements Base. Returns false for null handler.

type NullProgress

type NullProgress[Step any] struct{}

NullProgress provides a no-op implementation of ProgressHandler for any step type.

func (NullProgress[Step]) OnStep

func (NullProgress[Step]) OnStep(Step, StepStatus, string)

OnStep implements ProgressHandler. No-op for null handler.

type NullPromptHandler

type NullPromptHandler struct{}

NullPromptHandler provides a no-op implementation of PromptHandler. Returns (false, nil) for all prompts (auto-decline).

func (NullPromptHandler) PromptConfirm

func (NullPromptHandler) PromptConfirm(string) (bool, error)

PromptConfirm implements PromptHandler. Returns false (auto-decline) for null handler.

type ProgressHandler

type ProgressHandler[Step any] interface {
	// OnStep is called to report progress on a named step.
	OnStep(step Step, status StepStatus, message string)
}

ProgressHandler defines the interface for handlers that report step progress. The step parameter type varies by action, so this uses a generic Step type.

type PromptHandler

type PromptHandler interface {
	// PromptConfirm displays a confirmation prompt and returns the user's choice.
	// Returns (true, nil) to proceed, (false, nil) to cancel.
	// Returns an error if the prompt fails (e.g., terminal error).
	PromptConfirm(message string) (bool, error)
}

PromptHandler defines the interface for handlers that support confirmation prompts. Not all handlers need prompts, so this is a separate interface.

type Prompter added in v0.29.0

type Prompter interface {
	Confirmer
	Selector
	TextInputPrompter
	MultiSelector
}

Prompter bundles the generic interactive prompts actions may need. Actions should depend on the narrowest of the embedded interfaces that covers their interaction; adapters (CLI/TUI) provide the implementation.

Implementations must return term.ErrInteractiveDisabled (possibly wrapped) when interactive prompts are not available.

type Reparent added in v0.22.0

type Reparent struct {
	Branch    string
	OldParent string
	NewParent string
}

Reparent describes a branch moving from one parent to another.

type SelectOption added in v0.29.0

type SelectOption struct {
	Label string
	Value string
}

SelectOption is one choice in a single-select prompt. Label is what the user sees; Value is what the prompt returns when the option is chosen.

type Selector added in v0.29.0

type Selector interface {
	// Select returns the Value of the chosen option. defaultIndex is the
	// option highlighted initially.
	Select(title string, options []SelectOption, defaultIndex int) (string, error)
}

Selector asks the user to pick one option.

type StepStatus

type StepStatus string

StepStatus represents the lifecycle status of a step in an action. This is the standard status type used across all action handlers.

const (
	// StatusStarted indicates a step is beginning execution.
	StatusStarted StepStatus = "started"

	// StatusCompleted indicates a step finished successfully.
	StatusCompleted StepStatus = "completed"

	// StatusSkipped indicates a step was skipped (e.g., not applicable).
	StatusSkipped StepStatus = "skipped"

	// StatusFailed indicates a step encountered an error.
	StatusFailed StepStatus = "failed"
)

Step status constants - use these across all handlers for consistency.

type TextInputPrompter added in v0.29.0

type TextInputPrompter interface {
	// TextInput returns the entered text, pre-filled with defaultValue.
	TextInput(prompt, defaultValue string) (string, error)
}

TextInputPrompter asks the user for a line of text.

Jump to

Keyboard shortcuts

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