prompt

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Opt

type Opt func(*Prompt) error

Opt accepts a reference to a Prompt and is used to modify its state

func WithReader

func WithReader(r io.Reader) Opt

WithReader returns an option func which sets a customized (non stdout) io.Reader

func WithWriter

func WithWriter(w io.Writer) Opt

WithWriter returns an option func which sets a customized (non stdout) io.Writer

type Prompt

type Prompt struct {
	PromptMessage       string // The message prompt text displayed to user
	AllowNil            bool   // If this prompt accepts nil as allowable input
	IsPassword          bool   // If set, will suppress echoing of input to terminal
	InvalidInputMessage string // Message displayed if InputValidatorFunc returns false, or nil is provided but not accepted by setting AllowNil
	DefaultAsString     string // The default value if the user just hits enter without providing input
	MapKey              string // If utilizing a PromptList, this string is used as a key in the map[string]interface{} returned by Show()

	InputValidatorFunc   validation.InputValidator      // Function which validates the input string. If both InputValidatorFunc and InputValidatorRegex are provided both are tested, and both must pass for input to be valid
	InputValidatorRegex  *regexp.Regexp                 // Regex used to validate the input
	OutputSerializerFunc serialization.OutputSerializer // Function which converts the input string into a desired type returned as interface{}

	PromptMessageDelim         string // The string/character displayed after the PromptMessage. This will default to ": "
	SuppressTrimWhitespace     bool   // By default, both leading and trailing whitespace are trimmed from all input strings, unless IsPassword is set, before validation. Setting SuppressTrimWhitespace will disable this behavior
	SuppressEchoInputOnInvalid bool   // By default, input that fails validation will echod back as part of the error message. Setting SuppressEchoInputOnInvalid will disable this behavior
	// contains filtered or unexported fields
}

Prompt The main struct that defines how a prompt is displayed and handled If both DefaultAsString and OutputSerializerFunc are set, the default string should be serializable via the OutputSerializerFunc

func (*Prompt) SetOptions

func (h *Prompt) SetOptions(opts ...Opt) error

SetOptions will iterate over all provided Opt objects and call them

func (*Prompt) Show

func (h *Prompt) Show() (interface{}, error)

Show Displays a single Prompt and will return the supplied value. Blocks forever until valid input is received

func (*Prompt) ShowWithContext added in v0.1.2

func (h *Prompt) ShowWithContext(ctx context.Context) (interface{}, error)

ShowWithContext - Same as Show but is context aware so can be canceled / timed out

type PromptList

type PromptList []Prompt

PromptList represents a collection of CliPrompts; Used by (*PromptList) Show for displaying prompts in series and collecting responses as a map

func MakePromptList

func MakePromptList(prompts ...Prompt) *PromptList

MakePromptList is a helper function used to assemble a PromptList from individual Prompt instances

func (*PromptList) Show

func (c *PromptList) Show() (map[string]interface{}, error)

Show displays all prompts in the PromptList in succession and returns all responses as a map. Blocks forever until valid input is received for all prompts

func (*PromptList) ShowWithContext

func (c *PromptList) ShowWithContext(ctx context.Context) (map[string]interface{}, error)

ShowWithContext - Same as Show but is context aware so can be canceled / timed out

Jump to

Keyboard shortcuts

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