Documentation
¶
Index ¶
- Constants
- func AllowedValues(flag *pflag.Flag) []string
- 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
- func SetAllowedValues(flag *pflag.Flag, values ...string)
- type FieldInfo
- type FileReadPolicy
- type FlagValue
- type RequestOption
Constants ¶
const ARGS = "__args__"
Variables ¶
This section is empty.
Functions ¶
func AllowedValues ¶ added in v1.21.57
AllowedValues returns the schema values attached by SetAllowedValues.
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, options ...RequestOption) 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.
func SetAllowedValues ¶ added in v1.21.57
SetAllowedValues attaches the values accepted by a flag for schema consumers.
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
Hidden bool
IsStdin bool
IsArgs bool
// CLIFileRead and RPCFileRead opt the field into `@file`/`@url` expansion,
// from `clicky:"cli-file-read"` and `clicky:"rpc-file-read"`. They are
// separate because the two paths read from different machines: the CLI
// reads the operator's disk, the RPC handler reads the server's. See
// fileaccess.go.
CLIFileRead bool
RPCFileRead bool
// Enum is the field's closed set of accepted values, from an
// `enum:"a,b,c"` tag. It travels into the OpenAPI parameter and the
// published action schema, so a front end renders the real choices instead
// of hardcoding a list that drifts from the server's.
Enum []string
}
FieldInfo contains metadata about a struct field for flag parsing
type FileReadPolicy ¶ added in v1.21.60
type FileReadPolicy struct {
// Enabled is the field's opt-in for this path. False passes the value
// through untouched.
Enabled bool
// Remote marks a value that arrived over the network. It tightens the URL
// rules, because a server fetching a caller-supplied URL can reach hosts
// the caller cannot.
Remote bool
// contains filtered or unexported fields
}
FileReadPolicy decides whether an `@` value may be expanded, and how strictly.
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
CLIFileRead 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
type RequestOption ¶ added in v1.21.60
type RequestOption func(*populateRequestOptions)
RequestOption customizes request-scoped argument decoding.
func WithRequestContext ¶ added in v1.21.60
func WithRequestContext(ctx context.Context) RequestOption
WithRequestContext propagates request cancellation into file and URL expansion.