interact

package
v0.0.0-...-4bd6544 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2016 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindMatch

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 MatchOptions

func MatchOptions(options []string, err error) func(string) error

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 QueryVerify

func QueryVerify(question []byte, scanner *bufio.Scanner, w io.Writer, verify func(string) error) (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 the user, 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

This section is empty.

Jump to

Keyboard shortcuts

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