Documentation
¶
Overview ¶
Package prompter is a simple user prompter that asks users for input data or confirmations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultConfirmationChoices is the default value for the choices that are given to // the users in a confirmation prompt. DefaultConfirmationChoices = []string{"y", "n"} )
Functions ¶
func DefaultConfirmation ¶
DefaultConfirmation is a confirmation parser that covers most cases for confirmation. It converts y/Y/yes/YES/t/T/true/True/1 to true. It converts n/N/no/NO/f/F/false/FALSE/0 to false.
Types ¶
type Confirmation ¶
type Confirmation struct {
// The label that will be prompted to the user.
// Example: `Are you sure?`
Label string
// The choices that will be presented to the user.
// Example: `Y/n`. (A good practice is to uppercase
// the default value, if there is one).
Choices []string
// EnableDefaultValue tells the prompter whether or not
// there is a default value that will be used when the
// user doesn't input any data.
EnableDefaultValue bool
// DefaultValue is the default value that will be used when
// the user doesn't input any data, if EnableDefaultValue
// is set to true OR that the prompter is set to not
// interactive.
DefaultValue bool
// The parser that will be used to convert the user's input
// into a true/false value.
Parser ConfirmationParser
}
Confirmation represents a confirmation prompt's configuration.
type ConfirmationParser ¶
ConfirmationParser is a function that parses an input and returns a confirmation value as well as an error, if the input can't be parsed.
type Prompter ¶
type Prompter struct {
// contains filtered or unexported fields
}
Prompter prompts users to let them input data, and parses it.
func New ¶
New instantiates a new prompter which will prompt users on the writer and read their output from the reader. The interactive boolean makes all prompts return a default value if set to false, and won't prompt them. This should be used if your users are not in a TTY and can't write to answer to the prompt.