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 FlagAsVariable(flag string) string
- func FlagUsage(flag string) string
- func FlagsUsage(flags ...string) string
- 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) AddDurationFlag(name, shorthand string, defaultValue time.Duration, desc string, ...)
- 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) AddInt32VarFlag(address *int32, 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) AddStringSliceVarFlag(address *[]string, name, shorthand string, defaultValue []string, desc string, ...)
- func (c *Command) AddStringToStringFlag(name, shorthand string, defaultValue map[string]string, desc string, ...)
- func (c *Command) AddStringToStringVarFlag(v *map[string]string, name, shorthand string, defaultValue map[string]string, ...)
- func (c *Command) AddStringVarFlag(address *string, name, shorthand, value, 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 FlagAsVariable ¶ added in v6.6.7
FlagAsVariable takes a flag name and returns it as a screaming camel case
e.g. `FlagAsVariable("datacenter-id") -> "DATACENTER_ID"
func FlagUsage ¶ added in v6.6.7
FlagUsage ("datacenter-id") -> "--datacenter-id DATACENTER_ID"
Used as a convenience func
func FlagsUsage ¶ added in v6.6.7
FlagsUsage calls FlagUsage for every flag in the slice
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) AddDurationFlag ¶ added in v6.6.0
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) AddInt32VarFlag ¶ added in v6.6.0
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)
AddSetFlag adds a String slice flag with support for limitation to certain values in a slice. It also adds completions for those limited values, on top of throwing an error if the flag value isn't found among the marked valid values
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) AddStringSliceVarFlag ¶ added in v6.6.0
func (*Command) AddStringToStringFlag ¶
func (*Command) AddStringToStringVarFlag ¶ added in v6.6.0
func (*Command) AddStringVarFlag ¶ added in v6.6.0
func (c *Command) AddStringVarFlag(address *string, name, shorthand, value, desc string, optionFunc ...FlagOptionFunc)
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 authservice.Services CloudApiDbaasPgsqlServices cloudapidbaaspgsql.Services CertificateManagerServices certmanager.Services ContainerRegistryServices container_registry.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(help string) 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 authservice.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