provider

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
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

func NewInvalidParameterSpecError(reason string) error

NewInvalidParameterSpecError creates a new error indicating that a parameter spec is invalid.

Types

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

func NewParameter(content []byte) (*Parameter, error)

NewParameter creates a new Parameter from the provided spec.

func (*Parameter) CLIFlagName

func (param *Parameter) CLIFlagName() string

CLIFlagName returns the parameter name formatted as a CLI flag name.

func (*Parameter) SetDefaultValue

func (param *Parameter) SetDefaultValue()

SetDefaultValue assigns the default value to the parameter.

func (*Parameter) SetValue

func (param *Parameter) SetValue(value any)

SetValue assigns a value to the parameter.

func (*Parameter) Validate

func (param *Parameter) Validate() error

Validate validates a Parameter.

func (*Parameter) Value

func (param *Parameter) Value() any

Value returns the parameter's assigned value.

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) 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) 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) 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.

type Provider

type Provider interface {
	// Configure wires the provider's positional arguments, flags, and run
	// behavior onto the given cobra command.
	Configure(cmd *cobra.Command)
	Type() string
	Validate() error
}

A Provider defines what happens when a command is invoked on the command line.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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