Documentation ¶
Overview ¶
Package question provides functions for printing questions and validate answers.
The test enables to run in interactive mode (flag -user), or automatically (by default) where the answers are written directly every "n" seconds (flag -t).
Index ¶
- func PrintAnswer(i interface{}, err error)
- type Question
- func (q *Question) Check(flag valid.Checker) *Question
- func (q *Question) ChoiceFloat64(choices []float64) (float64, error)
- func (q *Question) ChoiceInt(choices []int) (int, error)
- func (q *Question) ChoiceString(choices []string) (string, error)
- func (q *Question) Default(str string) *Question
- func (q *Question) Max(n interface{}) *Question
- func (q *Question) Min(n interface{}) *Question
- func (q *Question) Prompt(str string) *Question
- func (q *Question) Range(min, max interface{}) *Question
- func (q *Question) ReadBool() (bool, error)
- func (q *Question) ReadEmail() (value string, err error)
- func (q *Question) ReadFloat64() (float64, error)
- func (q *Question) ReadFloat64Slice() (values []float64, err error)
- func (q *Question) ReadInt64() (int64, error)
- func (q *Question) ReadInt64Slice() (values []int64, err error)
- func (q *Question) ReadString() (string, error)
- func (q *Question) ReadStringSlice() (values []string, err error)
- func (q *Question) ReadURL() (value string, err error)
- func (q *Question) ReadUint64() (uint64, error)
- func (q *Question) ReadUint64Slice() (values []uint64, err error)
- func (q *Question) Restore() error
- func (q *Question) SetPrintNumber() *Question
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrintAnswer ¶
func PrintAnswer(i interface{}, err error)
PrintAnswer prints values returned by a Question.
Types ¶
type Question ¶
type Question struct {
// contains filtered or unexported fields
}
A Question represents a question.
func New ¶
func New() *Question
New returns a Question using values by default. The terminal is changed to raw mode so have to use (*Question) Restore() at finish.
func NewCustom ¶
NewCustom returns a Question with the given arguments; if any is empty, it is used the values by default. Panics if the terminal can not be set.
prePrompt is the text placed before of the prompt. preError is placed before of show any error.
trueStr and falseStr are the strings to be showed when the question needs a boolean like answer and it is used a value by default.
The terminal is changed to raw mode so have to use (*Question) Restore() at finish.
Handles interrupts CTRL-C to continue into a new line and CTRL-D to exit.
func (*Question) ChoiceFloat64 ¶
ChoiceFloat64 prints the prompt waiting to get a float64 that is in the slice.
func (*Question) ChoiceInt ¶
ChoiceInt prints the prompt waiting to get an int that is in the slice.
func (*Question) ChoiceString ¶
ChoiceString prints the prompt waiting to get a string that is in the slice.
func (*Question) Max ¶
Max sets the checking for the maximum length of a string, or the maximum value of a numeric type. The valid types for the aregument are: int, float64.
func (*Question) Min ¶
Min sets the checking for the minimum length of a string, or the minimum value of a numeric type. The valid types for the aregument are: int, float64.
func (*Question) Range ¶
Range sets the checking for the minimum and maximum lengths of a string, or the minimum and maximum values of a numeric type. The valid types for the areguments are: int, float64.
func (*Question) ReadBool ¶
ReadBool prints the prompt waiting to get a string that represents a boolean.
func (*Question) ReadFloat64 ¶
ReadFloat64 prints the prompt waiting to get a floating-point number.
func (*Question) ReadFloat64Slice ¶
ReadFloat64Slice reads multiple float64. You have to press Enter twice to finish.
func (*Question) ReadInt64Slice ¶
ReadInt64Slice reads multiple int64. You have to press Enter twice to finish.
func (*Question) ReadString ¶
ReadString prints the prompt waiting to get a string.
func (*Question) ReadStringSlice ¶
ReadSliceString reads multiple strings. You have to press Enter twice to finish.
func (*Question) ReadUint64 ¶
ReadUint64 prints the prompt waiting to get an unsigned integer number.
func (*Question) ReadUint64Slice ¶
ReadUint64Slice reads multiple uint64. You have to press Enter twice to finish.
func (*Question) SetPrintNumber ¶
SetPrintNumber shows the number of question.