prompt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package prompt provides a set of functions to prompt the user to enter a value.

Index

Constants

View Source
const (
	// Nanosecond timeUnit = "ns"
	Nanosecond timeUnit = "ns"
	// Microsecond timeUnit = "us"
	Microsecond timeUnit = "us"
	// Millisecond timeUnit = "ms"
	Millisecond timeUnit = "ms"
	// Second timeUnit = "s"
	Second timeUnit = "s"
	// Minute timeUnit = "m"
	Minute timeUnit = "m"
	// Hour timeUnit = "h"
	Hour timeUnit = "h"
	// Day timeUnit = "d"
	Day timeUnit = "d"
	// Week timeUnit = "w"
	Week timeUnit = "w"
	// Month timeUnit = "M"
	Month timeUnit = "M"
	// Year timeUnit = "y"
	Year timeUnit = "y"
)

Variables

View Source
var (
	// ErrorMaxAttemptExceeded is returned when the maximum number of attempts is exceeded.
	ErrorMaxAttemptExceeded = fmt.Errorf("max attempts exceeded")
	// ErrorPasswordMismatch is returned when the password and the confirmation password do not match.
	ErrorPasswordMismatch = fmt.Errorf("password mismatch")
	// ErrorTimeDurationFormat is returned when the time duration format is invalid.
	ErrorTimeDurationFormat = fmt.Errorf("invalid time duration format")
	// ErrorTimeFormat is returned when the time format is invalid.
	ErrorTimeFormat = fmt.Errorf("invalid time format")
	// ErrorNumberFormat is returned when the number format is invalid.
	ErrorNumberFormat = fmt.Errorf("invalid number format")
)

Functions

func Bool

func Bool(label string) (bool, error)

Bool prompts the user to enter a boolean value.

func Duration

func Duration(
	label string,
	timeUnit timeUnit,
	maxAttempts int,
	promptAgainCallback AgainCallback,
	isConfirm bool,
) (time.Duration, error)

Duration prompts the user to enter a duration.

func Number

func Number(
	label string,
	maxAttempts int,
	promptAgainCallback AgainCallback,
	isConfirm bool,
) (int, error)

Number prompts the user to enter a number.

func Password

func Password(
	label string,
	confirmLabel string,
	maxAttempts int,
	promptAgainCallback AgainCallback,
	isConfirm bool,
) (string, error)

Password prompts the user to enter a password.

func Select

func Select(
	label string,
	items []string,
) (string, error)

Select prompts the user to select an item from a list.

func Text

func Text(
	label string,
	isConfirm bool,
) (string, error)

Text prompts the user to enter a text.

func Time

func Time(
	label string,
	layout string,
	maxAttempts int,
	promptAgainCallback AgainCallback,
	isConfirm bool,
) (time.Time, error)

Time prompts the user to enter a time.

Types

type AgainCallback

type AgainCallback func(error) bool

AgainCallback is a callback function that is called when the user needs to be prompted again.

Jump to

Keyboard shortcuts

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