Documentation
¶
Index ¶
- Constants
- Variables
- func AddFlag[T any](cmd *cobra.Command, dest *T, name string, defaultValue T, help string, ...) error
- func FindUndefinedFlagEnvVarsInEnviron() []string
- func GetDefinedFlagEnvVarRegexes() map[FlagRegexExpr]*regexp.Regexp
- func NewGroupCommand(ctx context.Context, use, short, long string, group *CommandGroup, ...) *cobra.Command
- func NewRootCommand(ctx context.Context, use, long string) *cobra.Command
- func NewSubCommand(ctx context.Context, use, short, long string, priority int, ...) *cobra.Command
- func SetSubCommandAnnotations(cmd *cobra.Command, priority int, group *CommandGroup)
- type AddFlagOptions
- type CommandGroup
- type FlagGroup
- type FlagRegexExpr
- func GetFlagGlobalAndLocalEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
- func GetFlagGlobalAndLocalMultiEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
- func GetFlagGlobalEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
- func GetFlagGlobalMultiEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
- func GetFlagLocalEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
- func GetFlagLocalMultiEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
- func NewFlagRegexExpr(expr, human string) *FlagRegexExpr
- type FlagType
- type GetFlagEnvVarRegexesInterface
- type GroupCommandOptions
- type SubCommandOptions
Constants ¶
const ( CommandGroupIDAnnotationName = "group-id" CommandGroupTitleAnnotationName = "group-title" CommandGroupPriorityAnnotationName = "group-priority" )
const ( FlagGroupIDAnnotationName = "group-id" FlagGroupTitleAnnotationName = "group-title" FlagGroupPriorityAnnotationName = "group-priority" )
const CommandPriorityAnnotationName = "command-priority"
Variables ¶
var (
FlagEnvVarsPrefix string
)
Functions ¶
func AddFlag ¶
func AddFlag[T any](cmd *cobra.Command, dest *T, name string, defaultValue T, help string, opts AddFlagOptions) error
Create and bind a flag to the Cobra command. Corresponding environment variables (if enabled) parsed and the value is assigned to the flag immediately. Flag value type inferred from destination arg.
func FindUndefinedFlagEnvVarsInEnviron ¶
func FindUndefinedFlagEnvVarsInEnviron() []string
Get a full list of environment variables that have FlagEnvVarsPrefix as a prefix but were not defined with AddFlag function.
func GetDefinedFlagEnvVarRegexes ¶
func GetDefinedFlagEnvVarRegexes() map[FlagRegexExpr]*regexp.Regexp
func NewGroupCommand ¶
func NewGroupCommand(ctx context.Context, use, short, long string, group *CommandGroup, options GroupCommandOptions) *cobra.Command
func NewSubCommand ¶
func SetSubCommandAnnotations ¶
func SetSubCommandAnnotations(cmd *cobra.Command, priority int, group *CommandGroup)
Types ¶
type AddFlagOptions ¶
type AddFlagOptions struct {
// This function must return a slice of regexps to be matched agains all environment variables.
// Values of matched environment variables will become the flag value. Values priority (from
// lowest to highest): flag default value -> environment variable value (from first to last
// regexp; if regexp matches multiple env vars then the last has higher priority) -> cli flag
// value. For slice and map-type flags: all env vars values and all cli flags values are joined.
GetEnvVarRegexesFunc GetFlagEnvVarRegexesInterface
// Group info is saved in Flag annotations, which can be used later, e.g. for grouping flags in
// the --help output.
Group *FlagGroup
Type FlagType
ShortName string
Deprecated bool
Hidden bool
Required bool
NoSplitOnCommas bool
}
type CommandGroup ¶
type CommandGroup struct {
// Unique group identifier.
ID string
// Human-readable group title, expected to be used in the usage output.
Title string
// CommandGroup priority, expected to be used to sort groups in the usage output.
Priority int
}
func NewCommandGroup ¶
func NewCommandGroup(id, title string, priority int) *CommandGroup
type FlagGroup ¶
type FlagGroup struct {
// Unique group identifier.
ID string
// Human-readable group title, expected to be used in the usage output.
Title string
// FlagGroup priority, expected to be used to sort groups in the usage output.
Priority int
}
func NewFlagGroup ¶
type FlagRegexExpr ¶
func GetFlagGlobalAndLocalEnvVarRegexes ¶
func GetFlagGlobalAndLocalEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
Return env var regexps in the form of "^NELM_AUTO_ROLLBACK$" and "^NELM_RELEASE_DEPLOY_AUTO_ROLLBACK$". The latter has higher priority. The format is "^<prefix><flag_name>$" and "^<prefix><command_path>_<flag_name>$".
func GetFlagGlobalAndLocalMultiEnvVarRegexes ¶
func GetFlagGlobalAndLocalMultiEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
Return env var regexps in the form of "^NELM_LABELS_.+" and "^NELM_RELEASE_DEPLOY_LABELS_.+". // The format is "^<prefix><flag_name>_.+" and "^<prefix><command_path>_<flag_name>_.+".
func GetFlagGlobalEnvVarRegexes ¶
func GetFlagGlobalEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
Return env var regexp in the form of "^NELM_AUTO_ROLLBACK$". The format is "^<prefix><flag_name>$".
func GetFlagGlobalMultiEnvVarRegexes ¶
func GetFlagGlobalMultiEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
Return env var regexp in the form of "^NELM_LABELS_.+". The format is "^<prefix><flag_name>_.+".
func GetFlagLocalEnvVarRegexes ¶
func GetFlagLocalEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
Return env var regexp in the form of "^NELM_RELEASE_DEPLOY_AUTO_ROLLBACK$". The format is "^<prefix><command_path>_<flag_name>$".
func GetFlagLocalMultiEnvVarRegexes ¶
func GetFlagLocalMultiEnvVarRegexes(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
Return env var regexp in the form of "^NELM_RELEASE_DEPLOY_LABELS_.+". The format is "^<prefix><command_path>_<flag_name>_.+".
func NewFlagRegexExpr ¶
func NewFlagRegexExpr(expr, human string) *FlagRegexExpr
type GetFlagEnvVarRegexesInterface ¶
type GetFlagEnvVarRegexesInterface func(cmd *cobra.Command, flagName string) ([]*FlagRegexExpr, error)
type GroupCommandOptions ¶
type GroupCommandOptions struct{}
type SubCommandOptions ¶
type SubCommandOptions struct {
Args cobra.PositionalArgs
ValidArgsFunction func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
}