handler

package
v0.0.0-...-d73788f Latest Latest
Warning

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

Go to latest
Published: May 16, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(command Commander)

Handle is the function that handles all commands. It accepts a Commander as a parameter, which all commands implement.

Types

type Command

type Command struct {
	// See `Context`
	Ctx *Context
}

Command is the type that commands have.

type Commander

type Commander interface {
	// See `Context`.
	Context() *Context
	// Keys returns the keys available for the command output.
	Keys() []string
	// ServiceClientType returns the type of the service client to use.
	ServiceClientType() string
	// HandleFlags processes flags for the command that are relevant for both piped
	// and non-piped commands.
	HandleFlags(*Resource) error
	// Execute executes the command's HTTP request.
	Execute(*Resource)
}

Commander is an interface that all commands implement.

type Context

type Context struct {
	// CLIContext is the context that the `cli` library uses. `rack` uses it to
	// access flags.
	CLIContext *cli.Context
	// ServiceClient is the Rackspace service client used to authenticate the user
	// and carry out the requests while processing the command.
	ServiceClient *gophercloud.ServiceClient
	// ServiceClientType is the type of Rackspace service client used (e.g. compute).
	ServiceClientType string
	// Results is a channel into which commands send results. It allows for streaming
	// output.
	Results chan *Resource

	GlobalOptions struct {
		// contains filtered or unexported fields
	}
	// contains filtered or unexported fields
}

Context is a global context that `rack` uses.

func (*Context) CheckArgNum

func (ctx *Context) CheckArgNum(expected int) error

CheckArgNum checks that the provided number of arguments has the same cardinality as the expected number of arguments.

func (*Context) CheckFlagsSet

func (ctx *Context) CheckFlagsSet(flagNames []string) error

CheckFlagsSet checks that the given flag names are set for the command.

func (*Context) CheckKVFlag

func (ctx *Context) CheckKVFlag(flagName string) (map[string]string, error)

CheckKVFlag is a function used for verifying the format of a key-value flag.

func (*Context) CheckStructFlag

func (ctx *Context) CheckStructFlag(flagValues []string) ([]map[string]interface{}, error)

CheckStructFlag is a function used for verifying the format of a struct flag.

func (*Context) IDOrName

func (ctx *Context) IDOrName(idFromNameFunc func(*gophercloud.ServiceClient, string) (string, error)) (string, error)

IDOrName is a function for retrieving a resources unique identifier based on whether he or she passed an `id` or a `name` flag.

type PipeHandler

type PipeHandler interface {
	// Commander is an interface that all commands will implement.
	Commander
	// HandleSingle contains logic for processing a single resource. This method
	// will be used if input isn't sent to STDIN, so it will contain, for example,
	// logic for handling flags that would be mandatory if otherwise not piped in.
	HandleSingle(*Resource) error
	// HandlePipe is a method that commands implement for processing piped input.
	HandlePipe(*Resource, string) error
	// StdinField is the field that the command accepts on STDIN.
	StdinField() string
}

PipeHandler is an interface that commands implement if they can accept input from STDIN.

type PreCSVer

type PreCSVer interface {
	PreCSV(*Resource) error
}

PreCSVer is an interface that commands will satisfy if they have a `PreCSV` method.

type PreJSONer

type PreJSONer interface {
	PreJSON(*Resource) error
}

PreJSONer is an interface that commands will satisfy if they have a `PreJSON` method.

type PreTabler

type PreTabler interface {
	PreTable(*Resource) error
}

PreTabler is an interface that commands will satisfy if they have a `PreTable` method.

type Resource

type Resource struct {
	// Keys are the fields available to output. These may be limited by the `fields`
	// flag.
	Keys []string
	// Params will be the command-specific parameters, such as an instance ID or
	// list options.
	Params interface{}
	// Result will store the result of a single command.
	Result interface{}
	// Err will store any error encountered while processing the command.
	Err error
}

Resource is a general resource from Rackspace. This object stores information about a single request and response from Rackspace.

func (*Resource) FlattenMap

func (resource *Resource) FlattenMap(key string)

FlattenMap is used to flatten out a `map[string]map[string]*`

type StreamPipeHandler

type StreamPipeHandler interface {
	// PipeHandler is an interface that commands implement if they can accept input
	// from STDIN.
	PipeHandler
	// StreamField is the field that the command accepts for streaming input on STDIN.
	StreamField() string
	// HandleStreamPipe is a method that commands implement for processing streaming, piped input.
	HandleStreamPipe(*Resource) error
}

StreamPipeHandler is an interface that commands implement if they can stream input from STDIN.

Jump to

Keyboard shortcuts

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