question

package
v0.0.0-...-58e9c6f Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2014 License: MIT Imports: 8 Imported by: 0

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

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

func NewCustom(s *valid.Schema, prePrompt, preError, trueStr, falseStr string) *Question

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) Check

func (q *Question) Check(flag valid.Checker) *Question

Check sets the checker flags.

func (*Question) ChoiceFloat64

func (q *Question) ChoiceFloat64(choices []float64) (float64, error)

ChoiceFloat64 prints the prompt waiting to get a float64 that is in the slice.

func (*Question) ChoiceInt

func (q *Question) ChoiceInt(choices []int) (int, error)

ChoiceInt prints the prompt waiting to get an int that is in the slice.

func (*Question) ChoiceString

func (q *Question) ChoiceString(choices []string) (string, error)

ChoiceString prints the prompt waiting to get a string that is in the slice.

func (*Question) Default

func (q *Question) Default(str string) *Question

Default sets a value by default.

func (*Question) Max

func (q *Question) Max(n interface{}) *Question

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

func (q *Question) Min(n interface{}) *Question

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) Prompt

func (q *Question) Prompt(str string) *Question

Prompt sets a new prompt.

func (*Question) Range

func (q *Question) Range(min, max interface{}) *Question

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

func (q *Question) ReadBool() (bool, error)

ReadBool prints the prompt waiting to get a string that represents a boolean.

func (*Question) ReadEmail

func (q *Question) ReadEmail() (value string, err error)

ReadEmail prints the prompt waiting to get an email.

func (*Question) ReadFloat64

func (q *Question) ReadFloat64() (float64, error)

ReadFloat64 prints the prompt waiting to get a floating-point number.

func (*Question) ReadFloat64Slice

func (q *Question) ReadFloat64Slice() (values []float64, err error)

ReadFloat64Slice reads multiple float64. You have to press Enter twice to finish.

func (*Question) ReadInt64

func (q *Question) ReadInt64() (int64, error)

ReadInt64 prints the prompt waiting to get an integer number.

func (*Question) ReadInt64Slice

func (q *Question) ReadInt64Slice() (values []int64, err error)

ReadInt64Slice reads multiple int64. You have to press Enter twice to finish.

func (*Question) ReadString

func (q *Question) ReadString() (string, error)

ReadString prints the prompt waiting to get a string.

func (*Question) ReadStringSlice

func (q *Question) ReadStringSlice() (values []string, err error)

ReadSliceString reads multiple strings. You have to press Enter twice to finish.

func (*Question) ReadURL

func (q *Question) ReadURL() (value string, err error)

ReadURL prints the prompt waiting to get an URL.

func (*Question) ReadUint64

func (q *Question) ReadUint64() (uint64, error)

ReadUint64 prints the prompt waiting to get an unsigned integer number.

func (*Question) ReadUint64Slice

func (q *Question) ReadUint64Slice() (values []uint64, err error)

ReadUint64Slice reads multiple uint64. You have to press Enter twice to finish.

func (*Question) Restore

func (q *Question) Restore() error

Restore restores terminal settings.

func (*Question) SetPrintNumber

func (q *Question) SetPrintNumber() *Question

SetPrintNumber shows the number of question.

Jump to

Keyboard shortcuts

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