questions

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrQuestionNotAnswered = errors.New("question.Answer() called without the question having been successfully asked")

Functions

func AskQuestions

func AskQuestions(questions []Question) error

AskQuestions takes a list of questions and asks each one in sequence, returning the list of answers

Types

type Answer

type Answer string

type ClosedQuestion

type ClosedQuestion struct {
	Question string
	Items    []string
}

ClosedQuestion is a prompt where the user can choose from a fixed set of answers

type OpenEndedQuestion

type OpenEndedQuestion struct {
	Question  string
	Default   string
	AllowEdit bool
	Validate  func(string) error
}

OpenEndedQuestion is a prompt where the user can provide any answer

type Question

type Question interface {
	Ask() error
	Answer() Answer
}

Question represents a generic user prompt

type QuestionBranch

type QuestionBranch struct {
	ConditionQuestion Question
	ConditionAnswer   Answer
	BranchA           []Question
	BranchB           []Question
}

QuestionBranch is a sort of "meta-question" whose Ask method will delegate to ConditionQuestion and execute BranchA if ConditionAnswer is met, otherwise execute BranchB

func (*QuestionBranch) Answer

func (q *QuestionBranch) Answer() Answer

func (*QuestionBranch) Ask

func (q *QuestionBranch) Ask() error

type Questioner

type Questioner interface {
	NewOpenEndedQuestion(question *OpenEndedQuestion) Question
	NewClosedQuestion(question *ClosedQuestion) Question
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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