Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type NoopPrompter ¶
type NoopPrompter struct{}
NoopPrompter always returns defaults. Used for non-TTY, CI, and --yes flag.
func (NoopPrompter) Confirm ¶
func (NoopPrompter) Confirm(_ string, defaultVal bool) (bool, error)
Confirm returns the default value.
type Prompter ¶
type Prompter interface {
// Text prompts for a text value with a default.
// Displays: " label: (defaultVal) "
// Returns defaultVal if user enters empty string.
Text(label, defaultVal string) (string, error)
// Confirm prompts for a yes/no with a default.
// Displays: " label [Y/n] " or " label [y/N] "
// Returns defaultVal if user enters empty string.
Confirm(label string, defaultVal bool) (bool, error)
// Select prompts the user to choose from a numbered list.
// Displays each option with a 1-based index, returns the 0-based selected index.
// Returns defaultIdx if user enters empty string.
Select(label string, options []string, defaultIdx int) (int, error)
}
Prompter abstracts interactive input for testability.
func DefaultPrompter ¶
func DefaultPrompter() Prompter
DefaultPrompter returns a TTYPrompter if stdin is a terminal, else NoopPrompter.
type TTYPrompter ¶
type TTYPrompter struct {
// contains filtered or unexported fields
}
TTYPrompter reads from a reader (typically os.Stdin).
func (*TTYPrompter) Confirm ¶
func (p *TTYPrompter) Confirm(label string, defaultVal bool) (bool, error)
Confirm prompts for yes/no.
Click to show internal directories.
Click to hide internal directories.