survey

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("survey: not implemented")

ErrNotImplemented is the error returned if a method is not implemented.

Functions

func TransformOnlyId

func TransformOnlyId(answer interface{}) interface{}

TransformOnlyId is a `Transformer`. It receives an answer value and returns a copy of the answer with only the first word, which expected to be the ID of the resource.

func ValidateInt64

func ValidateInt64(answer interface{}) error

Types

type Input

type Input struct {
	Message   string
	Help      string
	Default   interface{}
	Required  bool
	Validate  Validator
	Transform Transformer
}

Input holds the configuration for input prompt.

type Interface

type Interface interface {
	// InputString gets an answer to a prompt from a user's free-form input.
	InputString(input *Input) (string, error)

	// InputInt gets an answer to a prompt from a user's free-form input.
	InputInt64(input *Input) (int64, error)

	// InputFloat64 gets an answer to a prompt from a user's free-form input.
	InputFloat64(input *Input) (float64, error)

	// Password gets a password (via hidden input) from a user's free-form input.
	Password(input *Input) (string, error)

	// Confirm prompts the user to confirm something.
	Confirm(input *Input) (bool, error)

	// Select gets the user to select an option from a list of options.
	Select(input *Select) (string, error)

	// SelectMulti gets the user to select multiple selections from a list of options.
	SelectMulti(input *Select) ([]string, error)
}

Interface defines the interface of a survey prompter.

func New

func New(in io.Reader, out, err io.Writer) Interface

New returns a new survey interface.

type Select

type Select struct {
	Message   string
	Help      string
	Defaults  []interface{}
	Options   []interface{}
	Validate  Validator
	Transform Transformer
}

Select holds the configuration for both select and multi-select prompts.

type Survey

type Survey struct {
	// In, Out, and Err represent the respective data streams that the survey
	// may act upon. They are attached directly to each prompt.
	In  terminal.FileReader
	Out terminal.FileWriter
	Err io.Writer
}

Survey holds the configuration for the survey.

func (*Survey) Confirm

func (x *Survey) Confirm(input *Input) (bool, error)

func (*Survey) InputFloat64

func (x *Survey) InputFloat64(input *Input) (float64, error)

func (*Survey) InputInt64

func (x *Survey) InputInt64(input *Input) (int64, error)

func (*Survey) InputString

func (x *Survey) InputString(input *Input) (string, error)

func (*Survey) Password

func (x *Survey) Password(input *Input) (string, error)

func (*Survey) Select

func (x *Survey) Select(input *Select) (string, error)

func (*Survey) SelectMulti

func (x *Survey) SelectMulti(input *Select) ([]string, error)

type Transformer

type Transformer func(answer interface{}) (newAnswer interface{})

Transformer is a function used to implement a custom logic that will result to return a different representation of the given answer.

type Validator

type Validator func(answer interface{}) error

Validator is a function used to validate a response. If the function returns an error, then the user will be prompted again for another response.

Jump to

Keyboard shortcuts

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