cmdline

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnvAppendValue

func EnvAppendValue(flag *pflag.Flag, value string) error

EnvAppendValue combines command line and environment var into a single argument

func EnvSetValue

func EnvSetValue(flag *pflag.Flag, value string) error

EnvSetValue set flag value if CLI option/argument is unset and env var is set

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

type EnvHandler func(*pflag.Flag, string) error

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 FlagError

type FlagError string

FlagError represents a flag error type

func (FlagError) Error

func (f FlagError) Error() string

type StringArray

type StringArray []string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL