Documentation
¶
Index ¶
- Constants
- func AssignFieldValue(structValue reflect.Value, fv *FlagValue, args []string, isStdinAvailable bool) error
- func GetFieldByPath(structValue reflect.Value, fieldPath []int) reflect.Value
- func PopulateFromRequest(optsValue reflect.Value, fields []FieldInfo, flagMap map[string]string, ...) error
- type FieldInfo
- type FlagValue
Constants ¶
const ARGS = "__args__"
Variables ¶
This section is empty.
Functions ¶
func AssignFieldValue ¶
func AssignFieldValue(structValue reflect.Value, fv *FlagValue, args []string, isStdinAvailable bool) error
AssignFieldValue assigns a flag value to a struct field using the field path
func GetFieldByPath ¶
GetFieldByPath navigates through embedded structs using field indices
func PopulateFromRequest ¶
func PopulateFromRequest(optsValue reflect.Value, fields []FieldInfo, flagMap map[string]string, args []string) error
PopulateFromRequest fills optsValue by parsing flagMap and args directly, without touching any shared pflag pointer. This is the entry point used by the HTTP data-func dispatcher in cobra_command.go.
The CLI path keeps the existing pflag-backed pipeline (AssignFieldValue); only the HTTP path benefits from per-request isolation. Concurrent requests allocate their own optsValue, so no locking is required.
Precedence per field: explicit flagMap[FlagName] → args (for the IsArgs field) → DefaultValue → type zero value. Stdin is intentionally skipped on this path — HTTP requests have no terminal.
Types ¶
type FieldInfo ¶
type FieldInfo struct {
FieldName string
FieldPath []int // Indices to navigate from root struct to this field
FieldType reflect.Type
FlagName string
Help string
DefaultValue string
ShortFlag string
Required bool
IsStdin bool
IsArgs bool
}
FieldInfo contains metadata about a struct field for flag parsing
type FlagValue ¶
type FlagValue struct {
FieldName string
FieldPath []int // Field indices for navigating embedded structs
FieldType reflect.Type
DefaultValue string
Required bool
IsStdin bool
IsArgs bool
StringPtr *string
IntPtr *int
BoolPtr *bool
StringSlicePtr *[]string
IntSlicePtr *[]int
DurationPtr *duration.Duration
TimePtr *time.Time
}
FlagValue holds information about a flag and its binding