plugin

package
v0.0.0-...-84e757a Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPluginContext

func NewPluginContext(pluginName string, coreConfig core_config.ReadWriter) *pluginContext

func Run

func Run(plugin Plugin, args []string)

func Start

func Start(plugin Plugin)

Types

type Command

type Command struct {
	Namespace   string // namespace of the command
	Name        string // command name
	Alias       string // command alias, usually the command's short name
	Description string // short description of the command
	Usage       string // usage detail to be displayed in command help
	Flags       []Flag // command options
}

func (Command) FullName

func (c Command) FullName() string

func (Command) FullNames

func (c Command) FullNames() []string

type Flag

type Flag struct {
	Name        string // name of the option
	Description string // description of the option
	HasValue    bool   // whether the option requires a value or not
}

Command option

type Namespace

type Namespace struct {
	Name        string // name of the namespace
	Description string // description of the namespace
}

func (Namespace) ParentName

func (n Namespace) ParentName() string

type Plugin

type Plugin interface {
	// GetMetadata returns the metadata of the plugin.
	GetMetadata() PluginMetadata

	// Run runs the plugin command with plugin context and given arguments.
	// Note: the first argument is always the command name or alias no matter
	// the command has namespace or not.
	// To get command namespace, call PluginContext.CommandNamespace()
	Run(c PluginContext, args []string)
}

Plugin is the interface of Bluemix CLI plugin.

type PluginConfig

type PluginConfig interface {
	// Get returns the value for the given key.
	// The return value is nil, float64, bool, string, []interface{} or map[string]interface.
	// If key not exists, return nil.
	Get(key string) interface{}

	// Get returns the value for the given key.
	// The return value is nil, float64, bool, string, []interface{} or map[string]interface.
	// If key not exists, return defaultVal.
	GetWithDefault(key string, defaultVal interface{}) interface{}

	// GetString returns string value for the given key.
	// If key not exists, return "".
	GetString(key string) (string, error)

	// GetStringWithDefault returns string value for the given key.
	// If key not exists, return defaultVal.
	GetStringWithDefault(key string, defaultVal string) (string, error)

	// GetBool returns boolean value for the given key.
	// If key not exists, return false.
	// If the value is a string, attempts to convert it to bool.
	GetBool(key string) (bool, error)

	// GetBoolWithDefault returns boolean value for the given key.
	// If key not exists, return defaultVal.
	// If the value is a string, attempts to convert it to bool.
	GetBoolWithDefault(key string, defaultVal bool) (bool, error)

	// GetInt returns int value for the given key.
	// If key not exists, return 0.
	// If the value is float or string, attempts to convert it to int.
	GetInt(key string) (int, error)

	// GetIntWithDefault returns int value for the given key.
	// If key not exists, return defaultVal.
	// If the value is float or string, attempts to convert it to int.
	GetIntWithDefault(key string, defaultVal int) (int, error)

	// GetFloat returns float64 value for the given key.
	// If key not exists, return 0.0.
	// If the value is int or string, attempts to convert it to float64.
	GetFloat(key string) (float64, error)

	// GetFloat returns float64 value for the given key.
	// If key not exists, return defaultVal
	// If the value is int or string, attempts to convert it to float64.
	GetFloatWithDefault(key string, defaultVal float64) (float64, error)

	// GetStringSlice return string slice for the given key.
	// If key not exists, return empty string slice.
	GetStringSlice(key string) ([]string, error)

	// GetIntSlice return string slice for the given key.
	// If key not exists, return empty int slice.
	GetIntSlice(key string) ([]int, error)

	// GetFloatSlice return string slice for the given key.
	// If key not exists, return empty float slice.
	GetFloatSlice(key string) ([]float64, error)

	// GetStringMap return map[string]interface{} for the given key.
	// If key not exists, return empty map.
	GetStringMap(key string) (map[string]interface{}, error)

	// GetStringMap return map[string]string for the given key.
	// If key not exists, return empty map.
	GetStringMapString(key string) (map[string]string, error)

	// Exists checks whether the key exists or not.
	Exists(key string) bool

	// Set sets the value for the given key.
	Set(string, interface{}) error

	// Erase delete the given key.
	Erase(key string) error
}

PluginConfig defines methods to access plug-in's private configuration stored in a JSON format.

func NewPluginConfig

func NewPluginConfig(path string) PluginConfig

type PluginContext

type PluginContext interface {
	APIVersion() string
	APIEndpoint() string
	HasAPIEndpoint() bool
	// deprecate loggergator endpoint, use Doppler endpoint instead
	// LoggregatorEndpoint() string
	DopplerEndpoint() string
	ConsoleEndpoint() string
	UAAEndpoint() string
	UAAToken() string
	UAARefreshToken() string
	RefreshUAAToken() (string, error)
	IAMTokenEndpoint() string
	IAMToken() string
	IAMRefreshToken() string
	RefreshIAMToken() (string, error)
	Username() string
	UserGUID() string
	UserEmail() string
	IsLoggedIn() bool
	CurrentOrg() models.OrganizationFields
	HasOrganization() bool
	// deprecated. Use Account() instead
	AccountID() string
	Account() models.Account
	IMSAccountID() string
	CurrentSpace() models.SpaceFields
	HasSpace() bool
	Region() string   // region name
	RegionID() string // region unique ID
	Locale() string
	Trace() string
	ColorEnabled() string
	IsSSLDisabled() bool
	PluginDirectory() string
	HTTPTimeout() int
	VersionCheckEnabled() bool
	PluginConfig() PluginConfig
	CommandNamespace() string
}

PluginContext holds context to be passed into plugin's Run method.

type PluginMetadata

type PluginMetadata struct {
	Name          string      // name of the plugin
	Version       VersionType // version of the plugin
	MinCliVersion VersionType // minimal CLI version required by the plugin
	Namespaces    []Namespace // command namespaces defined for the plugin
	Commands      []Command   // list of commands provided by the plugin
}

type TypeError

type TypeError struct {
	Key          string
	ExpectedType string
}

func NewTypeError

func NewTypeError(key string, expectedType string) *TypeError

func (*TypeError) Error

func (e *TypeError) Error() string

type VersionType

type VersionType struct {
	Major int
	Minor int
	Build int
}

func (VersionType) String

func (v VersionType) String() string

Directories

Path Synopsis
This file was generated by counterfeiter This file was generated by counterfeiter
This file was generated by counterfeiter This file was generated by counterfeiter

Jump to

Keyboard shortcuts

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