asker

package module
Version: v0.0.0-...-49cb0b8 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2017 License: MIT Imports: 7 Imported by: 0

README

asker

GoDoc

A simple question asking library for Go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Prompt

func Prompt(reader io.Reader) (string, error)

Prompt will read from the input until a newline is reached.

Types

type Answer

type Answer struct {
	StringResponse string
	BoolResponse   bool
	Provided       bool
}

Answer is what is returned in response to a question when asked it.

func Ask

func Ask(reader io.Reader, questions ...Asker) ([]Answer, error)

Ask will walk over each question and prompt for it, returning all the answers in an array.

type Asker

type Asker interface {
	Ask(reader io.Reader) (*Answer, error)
}

Asker is a struct which can Ask the user for input.

type ChoiceAsker

type ChoiceAsker struct {
	Choices  []string
	Question string
}

ChoiceAsker will allow the user to select from a list of options.

func (ChoiceAsker) Ask

func (cp ChoiceAsker) Ask(reader io.Reader) (*Answer, error)

Ask implements the Asker interface.

type ConfirmAsker

type ConfirmAsker struct {
	Question string
	Default  bool
}

ConfirmAsker will allow the user to select from y/N.

func (ConfirmAsker) Ask

func (cp ConfirmAsker) Ask(reader io.Reader) (*Answer, error)

Ask implements the Asker interface.

type TextAsker

type TextAsker struct {
	Question  string
	Prefix    string
	Required  bool
	Validator func(response string) error
}

TextAsker will Ask the user a text based inquiry.

func (TextAsker) Ask

func (tp TextAsker) Ask(reader io.Reader) (*Answer, error)

Ask implements the Asker interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL