prompt

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package prompt provides interactive CLI prompts for user input.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoResources        = errors.New("no resources to select from")
	ErrInvalidSelection   = errors.New("invalid selection")
	ErrSelectionCancelled = errors.New("selection cancelled")
)

Sentinel errors for resource selection.

Functions

func SelectResourceDefault

func SelectResourceDefault(query string, resources []resource.Resource) (*resource.Resource, error)

SelectResourceDefault is a convenience function that uses stdin/stdout.

Types

type Selector

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

Selector handles interactive resource selection prompts.

func NewSelector

func NewSelector() *Selector

NewSelector creates a new Selector using stdin and stdout.

func NewSelectorWithIO

func NewSelectorWithIO(r io.Reader, w io.Writer) *Selector

NewSelectorWithIO creates a Selector with custom reader and writer for testing.

func (*Selector) SelectResource

func (s *Selector) SelectResource(query string, resources []resource.Resource) (*resource.Resource, error)

SelectResource prompts the user to choose from a list of resources.

Returns:

  • ErrNoResources if the list is empty
  • The resource if only one exists (auto-selects without prompting)
  • The selected resource based on user input
  • ErrInvalidSelection if the selection is out of range
  • ErrSelectionCancelled if input is EOF (e.g., Ctrl+D)

Jump to

Keyboard shortcuts

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