Documentation
¶
Index ¶
- Constants
- Variables
- func CheckRequiredFlags(cmd *Command, ns string, localFlagsName ...string) error
- func CheckRequiredFlagsSets(cmd *Command, ns string, localFlagsNameSets ...[]string) error
- func CheckRequiredFlagsSetsIfPredicate(cmd *Command, ns string, localFlagsNameSets ...FlagNameSetWithPredicate) error
- func CmdConfigTest(t *testing.T, writer io.Writer, runner CmdRunnerTest)
- func ExecuteTestCases(t *testing.T, funcToTest func(c *CommandConfig) error, testCases []TestCase, ...)
- func GetFlagName(ns, flagName string) string
- func GetPrinter(noHeaders bool) printer.PrintService
- func PreCmdConfigTest(t *testing.T, writer io.Writer, preRunner PreCmdRunTest)
- func RequiresMinOptionsErr(cmd *Command, flagNames ...string) error
- func RequiresMultipleOptionsErr(cmd *Command, flagNamesSets ...[]string) error
- type CmdRunnerTest
- type Command
- func (c *Command) AddBoolFlag(name, shorthand string, defaultValue bool, desc string, ...)
- func (c *Command) AddCommand(commands ...*Command)
- func (c *Command) AddFloat32Flag(name, shorthand string, defaultValue float32, desc string, ...)
- func (c *Command) AddInt32Flag(name, shorthand string, defaultValue int32, desc string, ...)
- func (c *Command) AddIntFlag(name, shorthand string, defaultValue int, desc string, ...)
- func (c *Command) AddIntSliceFlag(name, shorthand string, defaultValue []int, desc string, ...)
- func (c *Command) AddIpFlag(name, shorthand string, defaultValue net.IP, desc string, ...)
- func (c *Command) AddIpSliceFlag(name, shorthand string, defaultValue []net.IP, desc string, ...)
- func (c *Command) AddSetFlag(name, shorthand, defaultValue string, allowed []string, desc string, ...)
- func (c *Command) AddStringFlag(name, shorthand, defaultValue, desc string, optionFunc ...FlagOptionFunc)
- func (c *Command) AddStringSliceFlag(name, shorthand string, defaultValue []string, desc string, ...)
- func (c *Command) AddStringToStringFlag(name, shorthand string, defaultValue map[string]string, desc string, ...)
- func (c *Command) AddUUIDFlag(name, shorthand, defaultValue, desc string, optionFunc ...FlagOptionFunc)
- func (c *Command) CommandPath() string
- func (c *Command) GetAnnotations() map[string]string
- func (c *Command) GetAnnotationsByKey(key string) string
- func (c *Command) GlobalFlags() *flag.FlagSet
- func (c *Command) IsAvailableCommand() bool
- func (c *Command) Name() string
- func (c *Command) SetFlagAnnotation(name, key string, values ...string)
- func (c *Command) SubCommands() []*Command
- type CommandBuilder
- type CommandConfig
- type CommandRun
- type FlagNameSetWithPredicate
- type FlagOptionFunc
- type FlagValuePair
- type PreCmdRunTest
- type PreCommandConfig
- type PreCommandRun
- type ResourcesMocksTest
- type SetFlag
- type TestCase
Constants ¶
const ( RequiredFlagsAnnotation = "RequiredFlags" DeprecatedFlagsAnnotation = "DeprecatedFlags" )
Variables ¶
var NoPreRun = func(c *PreCommandConfig) error { return nil }
var ( RootCmdTest = Command{ Command: &cobra.Command{ Use: testConst, }, } )
Functions ¶
func CheckRequiredFlags ¶
func CheckRequiredFlagsSets ¶
CheckRequiredFlagsSets focuses on commands that support multiple ways to run, and it is required at least one of the ways to be set. For example: for `datacenter delete`, it is required to be set either `--datacenter-id` option, either `--all` option.
func CheckRequiredFlagsSetsIfPredicate ¶
func CheckRequiredFlagsSetsIfPredicate(cmd *Command, ns string, localFlagsNameSets ...FlagNameSetWithPredicate) error
If a flag being set to a certain value creates some extra flag dependencies, then use this function!
func CmdConfigTest ¶
func CmdConfigTest(t *testing.T, writer io.Writer, runner CmdRunnerTest)
func ExecuteTestCases ¶
func ExecuteTestCases(t *testing.T, funcToTest func(c *CommandConfig) error, testCases []TestCase, cfg *CommandConfig)
func GetFlagName ¶
func GetPrinter ¶
func GetPrinter(noHeaders bool) printer.PrintService
TODO: Seems like there's no better way to Verbose print outside of 'commands' pkg, other than instantiating a PrintService as so. PrintService merits a refactor. It seems like without this exported func, I can only make Verbose prints if I am inside of a `commands` command object.
func PreCmdConfigTest ¶
func PreCmdConfigTest(t *testing.T, writer io.Writer, preRunner PreCmdRunTest)
func RequiresMinOptionsErr ¶
Types ¶
type CmdRunnerTest ¶
type CmdRunnerTest func(c *CommandConfig, mocks *ResourcesMocksTest)
type Command ¶
type Command struct {
// NS is the Global Namespace of the Command
NS string
Command *cobra.Command
// contains filtered or unexported fields
}
func NewCommand ¶
func NewCommand(ctx context.Context, parent *Command, info CommandBuilder) *Command
func (*Command) AddBoolFlag ¶
func (c *Command) AddBoolFlag(name, shorthand string, defaultValue bool, desc string, optionFunc ...FlagOptionFunc)
func (*Command) AddCommand ¶
func (*Command) AddFloat32Flag ¶
func (c *Command) AddFloat32Flag(name, shorthand string, defaultValue float32, desc string, optionFunc ...FlagOptionFunc)
func (*Command) AddInt32Flag ¶
func (c *Command) AddInt32Flag(name, shorthand string, defaultValue int32, desc string, optionFunc ...FlagOptionFunc)
func (*Command) AddIntFlag ¶
func (c *Command) AddIntFlag(name, shorthand string, defaultValue int, desc string, optionFunc ...FlagOptionFunc)
func (*Command) AddIntSliceFlag ¶
func (c *Command) AddIntSliceFlag(name, shorthand string, defaultValue []int, desc string, optionFunc ...FlagOptionFunc)
func (*Command) AddIpSliceFlag ¶
func (*Command) AddSetFlag ¶
func (c *Command) AddSetFlag(name, shorthand, defaultValue string, allowed []string, desc string, optionFunc ...FlagOptionFunc)
func (*Command) AddStringFlag ¶
func (c *Command) AddStringFlag(name, shorthand, defaultValue, desc string, optionFunc ...FlagOptionFunc)
func (*Command) AddStringSliceFlag ¶
func (c *Command) AddStringSliceFlag(name, shorthand string, defaultValue []string, desc string, optionFunc ...FlagOptionFunc)
func (*Command) AddStringToStringFlag ¶
func (*Command) AddUUIDFlag ¶
func (c *Command) AddUUIDFlag(name, shorthand, defaultValue, desc string, optionFunc ...FlagOptionFunc)
func (*Command) CommandPath ¶
func (*Command) GetAnnotations ¶
func (*Command) GetAnnotationsByKey ¶
func (*Command) GlobalFlags ¶
func (*Command) IsAvailableCommand ¶
func (*Command) SetFlagAnnotation ¶
func (*Command) SubCommands ¶
type CommandBuilder ¶
type CommandBuilder struct {
// Command is a Wrapper around Cobra Command
Command *Command
// Command Levels
// Namespace is the first level of the Command. e.g. [ionosctl] server
Namespace string
// Resource is the second level of the Command. e.g. [ionosctl server] volume
Resource string
// Verb is the 3rd level of the Command. e.g. [ionosctl server volume] attach
Verb string
// Short Description
ShortDesc string
// Long Description
LongDesc string
// Aliases
Aliases []string
// Example of Command run
Example string
// Command Run functions
// to be executed
PreCmdRun PreCommandRun
CmdRun CommandRun
// Init Client Services
InitClient bool
}
CommandBuilder contains information about the new Command to be used in Cobra Command
func (*CommandBuilder) GetNS ¶
func (c *CommandBuilder) GetNS() string
type CommandConfig ¶
type CommandConfig struct {
// Command is a Wrapper around Cobra Command
Command *Command
// CLI Engine
// NS is Global Namespace for all Command Levels
NS string
// Namespace is the first level of the Command. e.g. [ionosctl] server
Namespace string
// Resource is the second level of the Command. e.g. [ionosctl server] volume
Resource string
// Verb is the 3rd level of the Command. e.g. [ionosctl server volume] attach
Verb string
Stdin io.Reader
Printer printer.PrintService
// Services
CloudApiV6Services cloudapiv6.Services
AuthV1Services authV1.Services
CloudApiDbaasPgsqlServices cloudapidbaaspgsql.Services
CertificateManagerServices certmanager.Services
// Context
Context context.Context
// contains filtered or unexported fields
}
CommandConfig Properties and Services
func NewCommandCfg ¶
func NewCommandCfg(ctx context.Context, in io.Reader, p printer.PrintService, info CommandBuilder) (*CommandConfig, error)
type CommandRun ¶
type CommandRun func(commandConfig *CommandConfig) error
type FlagOptionFunc ¶
func DeprecatedFlagOption ¶
func DeprecatedFlagOption() FlagOptionFunc
func RequiredFlagOption ¶
func RequiredFlagOption() FlagOptionFunc
type FlagValuePair ¶
type FlagValuePair struct {
Flag string
Value interface{}
}
type PreCmdRunTest ¶
type PreCmdRunTest func(c *PreCommandConfig)
type PreCommandConfig ¶
type PreCommandConfig struct {
// Command is a Wrapper around Cobra Command
Command *Command
// NS is Global Namespace for all Command Levels
NS string
// Namespace is the first level of the Command. e.g. [ionosctl] server
Namespace string
// Resource is the second level of the Command. e.g. [ionosctl server] volume
Resource string
// Verb is the 3rd level of the Command. e.g. [ionosctl server volume] attach
Verb string
// Printer used in output formatting
Printer printer.PrintService
}
PreCommandConfig Properties
func NewPreCommandCfg ¶
func NewPreCommandCfg(p printer.PrintService, info CommandBuilder) *PreCommandConfig
type PreCommandRun ¶
type PreCommandRun func(commandConfig *PreCommandConfig) error
PreCommandRun will run in PreRun of Cobra Command structure, before running the actual Command. Its purpose is to keep the validate part separate from run part.
type ResourcesMocksTest ¶
type ResourcesMocksTest struct {
// Add New Services Resources Mocks
CloudApiV6Mocks cloudapiv6.ResourcesMocks
CloudApiDbaasPgsqlMocks cloudapidbaaspgsql.ResourcesMocks
AuthV1Mocks authv1.ResourcesMocks
}
type SetFlag ¶
SetFlag / Values set for this flag must be part of allowed values NOTE: Track progress of https://github.com/spf13/pflag/issues/236 : Might be implemented in pflag