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 ¶
- type AutoConfirmPromptHandler
- type Base
- type ConfirmPromptHandler
- type Confirmer
- type MultiSelector
- type NonInteractivePrompter
- type NullBase
- type NullProgress
- type NullPromptHandler
- type ProgressHandler
- type PromptHandler
- type Prompter
- type Reparent
- type SelectOption
- type Selector
- type StepStatus
- type TextInputPrompter
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
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 utils.ErrInteractiveDisabled, matching what an interactive prompt does under --no-interactive or without a TTY.
func (NonInteractivePrompter) Confirm ¶ added in v0.29.0
func (NonInteractivePrompter) Confirm(string, bool) (bool, error)
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
func (NonInteractivePrompter) Select(string, []SelectOption, int) (string, error)
Select implements Selector.
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 ¶
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 utils.ErrInteractiveDisabled (possibly wrapped) when interactive prompts are not available.
type SelectOption ¶ added in v0.29.0
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.