prompt

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: Apache-2.0 Imports: 7 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 func(*prompt)

Option is a functional option to configure the prompt.

func WithDefaultInput

func WithDefaultInput(s string) Option

WithDefaultInput sets a default message for an input prompt.

func WithFinalMessage

func WithFinalMessage(msg string) Option

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

func WithTrueDefault

func WithTrueDefault() Option

WithTrueDefault sets the default for a confirm prompt to true.

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, promptOpts ...Option) (bool, error)

Confirm prompts the user with a yes/no option.

func (Prompt) Get

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

Get prompts the user for free-form text input.

func (Prompt) GetSecret

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

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

func (Prompt) MultiSelect

func (p Prompt) MultiSelect(message, help string, options []string, promptOpts ...Option) ([]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, promptOpts ...Option) (string, error)

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

type ValidatorFunc

type ValidatorFunc func(interface{}) error

ValidatorFunc defines the function signature for validating inputs.

Jump to

Keyboard shortcuts

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