requestflag

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckInnerFlags

func CheckInnerFlags(cmd cli.Command) error

Helper function to verify that all inner flags have an outer flag set and follow the --foo.baz prefix format

func GetMissingRequiredFlags

func GetMissingRequiredFlags(cmd *cli.Command, body any) []cli.Flag

func WithInnerFlags

func WithInnerFlags(cmd cli.Command, innerFlagMap map[string][]HasOuterFlag) cli.Command

WithInnerFlags takes a command and a map of flag names to inner flags, and returns a modified command with the appropriate inner flags set.

Types

type DateTimeValue

type DateTimeValue string

func (*DateTimeValue) Parse

func (d *DateTimeValue) Parse(s string) error

func (DateTimeValue) String

func (d DateTimeValue) String() string

type DateValue

type DateValue string

Time-related value types

func (*DateValue) Parse

func (d *DateValue) Parse(s string) error

Parse methods for time-related types

func (DateValue) String

func (d DateValue) String() string

String methods for time-related types

type Flag

type Flag[
	T []any | []map[string]any | []DateTimeValue | []DateValue | []TimeValue | []string |
		[]float64 | []int64 | []bool | any | map[string]any | DateTimeValue | DateValue | TimeValue |
		string | float64 | int64 | bool,
] struct {
	Name        string               // name of the flag
	Category    string               // category of the flag, if any
	DefaultText string               // default text of the flag for usage purposes
	HideDefault bool                 // whether to hide the default value in output
	Usage       string               // usage string for help output
	Sources     cli.ValueSourceChain // sources to load flag value from
	Required    bool                 // whether the flag is required or not
	Hidden      bool                 // whether to hide the flag in help output
	Default     T                    // default value for this flag if not set by from any source
	Aliases     []string             // aliases that are allowed for this flag
	Validator   func(T) error        // custom function to validate this flag value

	QueryPath  string // location in the request query string to put this flag's value
	HeaderPath string // location in the request header to put this flag's value
	BodyPath   string // location in the request body to put this flag's value
	BodyRoot   bool   // if true, then use this value as the entire request body

	// Const, when true, marks this flag as a constant. The flag's Default value is used as the fixed value
	// and always included in the request (IsSet returns true). The user can still see and override the flag,
	// but isn't required to provide it. This is used for single-value enums and `x-stainless-const`
	// parameters.
	Const bool

	// FileInput, when true, indicates that the flag value is always treated as a file path. The file is read
	// automatically without requiring the "@" prefix. This is used for parameters with `type: string, format:
	// binary` in the OpenAPI spec.
	FileInput bool

	// DataAliases is a list of alternate names for this parameter recognized when parsing piped YAML/JSON
	// input. Values keyed by any alias are translated to the canonical API name before being sent.
	DataAliases []string
	// contains filtered or unexported fields
}

Flag [T] is a generic flag base which can be used to implement the most common interfaces used by urfave/cli. Additionally, it allows specifying where in an HTTP request the flag values should be placed (e.g. query, body, etc.).

func (*Flag[T]) Count

func (f *Flag[T]) Count() int

func (*Flag[T]) Get

func (f *Flag[T]) Get() any

func (Flag[T]) GetBodyPath

func (f Flag[T]) GetBodyPath() string

func (*Flag[T]) GetCategory

func (f *Flag[T]) GetCategory() string

func (Flag[T]) GetDataAliases added in v1.2.0

func (f Flag[T]) GetDataAliases() []string

func (*Flag[T]) GetDefaultText

func (f *Flag[T]) GetDefaultText() string

func (*Flag[T]) GetEnvVars

func (f *Flag[T]) GetEnvVars() []string

GetEnvVars returns the env vars for this flag

func (Flag[T]) GetHeaderPath

func (f Flag[T]) GetHeaderPath() string

func (Flag[T]) GetQueryPath

func (f Flag[T]) GetQueryPath() string

func (*Flag[T]) GetUsage

func (f *Flag[T]) GetUsage() string

func (*Flag[T]) GetValue

func (f *Flag[T]) GetValue() string

func (Flag[T]) IsBodyRoot

func (f Flag[T]) IsBodyRoot() bool

func (*Flag[T]) IsBoolFlag

func (f *Flag[T]) IsBoolFlag() bool

func (*Flag[T]) IsDefaultVisible

func (f *Flag[T]) IsDefaultVisible() bool

func (Flag[T]) IsFileInput

func (f Flag[T]) IsFileInput() bool

func (Flag[T]) IsLocal

func (f Flag[T]) IsLocal() bool

func (*Flag[T]) IsMultiValueFlag

func (f *Flag[T]) IsMultiValueFlag() bool

func (*Flag[T]) IsRequired

func (f *Flag[T]) IsRequired() bool

func (*Flag[T]) IsRequiredAsFlagOrStdin

func (f *Flag[T]) IsRequiredAsFlagOrStdin() bool

func (*Flag[T]) IsSet

func (f *Flag[T]) IsSet() bool

func (*Flag[T]) IsVisible

func (f *Flag[T]) IsVisible() bool

func (*Flag[T]) Names

func (f *Flag[T]) Names() []string

func (*Flag[T]) PostParse

func (f *Flag[T]) PostParse() error

func (*Flag[T]) PreParse

func (f *Flag[T]) PreParse() error

