cmd

package
v0.0.0-...-9ff6e62 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context captures the environment the sub-command is being run in, such as in/out/err streams and command line arguments.

func NewContext

func NewContext(stdin io.Reader, stdout, stderr io.Writer) *Context

NewContext creates a new command context with the given parameters.

func NewMemoryContext

func NewMemoryContext(streams *MemoryStreams) *Context

NewMemoryContext creates a new command Context using the given in-memory streams.

func (*Context) AskBool

func (c *Context) AskBool(question string, defaultAnswer string) bool

AskBool asks a question an expect a yes/no answer.

func (*Context) AskChoice

func (c *Context) AskChoice(question string, choices []string, defaultAnswer string) string

AskChoice asks the user to select between a set of choices

func (*Context) AskInt

func (c *Context) AskInt(question string, min int64, max int64, defaultAnswer string) int64

AskInt asks the user to enter an integer between a min and max value

func (*Context) AskPassword

func (c *Context) AskPassword(question string, reader func(int) ([]byte, error)) string

AskPassword asks the user to enter a password. The reader function used to read the password without echoing characters must be passed (usually terminal.ReadPassword from golang.org/x/crypto/ssh/terminal).

func (*Context) AskString

func (c *Context) AskString(question string, defaultAnswer string, validate func(string) error) string

AskString asks the user to enter a string, which optionally conforms to a validation function.

func (*Context) InputYAML

func (c *Context) InputYAML(out interface{}) error

InputYAML treats stdin as YAML content and returns the unmarshalled structure

func (*Context) Output

func (c *Context) Output(format string, a ...interface{})

Output prints a message on standard output.

type MemoryStreams

type MemoryStreams struct {
	// contains filtered or unexported fields
}

MemoryStreams provide an in-memory version of the system stdin/stdout/stderr streams.

func NewMemoryStreams

func NewMemoryStreams(input string) *MemoryStreams

NewMemoryStreams creates a new set of in-memory streams with the given user input.

func (*MemoryStreams) Err

func (s *MemoryStreams) Err() string

Err returns the current content of the err stream.

func (*MemoryStreams) InputAppend

func (s *MemoryStreams) InputAppend(text string)

InputAppend adds the given text to the current input.

func (*MemoryStreams) InputAppendBoolAnswer

func (s *MemoryStreams) InputAppendBoolAnswer(answer bool)

InputAppendBoolAnswer adds a new "yes" or "no" line depending on the answer.

func (*MemoryStreams) InputAppendLine

func (s *MemoryStreams) InputAppendLine(line string)

InputAppendLine adds a single line to the input stream.

func (*MemoryStreams) InputRead

func (s *MemoryStreams) InputRead() string

InputRead returns the current input string.

func (*MemoryStreams) InputReset

func (s *MemoryStreams) InputReset(input string)

InputReset replaces the data in the input stream.

func (*MemoryStreams) Out

func (s *MemoryStreams) Out() string

Out returns the current content of the out stream.

Jump to

Keyboard shortcuts

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