prompt

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package prompt provides functionality to retrieve free-form text, selection, and confirmation input from the user via a terminal.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyOptions = errors.New("list of provided options is empty")

ErrEmptyOptions indicates the input options list was empty.

Functions

func RequireNonEmpty added in v0.3.0

func RequireNonEmpty(v interface{}) error

RequireNonEmpty returns an error if v is a zero-value.

Types

type Option

type Option struct {
	Value string
	Hint  string
}

Option represents a choice with a hint for clarification.

func (Option) String added in v1.5.0

func (o Option) String() string

String implements the fmt.Stringer interface.

type Prompt

type Prompt func(survey.Prompt, interface{}, ...survey.AskOpt) error

Prompt abstracts the survey.Askone function.

func New

func New() Prompt

New returns a Prompt with default configuration.

func (Prompt) Confirm

func (p Prompt) Confirm(message, help string, promptCfgs ...PromptConfig) (bool, error)

Confirm prompts the user with a yes/no option.

func (Prompt) Get

func (p Prompt) Get(message, help string, validator ValidatorFunc, promptOpts ...PromptConfig) (string, error)

Get prompts the user for free-form text input.

func (Prompt) GetSecret

func (p Prompt) GetSecret(message, help string, promptOpts ...PromptConfig) (string, error)

GetSecret prompts the user for sensitive input. Wraps survey.Password

func (Prompt) MultiSelect

func (p Prompt) MultiSelect(message, help string, options []string, validator ValidatorFunc, promptCfgs ...PromptConfig) ([]string, error)

MultiSelect prompts the user with a list of options to choose from with the arrow keys and enter key.

func (Prompt) SelectOne

func (p Prompt) SelectOne(message, help string, options []string, promptCfgs ...PromptConfig) (string, error)

SelectOne prompts the user with a list of options to choose from with the arrow keys.

func (Prompt) SelectOption added in v1.5.0

func (p Prompt) SelectOption(message, help string, opts []Option, promptCfgs ...PromptConfig) (value string, err error)

SelectOption prompts the user to select one option from options and returns the Value of the option.

type PromptConfig added in v1.5.0

type PromptConfig func(*prompt)

PromptConfig is a functional option to configure the prompt.

func WithConfirmFinalMessage added in v1.10.0

func WithConfirmFinalMessage() PromptConfig

WithConfirmFinalMessage sets a short final message for to confirm the user's input.

func WithDefaultInput

func WithDefaultInput(s string) PromptConfig

WithDefaultInput sets a default message for an input prompt.

func WithDefaultSelections added in v1.14.0

func WithDefaultSelections(options []string) PromptConfig

WithDefaultSelections selects the options to be checked by default for a multiselect prompt.

func WithFinalMessage

func WithFinalMessage(msg string) PromptConfig

WithFinalMessage sets a final message that replaces the question prompt once the user enters an answer.

func WithTrueDefault

func WithTrueDefault() PromptConfig

WithTrueDefault sets the default for a confirm prompt to true.

type ValidatorFunc

type ValidatorFunc func(interface{}) error

ValidatorFunc defines the function signature for validating inputs.

func RequireMinItems added in v1.14.0

func RequireMinItems(min int) ValidatorFunc

RequireMinItems enforces at least min elements to be selected from MultiSelect.

Jump to

Keyboard shortcuts

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