prompt

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TrimSpace

func TrimSpace(val any) any

Custom survey.Transformer that removes leading and trailing whitespace from string values. Non-string values are a no-op.

Types

type ConfirmFunc

type ConfirmFunc func(msg string, value bool, help string) (bool, error)

func NewConfirmFunc

func NewConfirmFunc(result bool, err error) ConfirmFunc

Creates a new ConfirmFunc that returns the given result and err.

func NewConfirmFuncSet

func NewConfirmFuncSet(funcs ...ConfirmFunc) ConfirmFunc

Creates a new ConfirmFunc that delegates to funcs in series.

func NewNoopConfirmFunc

func NewNoopConfirmFunc() ConfirmFunc

Creates a new ConfirmFunc that returns the default value.

type InputFunc

type InputFunc func(msg string, value string, help string) (string, error)

func NewInputFunc

func NewInputFunc(result string, err error) InputFunc

Creates a new InputFunc that returns the given result and err.

func NewInputFuncSet

func NewInputFuncSet(funcs ...InputFunc) InputFunc

Creates a new InputFunc that delegates to funcs in series.

func NewNoopInputFunc

func NewNoopInputFunc() InputFunc

Creates a new InputFunc that returns the default value.

type MultiSelectFunc

type MultiSelectFunc func(msg string, options []string, values []string, help string) ([]string, error)

func NewMultiSelectFunc

func NewMultiSelectFunc(result []string, err error) MultiSelectFunc

Creates a new SelectFunc that returns the given result and err.

func NewNoopMultiSelectFunc

func NewNoopMultiSelectFunc() MultiSelectFunc

Creates a new InputFunc that returns the default value.

type Prompter

type Prompter interface {
	// Prompt for a boolean yes/no value.
	Confirm(msg string, value bool, help string) (bool, error)
	// Prompt for single string value.
	Input(msg string, value string, help string) (string, error)
	// Prompt for a slice of string values w/ a fixed set of options.
	MultiSelect(msg string, options []string, values []string, help string) ([]string, error)
	// Prompt for single string value w/ a fixed set of options.
	Select(msg string, options []string, value string, help string) (string, error)
}

type PrompterMock

type PrompterMock struct {
	// ConfirmFunc mocks the Confirm method.
	ConfirmFunc func(msg string, value bool, help string) (bool, error)

	// InputFunc mocks the Input method.
	InputFunc func(msg string, value string, help string) (string, error)

	// MultiSelectFunc mocks the MultiSelect method.
	MultiSelectFunc func(msg string, options []string, values []string, help string) ([]string, error)

	// SelectFunc mocks the Select method.
	SelectFunc func(msg string, options []string, value string, help string) (string, error)
	// contains filtered or unexported fields
}

PrompterMock is a mock implementation of Prompter.

func TestSomethingThatUsesPrompter(t *testing.T) {

	// make and configure a mocked Prompter
	mockedPrompter := &PrompterMock{
		ConfirmFunc: func(msg string, value bool, help string) (bool, error) {
			panic("mock out the Confirm method")
		},
		InputFunc: func(msg string, value string, help string) (string, error) {
			panic("mock out the Input method")
		},
		MultiSelectFunc: func(msg string, options []string, values []string, help string) ([]string, error) {
			panic("mock out the MultiSelect method")
		},
		SelectFunc: func(msg string, options []string, value string, help string) (string, error) {
			panic("mock out the Select method")
		},
	}

	// use mockedPrompter in code that requires Prompter
	// and then make assertions.

}

func (*PrompterMock) Confirm

func (mock *PrompterMock) Confirm(msg string, value bool, help string) (bool, error)

Confirm calls ConfirmFunc.

func (*PrompterMock) ConfirmCalls

func (mock *PrompterMock) ConfirmCalls() []struct {
	Msg   string
	Value bool
	Help  string
}

ConfirmCalls gets all the calls that were made to Confirm. Check the length with:

len(mockedPrompter.ConfirmCalls())

func (*PrompterMock) Input

func (mock *PrompterMock) Input(msg string, value string, help string) (string, error)

Input calls InputFunc.

func (*PrompterMock) InputCalls

func (mock *PrompterMock) InputCalls() []struct {
	Msg   string
	Value string
	Help  string
}

InputCalls gets all the calls that were made to Input. Check the length with:

len(mockedPrompter.InputCalls())

func (*PrompterMock) MultiSelect

func (mock *PrompterMock) MultiSelect(msg string, options []string, values []string, help string) ([]string, error)

MultiSelect calls MultiSelectFunc.

func (*PrompterMock) MultiSelectCalls

func (mock *PrompterMock) MultiSelectCalls() []struct {
	Msg     string
	Options []string
	Values  []string
	Help    string
}

MultiSelectCalls gets all the calls that were made to MultiSelect. Check the length with:

len(mockedPrompter.MultiSelectCalls())

func (*PrompterMock) Select

func (mock *PrompterMock) Select(msg string, options []string, value string, help string) (string, error)

Select calls SelectFunc.

func (*PrompterMock) SelectCalls

func (mock *PrompterMock) SelectCalls() []struct {
	Msg     string
	Options []string
	Value   string
	Help    string
}

SelectCalls gets all the calls that were made to Select. Check the length with:

len(mockedPrompter.SelectCalls())

type SelectFunc

type SelectFunc func(msg string, options []string, value string, help string) (string, error)

func NewNoopSelectFunc

func NewNoopSelectFunc() SelectFunc

Creates a new InputFunc that returns the default value.

func NewSelectFunc

func NewSelectFunc(result string, err error) SelectFunc

Creates a new SelectFunc that returns the given result and err.

func NewSelectFuncSet

func NewSelectFuncSet(funcs ...SelectFunc) SelectFunc

Creates a new SelectFunc that delegates to funcs in series.

type SurveyPrompter

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

func NewSurveyPrompter

func NewSurveyPrompter(in fileReader, out fileWriter, err fileWriter, ios ioSession) *SurveyPrompter

func (*SurveyPrompter) Confirm

func (p *SurveyPrompter) Confirm(prompt string, defaultValue bool, help string) (bool, error)

func (*SurveyPrompter) Input

func (p *SurveyPrompter) Input(prompt string, defaultValue string, help string) (string, error)

func (*SurveyPrompter) MultiSelect

func (p *SurveyPrompter) MultiSelect(
	prompt string, options []string, defaultValues []string, help string,
) ([]string, error)

func (*SurveyPrompter) Select

func (p *SurveyPrompter) Select(
	prompt string, options []string, defaultValue string, help string,
) (string, error)

Jump to

Keyboard shortcuts

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