prompter

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PromptForConfirmation deprecated

func PromptForConfirmation(in io.Reader, message string) bool

PromptForConfirmation prompts the user for y/N confirmation. Uses the provided reader for input (pass cmd.InOrStdin() for testability). Returns true only for "y" or "Y", false for anything else including errors. Writes prompt to stderr (not stdout) to preserve stdout for data output.

Deprecated: Use Prompter.Confirm() instead for better testability.

Types

type PromptConfig

type PromptConfig struct {
	Message   string
	Default   string
	Required  bool
	Validator func(string) error
}

PromptConfig configures a string prompt.

type Prompter

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

Prompter provides interactive prompting functionality. It uses IOStreams for testable I/O.

func NewPrompter

func NewPrompter(ios *iostreams.IOStreams) *Prompter

NewPrompter creates a new Prompter with the given IOStreams.

func (*Prompter) Confirm

func (p *Prompter) Confirm(message string, defaultYes bool) (bool, error)

Confirm prompts the user for a yes/no confirmation. In non-interactive mode, returns the default without prompting.

func (*Prompter) Select

func (p *Prompter) Select(message string, options []SelectOption, defaultIdx int) (int, error)

Select prompts the user to select from a list of options. Returns the index of the selected option. In non-interactive mode, returns the defaultIdx without prompting.

func (*Prompter) String

func (p *Prompter) String(cfg PromptConfig) (string, error)

String prompts the user for a string value. Returns the default if the user enters nothing. In non-interactive mode, returns the default without prompting.

type SelectOption

type SelectOption struct {
	Label       string
	Description string
}

SelectOption represents an option in a selection prompt.

Jump to

Keyboard shortcuts

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