func (*Flag[T]) Set

func (f *Flag[T]) Set(name string, val string) error

func (*Flag[T]) SetCategory

func (f *Flag[T]) SetCategory(c string)

func (*Flag[T]) SetInnerField

func (f *Flag[T]) SetInnerField(field string, val any)

func (*Flag[T]) String

func (f *Flag[T]) String() string

func (*Flag[T]) TakesValue

func (f *Flag[T]) TakesValue() bool

func (*Flag[T]) TypeName

func (f *Flag[T]) TypeName() string

type HasOuterFlag

type HasOuterFlag interface {
	cli.Flag
	SetOuterFlag(cli.Flag)
	GetOuterFlag() cli.Flag
	GetInnerField() string
	GetDataAliases() []string
}

type InRequest

type InRequest interface {
	GetQueryPath() string
	GetHeaderPath() string
	GetBodyPath() string
	IsBodyRoot() bool
	IsFileInput() bool
	GetDataAliases() []string
}

InRequest interface for flags that should be included in HTTP requests

type InnerFlag

type InnerFlag[
	T []any | []map[string]any | []DateTimeValue | []DateValue | []TimeValue | []string |
		[]float64 | []int64 | []bool | any | map[string]any | DateTimeValue | DateValue | TimeValue |
		string | float64 | int64 | bool,
] struct {
	Name        string        // name of the flag
	DefaultText string        // default text of the flag for usage purposes
	Usage       string        // usage string for help output
	Aliases     []string      // aliases that are allowed for this flag
	Validator   func(T) error // custom function to validate this flag value

	OuterFlag   cli.Flag // The flag on which this inner flag will set values
	InnerField  string   // The inner field which this flag will set
	DataAliases []string // alternate names recognized in YAML values passed as the outer flag
}

InnerFlag[T] represents a CLI flag for the urfave/cli package that allows setting nested fields within other flags. For example, using `--foo.baz` will set the "baz" field on a parent flag named `--foo`.

func (*InnerFlag[T]) Get

func (f *InnerFlag[T]) Get() any

func (*InnerFlag[T]) GetDataAliases added in v1.2.0

func (f *InnerFlag[T]) GetDataAliases() []string

GetDataAliases returns the aliases recognized when parsing inner field keys from piped or flag YAML.

func (*InnerFlag[T]) GetDefaultText

func (f *InnerFlag[T]) GetDefaultText() string

func (*InnerFlag[T]) GetEnvVars

func (f *InnerFlag[T]) GetEnvVars() []string

func (*InnerFlag[T]) GetInnerField added in v1.2.0

func (f *InnerFlag[T]) GetInnerField() string

GetInnerField returns the API field name that this inner flag sets on its outer flag's value. For example, the flag --parent.foo targeting a parameter whose OpenAPI property name is "foo" would return "foo". This is distinct from the flag's CLI name and from any DataAliases entries.

func (*InnerFlag[T]) GetOuterFlag

func (f *InnerFlag[T]) GetOuterFlag() cli.Flag

func (*InnerFlag[T]) GetUsage

func (f *InnerFlag[T]) GetUsage() string

func (*InnerFlag[T]) GetValue

func (f *InnerFlag[T]) GetValue() string

func (*InnerFlag[T]) IsBoolFlag

func (f *InnerFlag[T]) IsBoolFlag() bool

func (*InnerFlag[T]) IsDefaultVisible

func (f *InnerFlag[T]) IsDefaultVisible() bool

func (*InnerFlag[T]) IsMultiValueFlag

func (f *InnerFlag[T]) IsMultiValueFlag() bool

func (*InnerFlag[T]) IsSet

func (f *InnerFlag[T]) IsSet() bool

func (*InnerFlag[T]) Names

func (f *InnerFlag[T]) Names() []string

func (*InnerFlag[T]) PostParse

func (f *InnerFlag[T]) PostParse() error

func (*InnerFlag[T]) PreParse

func (f *InnerFlag[T]) PreParse() error

func (*InnerFlag[T]) Set

func (f *InnerFlag[T]) Set(name string, rawVal string) error

func (*InnerFlag[T]) SetOuterFlag

func (f *InnerFlag[T]) SetOuterFlag(flag cli.Flag)

func (*InnerFlag[T]) String

func (f *InnerFlag[T]) String() string

func (*InnerFlag[T]) TakesValue

func (f *InnerFlag[T]) TakesValue() bool

func (*InnerFlag[T]) TypeName

func (f *InnerFlag[T]) TypeName() string

type RequestContents

type RequestContents struct {
	Queries map[string]any
	Headers map[string]any
	Body    any
}

The values that will be sent in different parts of a request.

func ExtractRequestContents

func ExtractRequestContents(cmd *cli.Command) RequestContents

Extract query parameters, headers, and body values from command flags.

type RequiredFlagOrStdin

type RequiredFlagOrStdin interface {
	IsRequiredAsFlagOrStdin() bool
}

type SettableInnerField

type SettableInnerField interface {
	SetInnerField(string, any)
}

Allow setting inner fields on other flags (e.g. --foo.baz can set the "baz" field on the --foo flag)

type TimeValue

type TimeValue string

func (*TimeValue) Parse

func (t *TimeValue) Parse(s string) error

func (TimeValue) String

func (t TimeValue) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL