commands

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolFromString

func BoolFromString(b string) (*upcloud.Boolean, error)

BoolFromString parses a string and returns *upcloud.Boolean

func CustomBashCompletionFunc

func CustomBashCompletionFunc(name string) string

CustomBashCompletionFunc returns a bash completion function used by cobras bash completion generator

func DatabaseStateColour added in v1.4.0

func DatabaseStateColour(state upcloud.ManagedDatabaseState) text.Colors

DatabaseStateColour maps database states to colours

func HandleError added in v1.3.0

func HandleError(logline *ui.LogEntry, msg string, err error) (output.Output, error)

HandleError logs error in livelog by setting message to msg and details to err. Returns (nil, err), where err is the err passed in as input.

func LoadBalancerOperationalStateColour added in v1.4.0

func LoadBalancerOperationalStateColour(state upcloud.LoadBalancerOperationalState) text.Colors

LoadBalancerOperationalStateColour maps load balancer states to colours

func Parse

func Parse(in string) ([]string, error)

Parse parses a complex, querystring-type argument from in and returns all the parts found eg. `--foo bar=baz,flop=flip` returns `[]string{"bar","baz","flop","flip"}`

func SearchResources

func SearchResources(
	ids []string,
	searchFn func(id string) (interface{}, error),
	getUUID func(interface{}) string,
) ([]string, error)

SearchResources is a convenience method to map a list of resources to uuids. Any input strings that are uuids are returned as such and any other string is passed on to searchFn, the results of which are passed on to getUUID which is expected to return a uuid.

func ServerStateColour

func ServerStateColour(state string) text.Colors

ServerStateColour is a helper mapping server states to colours

func StorageStateColour added in v1.1.0

func StorageStateColour(state string) text.Colors

StorageStateColour is a helper mapping storage states to colours

func ToArray

func ToArray(in interface{}) []interface{}

ToArray turns an interface{} to a slice of interface{}s. If the underlying type is also a slice, the elements will be returned as the return values elements.. Otherwise, the input element is wrapped in a slice.

Types

type BaseCommand

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

BaseCommand is the base type for all commands, implementing Command

func New

func New(name, usage string, examples ...string) *BaseCommand

New returns a BaseCommand that implements Command. It is used as a base to create custom commands from.

func (*BaseCommand) AddFlags

func (s *BaseCommand) AddFlags(flags *pflag.FlagSet)

AddFlags adds a flagset to the command and binds config value into it with namespace

func (*BaseCommand) Cobra

func (s *BaseCommand) Cobra() *cobra.Command

Cobra returns the underlying *cobra.Command

func (*BaseCommand) InitCommand

func (s *BaseCommand) InitCommand()

InitCommand can be overridden to handle flag registration. A hook to handle flag registration. The config values are not available during this hook. Register a cobra hook to use them. You can set defaults though.

func (*BaseCommand) MaximumExecutions

func (s *BaseCommand) MaximumExecutions() int

MaximumExecutions return the max executed workers

type CobraCommand

type CobraCommand interface {
	Cobra() *cobra.Command
}

CobraCommand is an interface for commands that can refer back to their base cobra.Command

type Command

type Command interface {
	InitCommand()
	CobraCommand
}

Command is the base command type for all commands.

func BuildCommand

func BuildCommand(child Command, parent *cobra.Command, config *config.Config) Command

BuildCommand sets up a Command with the specified config and adds it to Cobra

type Executor

type Executor interface {
	NewLogEntry(s string) *ui.LogEntry
	Update()
	Close()
	WaitFor(waitFn func() error, timeout time.Duration) error
	Server() service.Server
	Storage() service.Storage
	Network() service.Network
	Firewall() service.Firewall
	IPAddress() service.IpAddress
	Account() service.Account
	Plan() service.Plans
	All() internal.AllServices
	Debug(msg string, args ...interface{})
	WithLogger(args ...interface{}) Executor
}

Executor represents the execution context for commands

func NewExecutor

func NewExecutor(cfg *config.Config, svc internal.AllServices, logger flume.Logger) Executor

NewExecutor creates the default Executor

type MultipleArgumentCommand

type MultipleArgumentCommand interface {
	Command
	MaximumExecutions() int
	Execute(exec Executor, arg string) (output.Output, error)
}

MultipleArgumentCommand is a command that can accept multiple positional arguments, each of which will result in a (parallel) call to Execute() with the argument.

type NoArgumentCommand

type NoArgumentCommand interface {
	Command
	ExecuteWithoutArguments(exec Executor) (output.Output, error)
}

NoArgumentCommand is a command that does not care about the positional arguments.

type OfflineCommand added in v1.2.0

type OfflineCommand interface {
	DoesNotUseServices()
}

OfflineCommand is a command that does not need connect to the API, e.g. upctl version.

type SingleArgumentCommand

type SingleArgumentCommand interface {
	Command
	ExecuteSingleArgument(exec Executor, arg string) (output.Output, error)
}

SingleArgumentCommand is a command that accepts exactly one positional argument.

Jump to

Keyboard shortcuts

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