Documentation ¶
Overview ¶
Package prompt provides functionality to retrieve free-form text, selection, and confirmation input from the user via a terminal.
Index ¶
- Variables
- func RequireNonEmpty(v interface{}) error
- type Option
- type Prompt
- func (p Prompt) Confirm(message, help string, promptCfgs ...PromptConfig) (bool, error)
- func (p Prompt) Get(message, help string, validator ValidatorFunc, promptOpts ...PromptConfig) (string, error)
- func (p Prompt) GetSecret(message, help string, promptOpts ...PromptConfig) (string, error)
- func (p Prompt) MultiSelect(message, help string, options []string, validator ValidatorFunc, ...) ([]string, error)
- func (p Prompt) SelectOne(message, help string, options []string, promptCfgs ...PromptConfig) (string, error)
- func (p Prompt) SelectOption(message, help string, opts []Option, promptCfgs ...PromptConfig) (value string, err error)
- type PromptConfig
- type ValidatorFunc
Constants ¶
This section is empty.
Variables ¶
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 Prompt ¶
type Prompt func(survey.Prompt, interface{}, ...survey.AskOpt) error
Prompt abstracts the survey.Askone function.
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.