Documentation ¶
Index ¶
- func BoolFromString(b string) (*upcloud.Boolean, error)
- func CompletionEscape(s string) string
- func CustomBashCompletionFunc(name string) string
- func MatchStringPrefix(vals []string, key string, caseSensitive bool) []string
- func Parse(in string) ([]string, error)
- func SearchResources(ids []string, searchFn func(id string) (interface{}, error), ...) ([]string, error)
- func StateColour(state string) text.Colors
- func ToArray(in interface{}) []interface{}
- type BaseCommand
- func (s *BaseCommand) AddFlags(flags *pflag.FlagSet)
- func (s *BaseCommand) AddPersistentFlags(flags *pflag.FlagSet)
- func (s *BaseCommand) AddVisibleColumnsFlag(flags *pflag.FlagSet, dstPtr *[]string, available, defaults []string)
- func (s *BaseCommand) ArgCompletion(fn func(toComplete string) ([]string, cobra.ShellCompDirective))
- func (s *BaseCommand) Children() []Command
- func (s *BaseCommand) Cobra() *cobra.Command
- func (s *BaseCommand) Config() *config.Config
- func (s *BaseCommand) ConfigLoader() func(config *config.Config) error
- func (s *BaseCommand) DeleteChild(command Command)
- func (s *BaseCommand) HandleError(err error)
- func (s *BaseCommand) HandleOutput(io.Writer, interface{}) error
- func (s *BaseCommand) InitCommand()
- func (s *BaseCommand) MakeExecuteCommand() func(args []string) (interface{}, error)
- func (s *BaseCommand) MakePersistentPreExecuteCommand() func(args []string) error
- func (s *BaseCommand) MakePreExecuteCommand() func(args []string) error
- func (s *BaseCommand) Name() string
- func (s *BaseCommand) Namespace() string
- func (s *BaseCommand) Parent() Command
- func (s *BaseCommand) SetChild(command Command)
- func (s *BaseCommand) SetConfig(config *config.Config)
- func (s *BaseCommand) SetConfigLoader(fn func(config *config.Config) error)
- func (s *BaseCommand) SetFlags(flags []string) error
- func (s *BaseCommand) SetParent(command Command)
- func (s *BaseCommand) SetPositionalArgHelp(help string)
- type CobraCommand
- type Command
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BoolFromString ¶
BoolFromString parses a string and returns *upcloud.Boolean
func CompletionEscape ¶
CompletionEscape escapes a string according to completion rules (?) in effect, this means that the string will be quoted with double quotes if it contains a space or parentheses.
func CustomBashCompletionFunc ¶
CustomBashCompletionFunc returns a bash completion function used by cobras bash completion generator
func MatchStringPrefix ¶
MatchStringPrefix returns a list of string in vals which have a prefix as specified in key. Quotes are removed from key and output strings are escaped according to completion rules
func Parse ¶
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 StateColour ¶
StateColour is a helper mapping states to colors
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) *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) AddPersistentFlags ¶
func (s *BaseCommand) AddPersistentFlags(flags *pflag.FlagSet)
AddPersistentFlags adds a persistent flagset to the command and binds config value into it with namespace
func (*BaseCommand) AddVisibleColumnsFlag ¶
func (s *BaseCommand) AddVisibleColumnsFlag(flags *pflag.FlagSet, dstPtr *[]string, available, defaults []string)
AddVisibleColumnsFlag is a convenience method to set a common flag '--columns' to commands
func (*BaseCommand) ArgCompletion ¶
func (s *BaseCommand) ArgCompletion(fn func(toComplete string) ([]string, cobra.ShellCompDirective))
ArgCompletion is a convenience method to set upctl-specific completion function to the underlying cobra.Command
func (*BaseCommand) Children ¶
func (s *BaseCommand) Children() []Command
Children returns a list of all the child commands of this command (eg. including the children of children)
func (*BaseCommand) Cobra ¶
func (s *BaseCommand) Cobra() *cobra.Command
Cobra returns the underlying *cobra.Command
func (*BaseCommand) Config ¶
func (s *BaseCommand) Config() *config.Config
Config implements Command.Config, returning the *config.Config of the command
func (*BaseCommand) ConfigLoader ¶
func (s *BaseCommand) ConfigLoader() func(config *config.Config) error
ConfigLoader implements Command.ConfigLoader, returning the specified ConfigLoader
func (*BaseCommand) DeleteChild ¶
func (s *BaseCommand) DeleteChild(command Command)
DeleteChild removes command from the children of this command
func (*BaseCommand) HandleError ¶
func (s *BaseCommand) HandleError(err error)
HandleError is used to handle errors from the main command
func (*BaseCommand) HandleOutput ¶
func (s *BaseCommand) HandleOutput(io.Writer, interface{}) error
HandleOutput should be overwritten by the actual command implementations It is expected to write output, given in out, to writer
func (*BaseCommand) InitCommand ¶
func (s *BaseCommand) InitCommand()
InitCommand can be overriden 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) MakeExecuteCommand ¶
func (s *BaseCommand) MakeExecuteCommand() func(args []string) (interface{}, error)
MakeExecuteCommand should be overwritten by the actual command implementations The function returned is ran during the 'regular' execute phase and the returned value is returned to the user, formatted as requested.
func (*BaseCommand) MakePersistentPreExecuteCommand ¶
func (s *BaseCommand) MakePersistentPreExecuteCommand() func(args []string) error
MakePersistentPreExecuteCommand should be overwritten by the actual command implementations The function returned is ran before PreExecuteCommand().
func (*BaseCommand) MakePreExecuteCommand ¶
func (s *BaseCommand) MakePreExecuteCommand() func(args []string) error
MakePreExecuteCommand should be overwritten by the actual command implementations The function returned is ran before the 'regular' execute phase.
func (*BaseCommand) Namespace ¶
func (s *BaseCommand) Namespace() string
Namespace returns the namespace of this command from the chain of parent commands The format is cmdRoot.child1.child2.childN No namespace is returned for the root command (parent == nil)
func (*BaseCommand) Parent ¶
func (s *BaseCommand) Parent() Command
Parent returns the parent of the command
func (*BaseCommand) SetChild ¶
func (s *BaseCommand) SetChild(command Command)
SetChild sets command as the child of this command
func (*BaseCommand) SetConfig ¶
func (s *BaseCommand) SetConfig(config *config.Config)
SetConfig sets the configuration used
func (*BaseCommand) SetConfigLoader ¶
func (s *BaseCommand) SetConfigLoader(fn func(config *config.Config) error)
SetConfigLoader implements Command.SetConfigLoader, setting internal config loader
func (*BaseCommand) SetFlags ¶
func (s *BaseCommand) SetFlags(flags []string) error
SetFlags parses the given flags
func (*BaseCommand) SetParent ¶
func (s *BaseCommand) SetParent(command Command)
SetParent sets the parent of this command to given command
func (*BaseCommand) SetPositionalArgHelp ¶
func (s *BaseCommand) SetPositionalArgHelp(help string)
SetPositionalArgHelp is a convenience method to set the help text for positional arguments. if help is an empty string, uses just the name of the command.
type CobraCommand ¶
CobraCommand is an interface for commands that can refer back to their base cobra.Command
type Command ¶
type Command interface { SetConfig(config *config.Config) SetParent(Command) SetChild(command Command) SetFlags(flags []string) error DeleteChild(command Command) Children() []Command Parent() Command Name() string InitCommand() MakeExecuteCommand() func(args []string) (interface{}, error) MakePreExecuteCommand() func(args []string) error MakePersistentPreExecuteCommand() func(args []string) error SetConfigLoader(func(config *config.Config) error) ConfigLoader() func(config *config.Config) error Config() *config.Config HandleOutput(writer io.Writer, out interface{}) error HandleError(err error) CobraCommand }
Command defines the common functionality for all commands