Documentation
¶
Overview ¶
Package surveyexpect provides expects for github.com/AlecAivazis/survey.
Index ¶
- Variables
- func IsIgnoredError(err error) bool
- func IsInterrupted(err error) bool
- func IsNothingTodo(err error) bool
- func WaitForReaction() <-chan time.Time
- type Action
- type Answer
- type Buffer
- type ConfirmAnswer
- type ConfirmPrompt
- func (c *ConfirmPrompt) Answer(answer string) *ConfirmAnswer
- func (c *ConfirmPrompt) Do(console Console) error
- func (c *ConfirmPrompt) Interrupt()
- func (c *ConfirmPrompt) No()
- func (c *ConfirmPrompt) ShowHelp(help string, options ...string)
- func (c *ConfirmPrompt) String() string
- func (c *ConfirmPrompt) Yes()
- type Console
- type ExpectOption
- type Expector
- type HelpAction
- type HelpAnswer
- type InlineSteps
- type InputAnswer
- type InputPrompt
- func (p *InputPrompt) Answer(answer string) *InputAnswer
- func (p *InputPrompt) Do(c Console) error
- func (p *InputPrompt) Interrupt()
- func (p *InputPrompt) Once() *InputPrompt
- func (p *InputPrompt) ShowHelp(help string, options ...string)
- func (p *InputPrompt) String() string
- func (p *InputPrompt) Tab(times ...int) *InputSuggestionSteps
- func (p *InputPrompt) Times(i int) *InputPrompt
- func (p *InputPrompt) Twice() *InputPrompt
- func (p *InputPrompt) Type(s string) *InputSuggestionSteps
- type InputSuggestionSteps
- func (a *InputSuggestionSteps) Delete(times ...int) *InputSuggestionSteps
- func (a *InputSuggestionSteps) Do(c Console) error
- func (a *InputSuggestionSteps) Enter()
- func (a *InputSuggestionSteps) Esc() *InputSuggestionSteps
- func (a *InputSuggestionSteps) ExpectSuggestions(suggestions ...string) *InputSuggestionSteps
- func (a *InputSuggestionSteps) Interrupt() *InputSuggestionSteps
- func (a *InputSuggestionSteps) MoveDown(times ...int) *InputSuggestionSteps
- func (a *InputSuggestionSteps) MoveUp(times ...int) *InputSuggestionSteps
- func (a *InputSuggestionSteps) String() string
- func (a *InputSuggestionSteps) Tab(times ...int) *InputSuggestionSteps
- func (a *InputSuggestionSteps) Type(s string) *InputSuggestionSteps
- type InterruptAnswer
- type MultiSelectExpect
- type MultiSelectPrompt
- func (p *MultiSelectPrompt) Delete(times ...int) *MultiSelectPrompt
- func (p *MultiSelectPrompt) Do(c Console) error
- func (p *MultiSelectPrompt) Enter()
- func (p *MultiSelectPrompt) ExpectOptions(options ...string) *MultiSelectPrompt
- func (p *MultiSelectPrompt) Interrupt()
- func (p *MultiSelectPrompt) MoveDown(times ...int) *MultiSelectPrompt
- func (p *MultiSelectPrompt) MoveUp(times ...int) *MultiSelectPrompt
- func (p *MultiSelectPrompt) Select() *MultiSelectPrompt
- func (p *MultiSelectPrompt) SelectAll() *MultiSelectPrompt
- func (p *MultiSelectPrompt) SelectNone() *MultiSelectPrompt
- func (p *MultiSelectPrompt) ShowHelp(help string, options ...string) *MultiSelectPrompt
- func (p *MultiSelectPrompt) String() string
- func (p *MultiSelectPrompt) Tab(times ...int) *MultiSelectPrompt
- func (p *MultiSelectPrompt) Type(s string) *MultiSelectPrompt
- type MultilineAnswer
- type MultilinePrompt
- func (p *MultilinePrompt) Answer(answer string) *MultilineAnswer
- func (p *MultilinePrompt) Do(c Console) error
- func (p *MultilinePrompt) Interrupt()
- func (p *MultilinePrompt) Once() *MultilinePrompt
- func (p *MultilinePrompt) String() string
- func (p *MultilinePrompt) Times(i int) *MultilinePrompt
- func (p *MultilinePrompt) Twice() *MultilinePrompt
- type NoAnswer
- type PasswordAnswer
- type PasswordPrompt
- func (p *PasswordPrompt) Answer(answer string) *PasswordAnswer
- func (p *PasswordPrompt) Do(c Console) error
- func (p *PasswordPrompt) Interrupt()
- func (p *PasswordPrompt) Once() *PasswordPrompt
- func (p *PasswordPrompt) ShowHelp(help string, options ...string)
- func (p *PasswordPrompt) String() string
- func (p *PasswordPrompt) Times(i int) *PasswordPrompt
- func (p *PasswordPrompt) Twice() *PasswordPrompt
- type Prompt
- type SelectExpect
- type SelectPrompt
- func (p *SelectPrompt) Delete(times ...int) *SelectPrompt
- func (p *SelectPrompt) Do(c Console) error
- func (p *SelectPrompt) Enter()
- func (p *SelectPrompt) ExpectOptions(options ...string) *SelectPrompt
- func (p *SelectPrompt) Interrupt()
- func (p *SelectPrompt) MoveDown(times ...int) *SelectPrompt
- func (p *SelectPrompt) MoveUp(times ...int) *SelectPrompt
- func (p *SelectPrompt) ShowHelp(help string, options ...string) *SelectPrompt
- func (p *SelectPrompt) String() string
- func (p *SelectPrompt) Tab(times ...int) *SelectPrompt
- func (p *SelectPrompt) Type(s string) *SelectPrompt
- type Signal
- type Step
- type Steps
- func (s *Steps) Append(more ...Step) *Steps
- func (s *Steps) Close()
- func (s *Steps) Do(c Console) error
- func (s *Steps) DoFirst(c Console) error
- func (s *Steps) ExpectationsWereMet() error
- func (s *Steps) HasNothingToDo() bool
- func (s *Steps) Len() int
- func (s *Steps) Reset()
- func (s *Steps) String() string
- type StringExpect
- type StringWriter
- type Survey
- func (s *Survey) Expect(c Console) error
- func (s *Survey) ExpectConfirm(message string) *ConfirmPrompt
- func (s *Survey) ExpectInput(message string) *InputPrompt
- func (s *Survey) ExpectMultiSelect(message string) *MultiSelectPrompt
- func (s *Survey) ExpectMultiline(message string) *MultilinePrompt
- func (s *Survey) ExpectPassword(message string) *PasswordPrompt
- func (s *Survey) ExpectSelect(message string) *SelectPrompt
- func (s *Survey) ExpectationsWereMet() error
- func (s *Survey) ResetExpectations()
- func (s *Survey) Start(fn func(stdio terminal.Stdio))
- func (s *Survey) WithTimeout(t time.Duration) *Survey
- type TestingT
- type TypeAnswer
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNothingToDo indicates that there is nothing to do. ErrNothingToDo = errors.New("nothing to do") // ErrNotFinished indicates that the step is not finished. ErrNotFinished = errors.New("step is not finished") // ErrSequenceClosed indicates that the step is closed and does not take more action. ErrSequenceClosed = errors.New("sequence is closed") )
var ReactionTime = 10 * time.Millisecond
ReactionTime is to create a small delay to simulate human reaction.
Functions ¶
func IsIgnoredError ¶
IsIgnoredError checks whether the error is ignored.
func IsInterrupted ¶
IsInterrupted checks if the error is terminal.InterruptErr or not.
func IsNothingTodo ¶
IsNothingTodo checks if the error is ErrNothingToDo or not.
func WaitForReaction ¶
WaitForReaction creates a small delay to simulate human reaction.
Types ¶
type Action ¶
type Action struct {
// contains filtered or unexported fields
}
Action sends an action.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a goroutine safe bytes.Buffer.
func (*Buffer) Reset ¶
func (b *Buffer) Reset()
Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes. Reset is the same as Truncate(0).
type ConfirmAnswer ¶
type ConfirmAnswer struct {
// contains filtered or unexported fields
}
ConfirmAnswer is an answer for confirm question.
func (*ConfirmAnswer) Do ¶
func (a *ConfirmAnswer) Do(c Console) error
Do runs the step. nolint: errcheck,gosec
func (*ConfirmAnswer) Interrupted ¶
func (a *ConfirmAnswer) Interrupted()
Interrupted expects the answer will be interrupted.
func (*ConfirmAnswer) String ¶
func (a *ConfirmAnswer) String() string
String represents the answer as a string.
type ConfirmPrompt ¶
type ConfirmPrompt struct {
// contains filtered or unexported fields
}
ConfirmPrompt is an expectation of survey.Confirm.
func (*ConfirmPrompt) Answer ¶
func (c *ConfirmPrompt) Answer(answer string) *ConfirmAnswer
Answer sets a custom answer to the prompt.
If the answer is not not empty, the survey expects to have a feedback from the prompt:
`Sorry, your reply was invalid: "hello world!" is not a valid answer, please try again.` Survey.ExpectConfirm("Are you sure to delete this file?"). Answer("hello world!").
func (*ConfirmPrompt) Interrupt ¶
func (c *ConfirmPrompt) Interrupt()
Interrupt marks the answer is interrupted.
Survey.ExpectConfirm("Are you sure to delete this file?"). Interrupt().
func (*ConfirmPrompt) No ¶
func (c *ConfirmPrompt) No()
No sets "no" as the answer to the prompt.
Survey.ExpectConfirm("Are you sure to delete this file?"). No().
func (*ConfirmPrompt) ShowHelp ¶
func (c *ConfirmPrompt) ShowHelp(help string, options ...string)
ShowHelp sets help for the expectation.
Survey.ExpectConfirm("Are you sure to delete this file?"). ShowHelp("The file will be permanently deleted").
func (*ConfirmPrompt) String ¶
func (c *ConfirmPrompt) String() string
String represents the expectation as a string.
func (*ConfirmPrompt) Yes ¶
func (c *ConfirmPrompt) Yes()
Yes sets "yes" as the answer to the prompt.
Survey.ExpectConfirm("Are you sure to delete this file?"). Yes().
type Console ¶
type Console interface { // terminal device. Tty() *os.File // pty. Fd() uintptr // Close closes Console's tty. Calling Close will unblock Expect and ExpectEOF. Close() error // Send writes string s to Console's tty. Send(s string) (int, error) // SendLine writes string s to Console's tty with a trailing newline. SendLine(s string) (int, error) // Expectf reads from the Console's tty until the provided formatted string // is read or an error occurs, and returns the buffer read by Console. Expectf(format string, args ...interface{}) (string, error) // ExpectString reads from Console's tty until the provided string is read or // an error occurs, and returns the buffer read by Console. ExpectString(s string) (string, error) // ExpectEOF reads from Console's tty until EOF or an error occurs, and returns // the buffer read by Console. We also treat the PTSClosed error as an EOF. ExpectEOF() (string, error) // Expect reads from Console's tty until a condition specified from opts is // encountered or an error occurs, and returns the buffer read by console. // No extra bytes are read once a condition is met, so if a program isn't // expecting input yet, it will be blocked. Sends are queued up in tty's // internal buffer so that the next Expect will read the remaining bytes (i.e. // rest of prompt) as well as its conditions. Expect(opts ...expect.ExpectOpt) (string, error) }
Console is an interface wrapper around *expect.Console.
type Expector ¶
Expector exp survey.
func Expect ¶
func Expect(options ...ExpectOption) Expector
Expect creates an expected survey with expectations and assures that ExpectationsWereMet() is called.
type HelpAction ¶
type HelpAction struct {
// contains filtered or unexported fields
}
HelpAction sends a ? to show the help.
func (*HelpAction) Do ¶
func (a *HelpAction) Do(c Console) error
Do runs the step. nolint: errcheck,gosec
func (*HelpAction) String ¶
func (a *HelpAction) String() string
String represents the answer as a string.
type HelpAnswer ¶
type HelpAnswer struct {
// contains filtered or unexported fields
}
HelpAnswer sends a ? to show the help.
func (*HelpAnswer) Do ¶
func (a *HelpAnswer) Do(c Console) error
Do runs the step. nolint: errcheck,gosec
func (*HelpAnswer) String ¶
func (a *HelpAnswer) String() string
String represents the answer as a string.
type InlineSteps ¶
type InlineSteps struct {
*Steps
}
InlineSteps is for internal steps and they are part of an expectation.
func (*InlineSteps) String ¶
func (s *InlineSteps) String() string
String represents the answer as a string.
type InputAnswer ¶
type InputAnswer struct {
// contains filtered or unexported fields
}
InputAnswer is an answer for password question.
func (*InputAnswer) Do ¶
func (a *InputAnswer) Do(c Console) error
Do runs the step. nolint: errcheck,gosec
func (*InputAnswer) Interrupted ¶
func (a *InputAnswer) Interrupted()
Interrupted expects the answer will be interrupted.
func (*InputAnswer) String ¶
func (a *InputAnswer) String() string
String represents the answer as a string.
type InputPrompt ¶
type InputPrompt struct {
// contains filtered or unexported fields
}
InputPrompt is an expectation of survey.Input.
func (*InputPrompt) Answer ¶
func (p *InputPrompt) Answer(answer string) *InputAnswer
Answer sets the answer to the input prompt.
Survey.ExpectInput("Enter your name:"). Answer("johnny")
func (*InputPrompt) Interrupt ¶
func (p *InputPrompt) Interrupt()
Interrupt marks the answer is interrupted.
Survey.ExpectInput("Enter your name:"). Interrupt()
func (*InputPrompt) Once ¶
func (p *InputPrompt) Once() *InputPrompt
Once indicates that the message should only be asked once.
Survey.ExpectInput("Enter your name:"). Answer("johnny"). Once()
func (*InputPrompt) ShowHelp ¶
func (p *InputPrompt) ShowHelp(help string, options ...string)
ShowHelp sets help for the expectation.
Survey.ExpectInput("Enter your name:"). ShowHelp("It's your full name")
func (*InputPrompt) String ¶
func (p *InputPrompt) String() string
String represents the expectation as a string.
func (*InputPrompt) Tab ¶
func (p *InputPrompt) Tab(times ...int) *InputSuggestionSteps
Tab starts a sequence of steps to interact with suggestion mode. Default is 1 when omitted.
Survey.ExpectInput("Enter your name:"). Tab()
func (*InputPrompt) Times ¶
func (p *InputPrompt) Times(i int) *InputPrompt
Times indicates that the message should only be asked the indicated number of times.
Survey.ExpectInput("Enter your name:"). Answer("johnny"). Times(5)
func (*InputPrompt) Twice ¶
func (p *InputPrompt) Twice() *InputPrompt
Twice indicates that the message should only be asked twice.
Survey.ExpectInput("Enter your name:"). Answer("johnny"). Twice()
func (*InputPrompt) Type ¶
func (p *InputPrompt) Type(s string) *InputSuggestionSteps
Type starts a sequence of steps to interact with suggestion mode.
Survey.ExpectInput("Enter your name:"). Type("johnny")
type InputSuggestionSteps ¶
type InputSuggestionSteps struct {
// contains filtered or unexported fields
}
InputSuggestionSteps is a sequence of steps when user is in suggestion mode.
func (*InputSuggestionSteps) Delete ¶
func (a *InputSuggestionSteps) Delete(times ...int) *InputSuggestionSteps
Delete sends the DELETE key the indicated times. Default is 1 when omitted.
Survey.ExpectInput("Enter your name:"). Type("johnny"). Delete(5)
func (*InputSuggestionSteps) Do ¶
func (a *InputSuggestionSteps) Do(c Console) error
Do runs the step.
func (*InputSuggestionSteps) Enter ¶
func (a *InputSuggestionSteps) Enter()
Enter sends the ENTER key and ends the sequence.
Survey.ExpectInput("Enter your name:"). Type("hello"). Enter()
func (*InputSuggestionSteps) Esc ¶
func (a *InputSuggestionSteps) Esc() *InputSuggestionSteps
Esc sends the ESC key.
Survey.ExpectInput("Enter your name:"). Type("hello"). Esc()
func (*InputSuggestionSteps) ExpectSuggestions ¶
func (a *InputSuggestionSteps) ExpectSuggestions(suggestions ...string) *InputSuggestionSteps
ExpectSuggestions expects a list of suggestions.
func (*InputSuggestionSteps) Interrupt ¶
func (a *InputSuggestionSteps) Interrupt() *InputSuggestionSteps
Interrupt sends ^C and closes the suggestions.
Survey.ExpectInput("Enter your name:"). Type("johnny"). Interrupt()
func (*InputSuggestionSteps) MoveDown ¶
func (a *InputSuggestionSteps) MoveDown(times ...int) *InputSuggestionSteps
MoveDown sends the ARROW DOWN key the indicated times. Default is 1 when omitted.
Survey.ExpectInput("Enter your name:"). Tab(). MoveDown(5)
func (*InputSuggestionSteps) MoveUp ¶
func (a *InputSuggestionSteps) MoveUp(times ...int) *InputSuggestionSteps
MoveUp sends the ARROW UP key the indicated times. Default is 1 when omitted.
Survey.ExpectInput("Enter your name:"). Tab(). MoveUp(5)
func (*InputSuggestionSteps) String ¶
func (a *InputSuggestionSteps) String() string
String represents the answer as a string.
func (*InputSuggestionSteps) Tab ¶
func (a *InputSuggestionSteps) Tab(times ...int) *InputSuggestionSteps
Tab sends the TAB key the indicated times. Default is 1 when omitted.
Survey.ExpectInput("Enter your name:"). Type("hello"). Tab(5)
func (*InputSuggestionSteps) Type ¶
func (a *InputSuggestionSteps) Type(s string) *InputSuggestionSteps
Type sends a string without enter.
Survey.ExpectInput("Enter your name:"). Type("johnny"). Tab(). Type(".c"). Enter()
type InterruptAnswer ¶
type InterruptAnswer struct{}
InterruptAnswer sends an interrupt sequence to terminate the survey.
func (*InterruptAnswer) Do ¶
func (a *InterruptAnswer) Do(c Console) error
Do runs the step. nolint: errcheck,gosec
func (*InterruptAnswer) String ¶
func (a *InterruptAnswer) String() string
String represents the answer as a string.
type MultiSelectExpect ¶
type MultiSelectExpect []string
MultiSelectExpect expects a multiselect list from console.
func (*MultiSelectExpect) String ¶
func (e *MultiSelectExpect) String() string
String represents the answer as a string.
type MultiSelectPrompt ¶
type MultiSelectPrompt struct {
// contains filtered or unexported fields
}
MultiSelectPrompt is an expectation of survey.Select.
func (*MultiSelectPrompt) Delete ¶
func (p *MultiSelectPrompt) Delete(times ...int) *MultiSelectPrompt
Delete sends the DELETE key the indicated times. Default is 1 when omitted.
Survey.ExpectMultiSelect("Select a language:"). Type("Eng"). Delete(3)
func (*MultiSelectPrompt) Enter ¶
func (p *MultiSelectPrompt) Enter()
Enter sends the ENTER key and ends the sequence.
Survey.ExpectMultiSelect("Select a language:"). Type("Eng"). Enter()
func (*MultiSelectPrompt) ExpectOptions ¶
func (p *MultiSelectPrompt) ExpectOptions(options ...string) *MultiSelectPrompt
ExpectOptions expects a list of options.
Survey.ExpectMultiSelect("Select a language:"). Type("Eng"). ExpectOptions("English")
func (*MultiSelectPrompt) Interrupt ¶
func (p *MultiSelectPrompt) Interrupt()
Interrupt sends ^C and ends the sequence.
Survey.ExpectMultiSelect("Select a language:"). Interrupt()
func (*MultiSelectPrompt) MoveDown ¶
func (p *MultiSelectPrompt) MoveDown(times ...int) *MultiSelectPrompt
MoveDown sends the ARROW DOWN key the indicated times. Default is 1 when omitted.
Survey.ExpectMultiSelect("Select a language:"). Type("Eng"). MoveDown()
func (*MultiSelectPrompt) MoveUp ¶
func (p *MultiSelectPrompt) MoveUp(times ...int) *MultiSelectPrompt
MoveUp sends the ARROW UP key the indicated times. Default is 1 when omitted.
Survey.ExpectMultiSelect("Select a language:"). Type("Eng"). MoveUp()
func (*MultiSelectPrompt) Select ¶
func (p *MultiSelectPrompt) Select() *MultiSelectPrompt
Select selects an option. If the option is selected, it will be deselected.
Survey.ExpectMultiSelect("Select a language:"). Type("Eng"). Select()
func (*MultiSelectPrompt) SelectAll ¶
func (p *MultiSelectPrompt) SelectAll() *MultiSelectPrompt
SelectAll selects all filtered options.
Survey.ExpectMultiSelect("Select a language:"). Type("Eng"). SelectAll()
func (*MultiSelectPrompt) SelectNone ¶
func (p *MultiSelectPrompt) SelectNone() *MultiSelectPrompt
SelectNone deselects all filtered options.
Survey.ExpectMultiSelect("Select a language:"). Type("Eng"). SelectNone()
func (*MultiSelectPrompt) ShowHelp ¶
func (p *MultiSelectPrompt) ShowHelp(help string, options ...string) *MultiSelectPrompt
ShowHelp asks for help and asserts the help text.
Survey.ExpectMultiSelect("Select a language:"). ShowHelp("Your preferred language")
func (*MultiSelectPrompt) String ¶
func (p *MultiSelectPrompt) String() string
String represents the expectation as a string.
func (*MultiSelectPrompt) Tab ¶
func (p *MultiSelectPrompt) Tab(times ...int) *MultiSelectPrompt
Tab sends the TAB key the indicated times. Default is 1 when omitted.
Survey.ExpectMultiSelect("Select a language:"). Type("Eng"). Tab()
func (*MultiSelectPrompt) Type ¶
func (p *MultiSelectPrompt) Type(s string) *MultiSelectPrompt
Type sends some text to filter the options.
Survey.ExpectMultiSelect("Select a language:"). Type("Eng")
type MultilineAnswer ¶
type MultilineAnswer struct {
// contains filtered or unexported fields
}
MultilineAnswer is an answer for password question.
func (*MultilineAnswer) Do ¶
func (a *MultilineAnswer) Do(c Console) error
Do runs the step. nolint: errcheck,gosec
func (*MultilineAnswer) Interrupted ¶
func (a *MultilineAnswer) Interrupted()
Interrupted expects the answer will be interrupted.
func (*MultilineAnswer) String ¶
func (a *MultilineAnswer) String() string
String represents the answer as a string.
type MultilinePrompt ¶
type MultilinePrompt struct {
// contains filtered or unexported fields
}
MultilinePrompt is an expectation of survey.Multiline.
func (*MultilinePrompt) Answer ¶
func (p *MultilinePrompt) Answer(answer string) *MultilineAnswer
Answer sets the answer to the input prompt.
Survey.ExpectMultiline("Enter your message:"). Answer("hello world")
func (*MultilinePrompt) Interrupt ¶
func (p *MultilinePrompt) Interrupt()
Interrupt marks the answer is interrupted.
Survey.ExpectMultiline("Enter your message:"). Interrupt()
func (*MultilinePrompt) Once ¶
func (p *MultilinePrompt) Once() *MultilinePrompt
Once indicates that the message should only be asked once.
Survey.ExpectMultiline("Enter your message:"). Answer("hello world"). Once()
func (*MultilinePrompt) String ¶
func (p *MultilinePrompt) String() string
String represents the expectation as a string.
func (*MultilinePrompt) Times ¶
func (p *MultilinePrompt) Times(i int) *MultilinePrompt
Times indicates that the message should only be asked the indicated number of times.
Survey.ExpectMultiline("Enter your message:"). Answer("hello world"). Times(5)
func (*MultilinePrompt) Twice ¶
func (p *MultilinePrompt) Twice() *MultilinePrompt
Twice indicates that the message should only be asked twice.
Survey.ExpectMultiline("Enter your message:"). Answer("hello world"). Twice()
type NoAnswer ¶
type NoAnswer struct{}
NoAnswer sends an empty line to answer the question.
type PasswordAnswer ¶
type PasswordAnswer struct {
// contains filtered or unexported fields
}
PasswordAnswer is an answer for password question.
func (*PasswordAnswer) Do ¶
func (a *PasswordAnswer) Do(c Console) error
Do runs the step. nolint: errcheck,gosec
func (*PasswordAnswer) Interrupted ¶
func (a *PasswordAnswer) Interrupted()
Interrupted expects the answer will be interrupted.
func (*PasswordAnswer) String ¶
func (a *PasswordAnswer) String() string
String represents the answer as a string.
type PasswordPrompt ¶
type PasswordPrompt struct {
// contains filtered or unexported fields
}
PasswordPrompt is an expectation of survey.Password.
func (*PasswordPrompt) Answer ¶
func (p *PasswordPrompt) Answer(answer string) *PasswordAnswer
Answer sets the answer to the password prompt.
Survey.ExpectPassword("Enter password:"). Answer("hello world!")
func (*PasswordPrompt) Interrupt ¶
func (p *PasswordPrompt) Interrupt()
Interrupt marks the answer is interrupted.
Survey.ExpectPassword("Enter password:"). Interrupt()
func (*PasswordPrompt) Once ¶
func (p *PasswordPrompt) Once() *PasswordPrompt
Once indicates that the message should only be asked once.
Survey.ExpectPassword("Enter password:"). Answer("hello world!"). Once()
func (*PasswordPrompt) ShowHelp ¶
func (p *PasswordPrompt) ShowHelp(help string, options ...string)
ShowHelp sets help for the expectation.
Survey.ExpectPassword("Enter password:"). ShowHelp("Your shiny password")
func (*PasswordPrompt) String ¶
func (p *PasswordPrompt) String() string
String represents the expectation as a string.
func (*PasswordPrompt) Times ¶
func (p *PasswordPrompt) Times(i int) *PasswordPrompt
Times indicates that the message should only be asked the indicated number of times.
Survey.ExpectPassword("Enter password:"). Answer("hello world!"). Times(5)
func (*PasswordPrompt) Twice ¶
func (p *PasswordPrompt) Twice() *PasswordPrompt
Twice indicates that the message should only be asked twice.
Survey.ExpectPassword("Enter password:"). Answer("hello world!"). Twice()
type SelectExpect ¶
type SelectExpect []string
SelectExpect expects a select list from console.
func (*SelectExpect) String ¶
func (e *SelectExpect) String() string
String represents the answer as a string.
type SelectPrompt ¶
type SelectPrompt struct {
// contains filtered or unexported fields
}
SelectPrompt is an expectation of survey.Select.
func (*SelectPrompt) Delete ¶
func (p *SelectPrompt) Delete(times ...int) *SelectPrompt
Delete sends the DELETE key the indicated times. Default is 1 when omitted.
Survey.ExpectSelect("Select a language:"). Type("Eng"). Delete(3)
func (*SelectPrompt) Enter ¶
func (p *SelectPrompt) Enter()
Enter sends the ENTER key and ends the sequence.
Survey.ExpectSelect("Select a language:"). Type("Eng"). Enter()
func (*SelectPrompt) ExpectOptions ¶
func (p *SelectPrompt) ExpectOptions(options ...string) *SelectPrompt
ExpectOptions expects a list of options.
Survey.ExpectSelect("Select a language:"). Type("Eng"). ExpectOptions("English")
func (*SelectPrompt) Interrupt ¶
func (p *SelectPrompt) Interrupt()
Interrupt sends ^C and ends the sequence.
Survey.ExpectSelect("Select a language:"). Interrupt()
func (*SelectPrompt) MoveDown ¶
func (p *SelectPrompt) MoveDown(times ...int) *SelectPrompt
MoveDown sends the ARROW DOWN key the indicated times. Default is 1 when omitted.
Survey.ExpectSelect("Select a language:"). Type("Eng"). MoveDown()
func (*SelectPrompt) MoveUp ¶
func (p *SelectPrompt) MoveUp(times ...int) *SelectPrompt
MoveUp sends the ARROW UP key the indicated times. Default is 1 when omitted.
Survey.ExpectSelect("Select a language:"). Type("Eng"). MoveUp()
func (*SelectPrompt) ShowHelp ¶
func (p *SelectPrompt) ShowHelp(help string, options ...string) *SelectPrompt
ShowHelp asks for help and asserts the help text.
Survey.ExpectSelect("Select a language:"). ShowHelp("Your preferred language")
func (*SelectPrompt) String ¶
func (p *SelectPrompt) String() string
String represents the expectation as a string.
func (*SelectPrompt) Tab ¶
func (p *SelectPrompt) Tab(times ...int) *SelectPrompt
Tab sends the TAB key the indicated times. Default is 1 when omitted.
Survey.ExpectSelect("Select a language:"). Type("Eng"). Tab()
func (*SelectPrompt) Type ¶
func (p *SelectPrompt) Type(s string) *SelectPrompt
Type sends some text to filter the options.
Survey.ExpectSelect("Select a language:"). Type("Eng")
type Signal ¶
type Signal struct {
// contains filtered or unexported fields
}
Signal is a safe chan to notify the others.
type Step ¶
type Step interface { // Do runs the step. Do(c Console) error // String represents the step as a string. String() string }
Step is an execution step for a survey.
type Steps ¶
type Steps struct {
// contains filtered or unexported fields
}
Steps is a chain of Step.
func (*Steps) ExpectationsWereMet ¶
ExpectationsWereMet checks whether all queued expectations were met in order. If any of them was not met - an error is returned.
func (*Steps) HasNothingToDo ¶
HasNothingToDo checks whether the steps are not empty.
type StringExpect ¶
type StringExpect string
StringExpect expects a string from console.
func (StringExpect) String ¶
func (e StringExpect) String() string
String represents the answer as a string.
type StringWriter ¶
StringWriter is a wrapper for bytes.Buffer.
type Survey ¶
type Survey struct {
// contains filtered or unexported fields
}
Survey is a expectations container and responsible for testing the prompts.
func (*Survey) ExpectConfirm ¶
func (s *Survey) ExpectConfirm(message string) *ConfirmPrompt
ExpectConfirm expects a ConfirmPrompt.
Survey.ExpectConfirm("ConfirmPrompt?"). Yes()
func (*Survey) ExpectInput ¶
func (s *Survey) ExpectInput(message string) *InputPrompt
ExpectInput expects an InputPrompt.
Survey.ExpectInput("Enter password:"). Answer("hello world!")
func (*Survey) ExpectMultiSelect ¶
func (s *Survey) ExpectMultiSelect(message string) *MultiSelectPrompt
ExpectMultiSelect expects a MultiSelectPrompt.
Survey.ExpectMultiSelect("Enter password:"). Enter()
func (*Survey) ExpectMultiline ¶
func (s *Survey) ExpectMultiline(message string) *MultilinePrompt
ExpectMultiline expects a MultilinePrompt.
Survey.ExpectMultiline("Enter password:"). Answer("hello world")
func (*Survey) ExpectPassword ¶
func (s *Survey) ExpectPassword(message string) *PasswordPrompt
ExpectPassword expects a PasswordPrompt.
Survey.ExpectPassword("Enter password:"). Answer("hello world!")
func (*Survey) ExpectSelect ¶
func (s *Survey) ExpectSelect(message string) *SelectPrompt
ExpectSelect expects a SelectPrompt.
Survey.ExpectSelect("Enter password:"). Enter()
func (*Survey) ExpectationsWereMet ¶
ExpectationsWereMet checks whether all queued expectations were met in order. If any of them was not met - an error is returned.
func (*Survey) ResetExpectations ¶
func (s *Survey) ResetExpectations()
ResetExpectations resets all the expectations.
type TestingT ¶
type TestingT interface { Errorf(format string, args ...interface{}) FailNow() Cleanup(func()) Log(args ...interface{}) Logf(format string, args ...interface{}) }
TestingT is an interface wrapper around *testing.T.
type TypeAnswer ¶
type TypeAnswer struct {
// contains filtered or unexported fields
}
TypeAnswer types an answer.
func (*TypeAnswer) Do ¶
func (a *TypeAnswer) Do(c Console) error
Do runs the step. nolint: errcheck,gosec
func (*TypeAnswer) String ¶
func (a *TypeAnswer) String() string
String represents the answer as a string.