Documentation ¶
Index ¶
- func EnvAppendValue(flag *pflag.Flag, value string) error
- func EnvSetValue(flag *pflag.Flag, value string) error
- type CommandError
- type CommandManager
- func (m *CommandManager) GetCmd(name string) *cobra.Command
- func (m *CommandManager) GetCmdGroup(name string) []*cobra.Command
- func (m *CommandManager) GetCmdName(cmd *cobra.Command) string
- func (m *CommandManager) GetError() []error
- func (m *CommandManager) GetRootCmd() *cobra.Command
- func (m *CommandManager) RegisterCmd(cmd *cobra.Command)
- func (m *CommandManager) RegisterFlagForCmd(flag *Flag, cmds ...*cobra.Command)
- func (m *CommandManager) RegisterSubCmd(parentCmd, childCmd *cobra.Command)
- func (m *CommandManager) SetCmdGroup(name string, cmds ...*cobra.Command)
- func (m *CommandManager) UpdateCmdFlagFromEnv(cmd *cobra.Command, precedence int, foundKeys map[string]string) error
- type EnvHandler
- type Flag
- type FlagError
- type StringArray
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvAppendValue ¶
EnvAppendValue combines command line and environment var into a single argument
Types ¶
type CommandError ¶
type CommandError string
CommandError represents a command error type
func (CommandError) Error ¶
func (c CommandError) Error() string
type CommandManager ¶
type CommandManager struct {
// contains filtered or unexported fields
}
CommandManager holds root command or first parent can stores group of command. A command group can be composed of one or many commands
func NewCommandManager ¶
func NewCommandManager(rootCmd *cobra.Command) *CommandManager
NewCommandManager instantiates a CommandManager.
func (*CommandManager) GetCmd ¶
func (m *CommandManager) GetCmd(name string) *cobra.Command
GetCmd returns a single command based on its unique group name. If the command group has more than one command this function return a nil command instead.
func (*CommandManager) GetCmdGroup ¶
func (m *CommandManager) GetCmdGroup(name string) []*cobra.Command
GetCmdGroup returns all commands associated with the group name
func (*CommandManager) GetCmdName ¶
func (m *CommandManager) GetCmdName(cmd *cobra.Command) string
GetCmdName returns name associated with the provided command. If command is named "child" and has two parents named "parent1" and "parent2", this function will return "parent1_parent2_child". Passing the root command to this function returns an empty string.
func (*CommandManager) GetError ¶
func (m *CommandManager) GetError() []error
GetError returns the error pool.
func (*CommandManager) GetRootCmd ¶
func (m *CommandManager) GetRootCmd() *cobra.Command
GetRootCmd returns the root command
func (*CommandManager) RegisterCmd ¶
func (m *CommandManager) RegisterCmd(cmd *cobra.Command)
RegisterCmd registers a child command of the root command. The registered command is automatically affected to a unique group containing this command only, the group name is based on the command name
func (*CommandManager) RegisterFlagForCmd ¶
func (m *CommandManager) RegisterFlagForCmd(flag *Flag, cmds ...*cobra.Command)
RegisterFlagForCmd registers a flag for one or many commands
func (*CommandManager) RegisterSubCmd ¶
func (m *CommandManager) RegisterSubCmd(parentCmd, childCmd *cobra.Command)
RegisterSubCmd registers a child command for parent command given as argument. The registered command is automatically affected to a unique group containing this command only, the group name is based on the command name appended to parents command name (see GetCmdName for details)
func (*CommandManager) SetCmdGroup ¶
func (m *CommandManager) SetCmdGroup(name string, cmds ...*cobra.Command)
SetCmdGroup creates a unique group of commands identified by name. If group already exists or empty command is passed, this function will panic
func (*CommandManager) UpdateCmdFlagFromEnv ¶
func (m *CommandManager) UpdateCmdFlagFromEnv(cmd *cobra.Command, precedence int, foundKeys map[string]string) error
UpdateCmdFlagFromEnv updates flag's values based on environment variables associated with all flags belonging to command provided as argument
type EnvHandler ¶
EnvHandler defines an environment handler type to set flag's values from environment variables
type Flag ¶
type Flag struct { ID string Value interface{} DefaultValue interface{} Name string ShortHand string Usage string Tag string Deprecated string Hidden bool Required bool EnvKeys []string EnvHandler EnvHandler // Export envar also without prefix WithoutPrefix bool }
Flag holds information about a command flag
type StringArray ¶
type StringArray []string