Documentation ¶
Overview ¶
Package interact provides helper methods for interacting with the CLI user at command run time.
Index ¶
- Constants
- func FindMatch(s string, options []string) (match string, found bool)
- func NewErrWriter(w io.Writer) io.Writer
- func QueryVerify(question string, scanner *bufio.Scanner, out, errOut io.Writer, ...) (answer string, err error)
- type List
- type MultiList
- type Pollster
- func (p *Pollster) Enter(valueName string) (string, error)
- func (p *Pollster) EnterDefault(valueName, defVal string) (string, error)
- func (p *Pollster) EnterOptional(valueName string) (string, error)
- func (p *Pollster) EnterPassword(valueName string) (string, error)
- func (p *Pollster) EnterVerify(valueName string, verify VerifyFunc) (string, error)
- func (p *Pollster) EnterVerifyDefault(valueName string, verify VerifyFunc, defVal string) (string, error)
- func (p *Pollster) MultiSelect(l MultiList) ([]string, error)
- func (p *Pollster) QuerySchema(schema *jsonschema.Schema) (interface{}, error)
- func (p *Pollster) Select(l List) (string, error)
- func (p *Pollster) SelectVerify(l List, verify VerifyFunc) (string, error)
- func (p *Pollster) YN(q string, defVal bool) (bool, error)
- type VerifyFunc
Constants ¶
const FormatCertFilename jsonschema.Format = "cert-filename"
Non standard json Format
Variables ¶
This section is empty.
Functions ¶
func FindMatch ¶
FindMatch does a case-insensitive search of the given options and returns the matching option. Found reports whether s was found in the options.
func NewErrWriter ¶
NewErrWriter wraps w in a type that will cause all writes to be written as ansi terminal BrightRed.
func QueryVerify ¶
func QueryVerify(question string, scanner *bufio.Scanner, out, errOut io.Writer, verify VerifyFunc) (answer string, err error)
QueryVerify writes a question to w and waits for an answer to be read from scanner. It will pass the answer into the verify function. Verify, if non-nil, should check the answer for validity, returning an error that will be written out to errOut, or nil if answer is valid.
This function takes a scanner rather than an io.Reader to avoid the case where the scanner reads past the delimiter and thus might lose data. It is expected that this method will be used repeatedly with the same scanner if multiple queries are required.
Types ¶
type List ¶
List contains the information necessary to ask the user to select one item from a list of options.
type MultiList ¶
MultiList contains the information necessary to ask the user to select from a list of options.
type Pollster ¶
type Pollster struct { VerifyURLs VerifyFunc VerifyCertFile VerifyFunc // contains filtered or unexported fields }
Pollster is used to ask multiple questions of the user using a standard formatting.
func (*Pollster) Enter ¶
Enter requests that the user enter a value. Any value except an empty string is accepted.
func (*Pollster) EnterDefault ¶
EnterDefault requests that the user enter a value. Any value is accepted. An empty string is treated as defVal.
func (*Pollster) EnterOptional ¶
EnterOptional requests that the user enter a value. It accepts any value, even an empty string.
func (*Pollster) EnterPassword ¶
EnterPassword works like Enter except that if the pollster's input wraps a terminal, the user's input will be read without local echo.
func (*Pollster) EnterVerify ¶
func (p *Pollster) EnterVerify(valueName string, verify VerifyFunc) (string, error)
EnterVerify requests that the user enter a value. Values failing to verify will be rejected with the error message returned by verify. A nil verify function will accept any value (even an empty string).
func (*Pollster) EnterVerifyDefault ¶
func (p *Pollster) EnterVerifyDefault(valueName string, verify VerifyFunc, defVal string) (string, error)
EnterVerifyDefault requests that the user enter a value. Values failing to verify will be rejected with the error message returned by verify. An empty string will be accepted as the default value even if it would fail verification.
func (*Pollster) MultiSelect ¶
MultiSelect queries the user to select one more answers from the given list of options by entering values delimited by commas (and thus options must not contain commas).
func (*Pollster) QuerySchema ¶
func (p *Pollster) QuerySchema(schema *jsonschema.Schema) (interface{}, error)
QuerySchema takes a jsonschema and queries the user to input value(s) for the schema. It returns an object as defined by the schema (generally a map[string]interface{} for objects, etc).
func (*Pollster) SelectVerify ¶
func (p *Pollster) SelectVerify(l List, verify VerifyFunc) (string, error)
SelectVerify queries the user to select from the given list of options, verifying the choice by passing responses through verify.
type VerifyFunc ¶
VerifyFunc is a type that determines whether a value entered by the user is acceptable or not. If it returns an error, the calling func will return an error, and the other return values are ignored. If ok is true, the value is acceptable, and that value will be returned by the calling function. If ok is false, the user will be asked to enter a new value for query. If ok is false. if errmsg is not empty, it will be printed out as an error to te the user.
func MatchOptions ¶
func MatchOptions(options []string, errmsg string) VerifyFunc
MatchOptions returns a function that performs a case insensitive comparison against the given list of options. To make a verification function that accepts an empty default, include an empty string in the list.
func VerifyOptions ¶
func VerifyOptions(singular string, options []string, hasDefault bool) VerifyFunc
VerifyOptions is the verifier used by pollster.Select.