Documentation
¶
Index ¶
- Constants
- Variables
- func InferDecodeHooks(c *cobra.Command, name, typename string) bool
- func InferDefineHooks(c *cobra.Command, name, short, descr string, structField reflect.StructField, ...) bool
- func StoreDecodeHookFunc(c *cobra.Command, flagname string, decodeM reflect.Value, target reflect.Type) error
- func StringToIntSliceHookFunc(sep string) mapstructure.DecodeHookFunc
- func StringToSlogLevelHookFunc() mapstructure.DecodeHookFunc
- func StringToZapcoreLevelHookFunc() mapstructure.DecodeHookFunc
- type DecodeHookFunc
- type DefineHookFunc
Constants ¶
const (
FlagDecodeHookAnnotation = "___leodido_structcli_flagdecodehooks"
)
Variables ¶
var AnnotationToDecodeHookRegistry map[string]mapstructure.DecodeHookFunc
AnnotationToDecodeHookRegistry maps annotation names to decode hook functions
var DecodeHookRegistry = map[string]decodingAnnotation{ "time.Duration": { "StringToTimeDurationHookFunc", mapstructure.StringToTimeDurationHookFunc(), }, "zapcore.Level": { "StringToZapcoreLevelHookFunc", StringToZapcoreLevelHookFunc(), }, "slog.Level": { "StringToSlogLevelHookFunc", StringToSlogLevelHookFunc(), }, "[]string": { "StringToSliceHookFunc", mapstructure.StringToSliceHookFunc(","), }, "[]int": { "StringToIntSliceHookFunc", StringToIntSliceHookFunc(","), }, }
var DefineHookRegistry = map[string]DefineHookFunc{ "zapcore.Level": DefineZapcoreLevelHookFunc(), "time.Duration": DefineTimeDurationHookFunc(), "slog.Level": DefineSlogLevelHookFunc(), }
DefineHookRegistry keeps track of the built-in flag definition functions
Functions ¶
func InferDefineHooks ¶
func InferDefineHooks(c *cobra.Command, name, short, descr string, structField reflect.StructField, fieldValue reflect.Value) bool
InferDefineHooks checks if there's a predefined flag definition function for the given type
func StoreDecodeHookFunc ¶
func StringToIntSliceHookFunc ¶
func StringToIntSliceHookFunc(sep string) mapstructure.DecodeHookFunc
StringToIntSliceHookFunc creates a decode hook that converts comma-separated string values to []int slices during configuration unmarshaling.
func StringToSlogLevelHookFunc ¶ added in v0.9.1
func StringToSlogLevelHookFunc() mapstructure.DecodeHookFunc
StringToSlogLevelHookFunc creates a decode hook that converts string values to slog.Level types during configuration unmarshaling.
func StringToZapcoreLevelHookFunc ¶
func StringToZapcoreLevelHookFunc() mapstructure.DecodeHookFunc
StringToZapcoreLevelHookFunc creates a decode hook that converts string values to zapcore.Level types during configuration unmarshaling.
Types ¶
type DecodeHookFunc ¶
type DefineHookFunc ¶
type DefineHookFunc func(name, short, descr string, structField reflect.StructField, fieldValue reflect.Value) (pflag.Value, string)
DefineHookFunc defines how to create a flag for a custom type.
It receives flag metadata and struct field information and must return a pflag.Value that knows how to set the underlying field's value, along with an optional enhanced description for the flag's usage message.
func DefineSlogLevelHookFunc ¶ added in v0.9.1
func DefineSlogLevelHookFunc() DefineHookFunc
DefineSlogLevelHookFunc creates a flag definition function for slog.Level.
It returns an enum flag that implements pflag.Value.
func DefineTimeDurationHookFunc ¶
func DefineTimeDurationHookFunc() DefineHookFunc
func DefineZapcoreLevelHookFunc ¶
func DefineZapcoreLevelHookFunc() DefineHookFunc
DefineZapcoreLevelHookFunc creates a flag definition function for zapcore.Level.
It returns an enum flag that implements pflag.Value.