prompt

package
v2.43.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorPasswordMismatch error when the passwords entered by a user do not match
	ErrorPasswordMismatch = fmt.Errorf("passwords do not match")
	ErrorUserCancelled    = fmt.Errorf("user cancelled input")
)
View Source
var ErrCancelAll = errors.New("cancel all")

ErrCancelAll cancel all operations

Functions

func PromptMultiLine

func PromptMultiLine(in *os.File, out *os.File, stderr io.Writer, prefix, message, defaultValue string) (string, error)

func PromptSingleLine

func PromptSingleLine(in *os.File, out *os.File, stderr io.Writer, prefix, message, defaultValue string) (string, error)

PromptSingleLine prompt on a single line

func Select

func Select(message string, options []string, defaultOption string) (string, error)

Types

type ConfirmResult

type ConfirmResult int

ConfirmResult confirm result

const (
	// ConfirmYesToAll user has selected yes to current and all future operations
	ConfirmYesToAll ConfirmResult = iota + 1

	// ConfirmYes user has selected yes to current operation
	ConfirmYes

	// ConfirmNo user has selected no to current operation
	ConfirmNo

	// ConfirmNoToAll user has selected no to current and all future operations
	ConfirmNoToAll
)

func Confirm

func Confirm(prefix, label string, target, defaultValue string, force bool) (ConfirmResult, error)

Confirm prompts for a confirmation from the user

func (ConfirmResult) FromString

func (c ConfirmResult) FromString(name string) ConfirmResult

func (ConfirmResult) String

func (c ConfirmResult) String() string

type ErrAbortAction

type ErrAbortAction struct {
	Message string
	Err     error
}

ErrAbortAction indicates that the user did not confirm an action

func (ErrAbortAction) Error

func (e ErrAbortAction) Error() string

type Prompt

type Prompt struct {
	Logger         *logger.Logger
	ShowValueAfter bool
}

Prompt used to provide various interactive prompts which can be used within the cli

func NewPrompt

func NewPrompt(l *logger.Logger) *Prompt

NewPrompt returns a new Prompt which can be used to prompt the user for different information

func (*Prompt) EncryptionPassphrase

func (p *Prompt) EncryptionPassphrase(encryptedData string, initPassphrase string, message string) (string, error)

EncryptionPassphrase prompt for the encryption passphrase, and test the passphrase against the encrypted content to see if it is valid

func (*Prompt) Input

func (p *Prompt) Input(label string, defaultValue string, required bool, hideEntered bool) (string, error)

func (*Prompt) Password

func (p *Prompt) Password(label string, message string) (string, error)

Password prompts the user for a password without confirmation

func (*Prompt) PasswordWithConfirm

func (p *Prompt) PasswordWithConfirm(label string, message string) (string, error)

PasswordWithConfirm prompts the user for a password and confirms it by getting the user to type it in again

func (*Prompt) ShowMessage

func (p *Prompt) ShowMessage(m string)

func (*Prompt) TOTPCode

func (p *Prompt) TOTPCode(host, username string, code string, client *c8y.Client, initRequest string) (string, error)

TOTPCode prompts for a TOTP code and validates using the given Cumulocity client

func (*Prompt) Username

func (p *Prompt) Username(label string, defaultValue string) (string, error)

Username prompts for a username on the console

type PromptWithPostValidate

type PromptWithPostValidate struct {
	Attempts     int
	MaxAttempts  int
	PostValidate func(string) error
	// contains filtered or unexported fields
}

func NewPromptWithPostValidate

func NewPromptWithPostValidate(p *promptui.Prompt, validate func(string) error) *PromptWithPostValidate

NewPromptWithPostValidate create a new prompt with a lazy validation function which is only run when the user hits enter.

func (*PromptWithPostValidate) IsUserCancelled

func (p *PromptWithPostValidate) IsUserCancelled(err error) bool

func (*PromptWithPostValidate) Run

func (p *PromptWithPostValidate) Run() (string, error)

Run prompts the user for input

type Validate

type Validate func(string) error

Validate function used to validate the user's input in a prompt ui

type Validator

type Validator interface {
	Validate(string) error
}

Jump to

Keyboard shortcuts

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