Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Opt ¶
Opt accepts a reference to a Prompt and is used to modify its state
func WithReader ¶
WithReader returns an option func which sets a customized (non stdout) io.Reader
func WithWriter ¶
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 ¶
SetOptions will iterate over all provided Opt objects and call them
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