prompt

package
v0.0.0-...-7eaa7e1 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoForceOption = errs.New("No force option given for forced prompt")

Functions

This section is empty.

Types

type Confirm

type Confirm struct {
	*survey.Confirm
	// contains filtered or unexported fields
}

func (*Confirm) Cleanup

func (s *Confirm) Cleanup(interface{}) error

func (*Confirm) Prompt

func (s *Confirm) Prompt() (interface{}, error)

type EventDispatcher

type EventDispatcher interface {
	EventWithLabel(category, action string, label string, dim ...*dimensions.Values)
}

type Input

type Input struct {
	*survey.Input
	// contains filtered or unexported fields
}

func (*Input) Cleanup

func (i *Input) Cleanup(val interface{}) error

func (*Input) Prompt

func (i *Input) Prompt() (interface{}, error)

type Password

type Password struct {
	*survey.Password
}

func (*Password) Cleanup

func (i *Password) Cleanup(val interface{}) error

type Prompt

type Prompt struct {
	// contains filtered or unexported fields
}

Prompt is our main prompting struct

func (*Prompt) Confirm

func (p *Prompt) Confirm(title, message string, defaultChoice *bool, forcedChoice *bool) (bool, error)

Confirm prompts user for yes or no response. If the prompt is non-interactive, it returns defaultChoice. If the prompt is forced, it returns forcedChoice if not nil, or defaultChoice.

func (*Prompt) Input

func (p *Prompt) Input(title, message string, defaultResponse *string, forcedResponse *string, flags ...ValidatorFlag) (string, error)

Input prompts the user for input. The user can specify available validation flags to trigger validation of responses If the prompt is non-interactive, it returns defaultResponse. If the prompt is forced, it returns forcedResponse if not nil, or defaultResponse.

func (*Prompt) InputAndValidate

func (p *Prompt) InputAndValidate(title, message string, defaultResponse *string, forcedResponse *string, validator ValidatorFunc, flags ...ValidatorFlag) (string, error)

InputAndValidate prompts an input field and allows you to specfiy a custom validation function as well as the built in flags If the prompt is non-interactive, it returns defaultResponse. If the prompt is forced, it returns forcedResponse if not nil, or defaultResponse.

func (*Prompt) InputSecret

func (p *Prompt) InputSecret(title, message string, flags ...ValidatorFlag) (string, error)

InputSecret prompts the user for input and obfuscates the text in stdout. Will fail if empty.

func (*Prompt) IsForced

func (p *Prompt) IsForced() bool

func (*Prompt) IsInteractive

func (p *Prompt) IsInteractive() bool

IsInteractive checks if the prompts can be interactive or should just return default values

func (*Prompt) Select

func (p *Prompt) Select(title, message string, choices []string, defaultChoice *string, forcedChoice *string) (string, error)

Select prompts the user to select one entry from multiple choices. If the prompt is non-interactive, it returns defaultChoice. If the prompt is forced, it returns forcedChoice if not nil, or defaultChoice.

func (*Prompt) SetForce

func (p *Prompt) SetForce(force bool)

SetForce enables prompts to return the force value (which is often different from the non-interactive value).

func (*Prompt) SetInteractive

func (p *Prompt) SetInteractive(interactive bool)

type Prompter

type Prompter interface {
	Input(title, message string, defaultResponse *string, forcedResponse *string, flags ...ValidatorFlag) (string, error)
	InputAndValidate(title, message string, defaultResponse *string, forcedResponse *string, validator ValidatorFunc, flags ...ValidatorFlag) (string, error)
	Select(title, message string, choices []string, defaultResponse *string, forcedResponse *string) (string, error)
	Confirm(title, message string, defaultChoice *bool, forcedChoice *bool) (bool, error)
	InputSecret(title, message string, flags ...ValidatorFlag) (string, error)
	IsInteractive() bool
	SetInteractive(bool)
	SetForce(bool)
	IsForced() bool
}

Prompter is the interface used to run our prompt from

func New

New creates a new prompter

type Select

type Select struct {
	*survey.Select
	// contains filtered or unexported fields
}

func (*Select) Cleanup

func (s *Select) Cleanup(interface{}) error

func (*Select) Prompt

func (s *Select) Prompt() (interface{}, error)

type ValidatorFlag

type ValidatorFlag int

ValidatorFlag represents flags for prompt functions to change their behavior on.

const (
	// InputRequired requires that the user provide input
	InputRequired ValidatorFlag = iota
)

type ValidatorFunc

type ValidatorFunc = survey.Validator

ValidatorFunc is a function pass to the Prompter to perform validation on the users input

Jump to

Keyboard shortcuts

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