Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrTooManyDefaultValues is returned when more than one optional default // value is provided. ErrTooManyDefaultValues = errors.New("expected at most one default value") // ErrInvalidDefaultChoice is returned when a default choice is not present in // the choices set. ErrInvalidDefaultChoice = errors.New("invalid default choice") // ErrEmptyChoices is returned when Choices is called with no choices. ErrEmptyChoices = errors.New("empty choices") // ErrSecretRequiresTTY is returned when secret input requires a terminal but // stdin is not a TTY. ErrSecretRequiresTTY = errors.New("secret input requires TTY") // ErrNilPrompter is returned when a nil Prompter is provided. ErrNilPrompter = errors.New("nil prompter") // ErrNilParser is returned when a nil parse function is provided. ErrNilParser = errors.New("nil parser") // ErrNilStdin is returned when NewWithIO receives a nil stdin reader. ErrNilStdin = errors.New("nil stdin") // ErrNilStdout is returned when NewWithIO receives a nil stdout writer. ErrNilStdout = errors.New("nil stdout") // ErrInputTooLong is returned when a single input line exceeds the maximum // accepted byte length. ErrInputTooLong = errors.New("input too long") )
Functions ¶
func PromptSecretBytes ¶
func PromptSecretBytes[T any](p Prompter, prompt string, parse ParseBytesFunc[T]) (T, error)
PromptSecretBytes prompts for secret input and parses it with parse. It uses SecretBytes with requireTTY set to false. The returned secret byte slice is zeroed after parse returns.
Types ¶
type ParseBytesFunc ¶
ParseBytesFunc parses secret byte input into a typed value.
type Prompter ¶
type Prompter interface {
// String prompts for a string value.
// If the entered value is empty (after TrimSpace) and a default is provided,
// the default is returned.
String(prompt string, defaultValue ...string) (string, error)
// SecretBytes prompts for secret input and returns it as bytes.
// On TTY stdin, input is read via term.ReadPassword (no echo).
// If requireTTY is true and stdin is not a TTY, ErrSecretRequiresTTY is returned.
// If requireTTY is false and stdin is not a TTY, one line is read up to
// maxInputLineBytes. In this mode, bufio.Reader internal buffers may retain
// secret data.
SecretBytes(prompt string, requireTTY bool) ([]byte, error)
// Choices prompts until the input matches one of the provided choices.
// If the entered value is empty (after TrimSpace) and a default is provided,
// the default is returned.
Choices(prompt string, choices []string, defaultValue ...string) (string, error)
// Int64 prompts for a signed 64-bit integer.
Int64(prompt string, defaultValue ...int64) (int64, error)
// Float64 prompts for a float64.
Float64(prompt string, defaultValue ...float64) (float64, error)
// Duration prompts for a time.Duration.
Duration(prompt string, defaultValue ...time.Duration) (time.Duration, error)
}
Click to show internal directories.
Click to hide internal directories.