userio

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInterrupted = errors.New("input was interrupted")
)
View Source
var (
	ErrValueIsNotSet = errors.New("value is not set")
)

Functions

func Required

func Required(s string) (string, error)

func ValidateFilePath

func ValidateFilePath(path string, opt FileValidatorOptions) error

Types

type FilePicker

type FilePicker struct {
	Prompt         string
	WorkingDir     string
	InitialValue   string
	ValidateAndMap ValidateAndMap[string, string]
}

func (*FilePicker) GetInput

func (ifp *FilePicker) GetInput(streams IOStreams) (string, error)

type FileValidatorOptions

type FileValidatorOptions struct {
	ExistingOnly bool
	DirsOnly     bool
	DirIsEmpty   bool
	FilesOnly    bool
	Optional     bool
}

type IOStreams

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

func NewIOStreams

func NewIOStreams(in io.Reader, out io.Writer) IOStreams

func NewIOStreamsWithInteractive

func NewIOStreamsWithInteractive(in io.Reader, out io.Writer, isInteractive bool) IOStreams

func NewTestIOStreams added in v0.23.1

func NewTestIOStreams(in io.Reader, out io.Writer, isInteractive bool) IOStreams

func (IOStreams) GetOutput

func (s IOStreams) GetOutput() io.Writer

func (IOStreams) Info

func (streams IOStreams) Info(messages ...string)

func (IOStreams) InfoE

func (streams IOStreams) InfoE(messages ...string) error

func (IOStreams) IsInteractive

func (streams IOStreams) IsInteractive() bool

func (IOStreams) Spinner

func (streams IOStreams) Spinner(message string) SpinnerHandler

type InputPrompt

type InputPrompt[V any] interface {
	GetInput(streams IOStreams) (V, error)
}

type InputSourceSwitch

type InputSourceSwitch[V, T any] struct {
	DefaultValue        Zeroable[V]
	Optional            bool
	InteractivePromptFn func() (InputPrompt[V], error)
	ValidateAndMap      ValidateAndMap[V, T]
	ErrMessage          string
	// contains filtered or unexported fields
}

func (*InputSourceSwitch[V, T]) GetValue

func (iss *InputSourceSwitch[V, T]) GetValue(streams IOStreams) (T, error)

func (*InputSourceSwitch[V, T]) Validate

func (iss *InputSourceSwitch[V, T]) Validate(streams IOStreams) error

type MultiSelect

type MultiSelect struct {
	Prompt         string
	Items          []string
	ValidateAndMap ValidateAndMap[[]string, []string]
}

func (*MultiSelect) GetInput

func (op *MultiSelect) GetInput(streams IOStreams) ([]string, error)

type SingleSelect

type SingleSelect struct {
	Prompt          string
	Items           []string
	PreselectedItem string
}

func (*SingleSelect) GetInput

func (op *SingleSelect) GetInput(streams IOStreams) (string, error)

type SpinnerHandler

type SpinnerHandler interface {
	Done()
}

type TextInput

type TextInput[V interface{}] struct {
	Prompt         string
	InitialValue   string
	Placeholder    string
	ValidateAndMap ValidateTextAndMapFn[V]
}

func (*TextInput[V]) GetInput

func (ti *TextInput[V]) GetInput(streams IOStreams) (V, error)

type ValidateAndMap

type ValidateAndMap[V, T any] func(V) (T, error)

type ValidateTextAndMapFn

type ValidateTextAndMapFn[V interface{}] func(string) (V, error)

type Zeroable

type Zeroable[V any] interface {
	Value() V
	IsZeroValue() bool
}

Zeroable this interface is required to check if a value is not set we could use simply "comparable" as generic constraint, but slices are not comparable, which makes them impossible to use. This interface abstracts helps mitigate the issue

func AsZeroable

func AsZeroable[V comparable](value V) Zeroable[V]

func AsZeroableSlice

func AsZeroableSlice[V []T, T any](value V) Zeroable[V]

Jump to

Keyboard shortcuts

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