Documentation
¶
Index ¶
- Constants
- func NewInvalidParameterSpecError(reason string) error
- func RegisterServerFlag(cmd *cobra.Command, defaultServer string)
- func WithAuth(ctx context.Context, a *AuthScheme) context.Context
- type AuthScheme
- type Parameter
- type ParameterSet
- func (ps ParameterSet) ArgsUsage() string
- func (ps ParameterSet) InjectPathValues(endpoint string) string
- func (ps ParameterSet) InjectValues(str string) string
- func (ps ParameterSet) Optional() ParameterSet
- func (ps ParameterSet) RegisterAsFlags(cmd *cobra.Command)
- func (ps ParameterSet) RegisterFlags(flags *pflag.FlagSet)
- func (ps ParameterSet) Required() ParameterSet
- func (ps ParameterSet) ResolveFromFlags(cmd *cobra.Command)
- func (ps ParameterSet) ResolveValues(cmd *cobra.Command, args []string) error
- func (ps ParameterSet) Validate() error
- type Provider
Constants ¶
const ( FlagServer = "server" FlagToken = "token" FlagUsername = "username" FlagPassword = "password" FlagAPIKey = "api-key" )
Names of the app-level persistent flags used for server selection and auth.
const ( AuthBearer = "bearer" AuthBasic = "basic" AuthAPIKey = "apikey" )
Auth scheme types.
const ( // BoolParamType is a bool parameter. BoolParamType = "bool" // IntParamType is an int parameter. IntParamType = "int" // NumberParamType is a number parameter. NumberParamType = "number" // StringParamType is a string parameter. StringParamType = "string" )
Variables ¶
This section is empty.
Functions ¶
func NewInvalidParameterSpecError ¶
NewInvalidParameterSpecError creates a new error indicating that a parameter spec is invalid.
func RegisterServerFlag ¶ added in v0.6.0
RegisterServerFlag registers the persistent --server override flag.
Types ¶
type AuthScheme ¶ added in v0.6.0
type AuthScheme struct {
Type string `json:"type" yaml:"type"` // bearer | basic | apikey
In string `json:"in,omitempty" yaml:"in,omitempty"` // header | query (apikey)
Name string `json:"name,omitempty" yaml:"name,omitempty"` // header/query name (apikey)
}
AuthScheme describes how requests are authenticated, surfaced as CLI flags with CLIC_* environment-variable fallback.
func AuthFromContext ¶ added in v0.6.0
func AuthFromContext(ctx context.Context) *AuthScheme
AuthFromContext returns the auth scheme carried by the context, if any.
func (*AuthScheme) Apply ¶ added in v0.6.0
func (a *AuthScheme) Apply(req *http.Request, flags *pflag.FlagSet)
Apply adds credentials to the request, reading values from the given flags and falling back to CLIC_* environment variables.
func (*AuthScheme) RegisterFlags ¶ added in v0.6.0
func (a *AuthScheme) RegisterFlags(cmd *cobra.Command)
RegisterFlags registers the persistent auth flags for this scheme.
type Parameter ¶
type Parameter struct {
Name string `json:"name" yaml:"name"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Type string `json:"type" yaml:"type"`
Required bool `json:"required" yaml:"required"`
Default any `json:"default,omitempty" yaml:"default,omitempty"`
AsFlag string `json:"as_flag,omitempty" yaml:"as_flag,omitempty"`
// contains filtered or unexported fields
}
A Parameter specifies a command parameter.
func NewParameter ¶
NewParameter creates a new Parameter from the provided spec.
func (*Parameter) CLIFlagName ¶
CLIFlagName returns the parameter name formatted as a CLI flag name. The original Name is preserved for use as the request key (header/query/body); only the flag spelling is normalized to lower-kebab-case.
func (*Parameter) SetDefaultValue ¶
func (param *Parameter) SetDefaultValue()
SetDefaultValue assigns the default value to the parameter.
type ParameterSet ¶
type ParameterSet []*Parameter
A ParameterSet is a slice of parameter pointers.
func (ParameterSet) ArgsUsage ¶ added in v0.5.0
func (ps ParameterSet) ArgsUsage() string
ArgsUsage returns a usage string describing the set's required positional arguments.
func (ParameterSet) InjectPathValues ¶ added in v0.6.0
func (ps ParameterSet) InjectPathValues(endpoint string) string
InjectPathValues substitutes {name} placeholders in a URL path template with the URL-escaped values of the matching parameters.
func (ParameterSet) InjectValues ¶
func (ps ParameterSet) InjectValues(str string) string
InjectValues replaces all param references with their corresponding values in the given string.
func (ParameterSet) Optional ¶
func (ps ParameterSet) Optional() ParameterSet
Optional returns a subset of the ParameterSet containing only optional parameters.
func (ParameterSet) RegisterAsFlags ¶ added in v0.6.0
func (ps ParameterSet) RegisterAsFlags(cmd *cobra.Command)
RegisterAsFlags registers every parameter in the set as a flag, marking required parameters as required flags on the command.
func (ParameterSet) RegisterFlags ¶ added in v0.5.0
func (ps ParameterSet) RegisterFlags(flags *pflag.FlagSet)
RegisterFlags registers the set's optional parameters as flags on the given flag set.
func (ParameterSet) Required ¶
func (ps ParameterSet) Required() ParameterSet
Required returns a subset of the ParameterSet containing only required parameters.
func (ParameterSet) ResolveFromFlags ¶ added in v0.6.0
func (ps ParameterSet) ResolveFromFlags(cmd *cobra.Command)
ResolveFromFlags assigns every parameter's value from its flag, applying defaults for optional parameters that were not set.
func (ParameterSet) ResolveValues ¶
func (ps ParameterSet) ResolveValues(cmd *cobra.Command, args []string) error
ResolveValues assigns values to the parameters from the positional arguments, flags, and defaults provided via the cobra command.
func (ParameterSet) Validate ¶
func (ps ParameterSet) Validate() error
Validate validates the parameter set, returning the first error it encounters, if any.