Documentation
¶
Index ¶
- Constants
- Variables
- func AllowedValues(flag *pflag.Flag) []string
- func AssignFieldValue(structValue reflect.Value, fv *FlagValue, args []string, isStdinAvailable bool) error
- func Category(flag *pflag.Flag) string
- 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)
- func SetCategory(flag *pflag.Flag, category string)
- func SetSpreadsheetReader(reader SpreadsheetReader)
- func SetURLFetcher(f URLFetcher)
- type FieldInfo
- type FileReadPolicy
- type FileReference
- type FileReferenceOptions
- type FlagValue
- type RequestOption
- type SpreadsheetReader
- type URLFetcher
Constants ¶
const ( CategoryModelSelection = "Model selection" CategoryModelPermissions = "Model permissions" CategoryModelRuntime = "Model runtime" CategoryFormatting = "Formatting" CategoryLogging = "Logging" CategoryTasks = "Tasks" )
const ARGS = "__args__"
const CategoryAnnotation = "clicky_category"
CategoryAnnotation stores the display category used by grouped CLI help.
Variables ¶
var ErrNoSpreadsheetReader = errors.New("no spreadsheet reader configured: call excel.Use() from github.com/flanksource/clicky/formatters/excel")
var ErrNoURLFetcher = errors.New("no URL fetcher configured: call urlfetch.Use() from github.com/flanksource/clicky/flags/urlfetch")
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 Category ¶ added in v1.21.83
Category returns a flag's category, or empty for an uncategorized flag.
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.
func SetCategory ¶ added in v1.21.83
SetCategory assigns a display category to a registered flag.
func SetSpreadsheetReader ¶ added in v1.21.83
func SetSpreadsheetReader(reader SpreadsheetReader)
func SetURLFetcher ¶ added in v1.21.83
func SetURLFetcher(f URLFetcher)
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
Category string
DefaultValue string
ShortFlag string
Required bool
Hidden bool
IsStdin bool
IsArgs bool
LiteralSlice 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 FileReference ¶ added in v1.21.67
type FileReference struct {
Name string
Body io.ReadCloser
}
FileReference retains the source name so callers can identify binary formats.
func OpenFileReference ¶ added in v1.21.67
func OpenFileReference(ctx context.Context, value string, options FileReferenceOptions) (FileReference, error)
OpenFileReference opens a binary @file or @http(s) reference without converting its bytes to a string. The caller owns the returned Body.
type FileReferenceOptions ¶ added in v1.21.67
type FileReferenceOptions struct {
// BaseDir anchors relative paths; empty uses the working directory.
BaseDir string
// Root confines local files to this real directory. Remote callers must set
// it or Roots.
Root string
// Roots extends Root: a local file is accepted when it lies under Root or any
// of these. Every entry must exist.
Roots []string
// Remote uses defensive HTTP and forbids unrooted local files.
Remote bool
}
FileReferenceOptions controls binary @file/@url access.
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
Float64Ptr *float64
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.
type SpreadsheetReader ¶ added in v1.21.83
SpreadsheetReader returns the first worksheet's name and its rows. It backs @data.xlsx:Column flag values; opt in with excel.Use() from github.com/flanksource/clicky/formatters/excel.
type URLFetcher ¶ added in v1.21.83
type URLFetcher interface {
// Fetch GETs url. defensive is set for values supplied by remote (RPC)
// callers, which must be guarded against SSRF.
Fetch(ctx context.Context, url string, defensive bool) (*http.Response, error)
}
URLFetcher performs the HTTP GET behind @http(s) file references. The core package ships none, so binaries that never read URLs don't compile an HTTP client stack; opt in with urlfetch.Use().