Documentation
¶
Index ¶
- Constants
- func BoolFromString(b string) (*upcloud.Boolean, error)
- func HandleError(exec Executor, key string, err error) (output.Output, error)
- func IsDeprecatedAliasUsed(deprecatedAlias string) bool
- func Must(err error)
- func Parse(in string) ([]string, error)
- func ParseN(in string, n int) ([]string, error)
- func ParseSSHKeys(sshKeys []string) ([]string, error)
- func PrintDeprecationWarning(deprecatedAlias, newCommand string)
- func SearchResources(ids []string, searchFn func(id string) (interface{}, error), ...) ([]string, error)
- func SetDeprecationHelp(cmd *cobra.Command, deprecatedAliases []string)
- func SetSubcommandDeprecationHelp(cmd Command, aliases []string)
- func SetSubcommandExecutionDeprecationMessage(cmd Command, deprecatedParentAliases []string, mainParentAlias string)
- func ToArray(in interface{}) []interface{}
- func WrapLongDescription(message string) string
- type BaseCommand
- func (s *BaseCommand) AddFlags(flags *pflag.FlagSet)
- func (s *BaseCommand) Aliases() []string
- func (s *BaseCommand) Cobra() *cobra.Command
- func (s *BaseCommand) DeprecatedAliases() []string
- func (s *BaseCommand) InitCommand()
- func (s *BaseCommand) InitCommandWithConfig(*config.Config)
- func (s *BaseCommand) MaximumExecutions() int
- func (s *BaseCommand) SetDeprecatedAliases(aliases []string)
- type CobraCommand
- type Command
- type CommandContextKey
- type Executor
- type MultipleArgumentCommand
- type NoArgumentCommand
- type OfflineCommand
- type SingleArgumentCommand
Constants ¶
const ( // FlagAnnotationNoFileCompletions is the annotation name to use for our flags that have no filename completions. FlagAnnotationNoFileCompletions = "upctl_flag_no_file_completions" // FlagAnnotationFixedCompletions is the annotation name to use for our flags that have a fixed set of completions. FlagAnnotationFixedCompletions = "upctl_flag_fixed_completions" )
Variables ¶
This section is empty.
Functions ¶
func BoolFromString ¶
BoolFromString parses a string and returns *upcloud.Boolean
func HandleError ¶
HandleError updates error details to progress log message identified by given key. Returns (nil, err), where err is the err passed in as input.
func IsDeprecatedAliasUsed ¶ added in v3.15.0
isDeprecatedAliasUsed checks if the deprecated alias was used in the command invocation
func Parse ¶
Parse calls `ParseN()` with `n` -1: eg. `--foo bar=baz,flop=flip` returns `[]string{"bar","baz","flop","flip"}` and `--foo bar=baz,flop=flip=1` returns `[]string{"bar","baz","flop","flip","1"}`
func ParseN ¶
ParseN parses a complex, querystring-type argument from `in` and splits values to `n` amount of substrings e.g. with `n` 2: `--foo bar=baz,flop=flip=1` returns `[]string{"bar","baz","flop","flip=1"}`
func ParseSSHKeys ¶
ParseSSHKeys parses strings that can be either actual public keys or file names referring public key files.
func PrintDeprecationWarning ¶ added in v3.15.0
func PrintDeprecationWarning(deprecatedAlias, newCommand string)
PrintDeprecationWarning prints a deprecation message
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 SetDeprecationHelp ¶ added in v3.15.0
SetDeprecationHelp hides a specific alias in the help output and prints a deprecation warning when used. Only works for primary commands, not subcommands.
func SetSubcommandDeprecationHelp ¶ added in v3.15.0
SetSubcommandDeprecationHelp detects the correct interface implementation and wraps the relevant execution function.
func SetSubcommandExecutionDeprecationMessage ¶ added in v3.15.0
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.
func WrapLongDescription ¶
WrapLongDescription wraps Long description messages at 80 characters and removes trailing whitespace from the message.
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) Aliases ¶ added in v3.15.0
func (s *BaseCommand) Aliases() []string
Aliases return non deprecated aliases
func (*BaseCommand) Cobra ¶
func (s *BaseCommand) Cobra() *cobra.Command
Cobra returns the underlying *cobra.Command
func (*BaseCommand) DeprecatedAliases ¶ added in v3.15.0
func (s *BaseCommand) DeprecatedAliases() []string
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) InitCommandWithConfig ¶
func (s *BaseCommand) InitCommandWithConfig(*config.Config)
InitCommandWithConfig is a hook for running additional initialisations with access to config. E.g., can be used to set flag completion functions. Note that the config might not be initialized when this function is called. Thus, config has to be used in a hook function, e.g. Cobras Command.RegisterFlagCompletionFunc.
func (*BaseCommand) MaximumExecutions ¶
func (s *BaseCommand) MaximumExecutions() int
MaximumExecutions return the max executed workers
func (*BaseCommand) SetDeprecatedAliases ¶ added in v3.15.0
func (s *BaseCommand) SetDeprecatedAliases(aliases []string)
type CobraCommand ¶
CobraCommand is an interface for commands that can refer back to their base cobra.Command
type Command ¶
type Command interface { InitCommand() InitCommandWithConfig(*config.Config) CobraCommand }
Command is the base command type for all commands.
type CommandContextKey ¶ added in v3.15.0
type CommandContextKey string
type Executor ¶
type Executor interface { Context() context.Context PushProgressUpdate(messages.Update) PushProgressStarted(msg string) PushProgressUpdateMessage(key, msg string) PushProgressSuccess(msg string) StopProgressLog() 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 Token() service.Token All() internal.AllServices Debug(msg string, args ...interface{}) WithLogger(args ...interface{}) Executor WithProgress(progress *progress.Progress) Executor }
Executor represents the execution context for commands
func NewExecutor ¶
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 ¶
type OfflineCommand interface {
DoesNotUseServices()
}
OfflineCommand is a command that does not need connect to the API, e.g. upctl version.