juju: github.com/juju/juju/cmd/juju/interact Index | Files

package interact

import "github.com/juju/juju/cmd/juju/interact"

Package interact provides helper methods for interacting with the CLI user at command run time.

Index

Package Files

doc.go errwriter.go pollster.go query.go

Constants

const FormatCertFilename jsonschema.Format = "cert-filename"

Non standard json Format

func FindMatch Uses

func FindMatch(s string, options []string) (match string, found bool)

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 Uses

func NewErrWriter(w io.Writer) io.Writer

NewErrWriter wraps w in a type that will cause all writes to be written as ansi terminal BrightRed.

func QueryVerify Uses

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.

type List Uses

type List struct {
    Singular string
    Plural   string
    Options  []string
    Default  string
}

List contains the information necessary to ask the user to select one item from a list of options.

type MultiList Uses

type MultiList struct {
    Singular string
    Plural   string
    Options  []string
    Default  []string
}

MultiList contains the information necessary to ask the user to select from a list of options.

type Pollster Uses

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 New Uses

func New(in io.Reader, out, errOut io.Writer) *Pollster

New returns a Pollster that wraps the given reader and writer.

func (*Pollster) Enter Uses

func (p *Pollster) Enter(valueName string) (string, error)

Enter requests that the user enter a value. Any value except an empty string is accepted.

func (*Pollster) EnterDefault Uses

func (p *Pollster) EnterDefault(valueName, defVal string) (string, error)

EnterDefault requests that the user enter a value. Any value is accepted. An empty string is treated as defVal.

func (*Pollster) EnterOptional Uses

func (p *Pollster) EnterOptional(valueName string) (string, error)

EnterOptional requests that the user enter a value. It accepts any value, even an empty string.

func (*Pollster) EnterPassword Uses

func (p *Pollster) EnterPassword(valueName string) (string, error)

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 Uses

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 Uses

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 Uses

func (p *Pollster) MultiSelect(l MultiList) ([]string, error)

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 Uses

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) Select Uses

func (p *Pollster) Select(l List) (string, error)

Select queries the user to select from the given list of options.

func (*Pollster) SelectVerify Uses

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.

func (*Pollster) YN Uses

func (p *Pollster) YN(q string, defVal bool) (bool, error)

YN queries the user with a yes no question q (which should not include a question mark at the end). It uses defVal as the default answer.

type VerifyFunc Uses

type VerifyFunc func(s string) (ok bool, errmsg string, err error)

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 Uses

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 Uses

func VerifyOptions(singular string, options []string, hasDefault bool) VerifyFunc

VerifyOptions is the verifier used by pollster.Select.

Package interact imports 15 packages (graph) and is imported by 31 packages. Updated 2019-08-25. Refresh now. Tools for package owners.