uritemplates

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: BSD-3-Clause Imports: 15 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextValue added in v0.7.3

func ContextValue(e *Expander) cli.Action

ContextValue returns an action that adds the expander to the context

func ExpandAndPrint added in v0.7.3

func ExpandAndPrint() cli.Action

ExpandAndPrint returns an action that expands the URI template and prints the output

func FlagsAndArgs

func FlagsAndArgs() cli.Action

FlagsAndArgs returns an action that sets up flags and arguments for URI template expansion

func SetPartialExpand

func SetPartialExpand(b ...bool) cli.Action

SetPartialExpand returns an action that sets up a flag for enabling partial expansion

func SetTemplate added in v0.7.3

func SetTemplate(v ...*URITemplate) cli.Action

SetTemplate sets the template used

func SetURITemplateVar

func SetURITemplateVar(v ...*Var) cli.Action

SetURITemplateVar returns an action that sets up a flag for specifying template variables

func SetURITemplateVars

func SetURITemplateVars(v ...*Vars) cli.Action

SetURITemplateVars returns an action that sets up a flag for specifying template variables from JSON

func SourceAnnotation

func SourceAnnotation() (string, string)

SourceAnnotation gets the name and value of the annotation added to the Data of all flags that are initialized from this package

Types

type Expander added in v0.7.3

type Expander struct {
	cli.Action
	// contains filtered or unexported fields
}

Expander provides URI template expansion functionality that can be initialized and configured within a CLI app. The expander is used within the Uses pipeline where it registers itself as a context service.

func FromContext added in v0.7.3

func FromContext(ctx context.Context) *Expander

FromContext obtains the expander from the context.

func New added in v0.7.3

func New(options ...Option) *Expander

New creates a new URI template expander with the given options.

func (*Expander) AddURITemplateVar added in v0.7.3

func (e *Expander) AddURITemplateVar(v *Var) error

AddURITemplateVar adds a template variable to the expander

func (*Expander) Apply added in v0.7.3

func (e *Expander) Apply(opts ...Option)

Apply applies the given options to the expander

func (*Expander) Expand added in v0.7.3

func (e *Expander) Expand() (string, error)

Expand performs the expansion

func (*Expander) Partial added in v0.7.3

func (e *Expander) Partial() bool

Partial returns whether partial expansion is enabled

func (*Expander) Pipeline added in v0.7.3

func (e *Expander) Pipeline() cli.Action

func (*Expander) SetPartialExpand added in v0.7.3

func (e *Expander) SetPartialExpand(b bool) error

SetPartialExpand sets whether to partially expand the template

func (*Expander) SetTemplate added in v0.7.3

func (e *Expander) SetTemplate(v *URITemplate) error

SetTemplate sets the template to expand

func (*Expander) Template added in v0.7.3

func (e *Expander) Template() *URITemplate

Template returns the template to expand

func (*Expander) UpdateURITemplateVars added in v0.7.3

func (e *Expander) UpdateURITemplateVars(v *Vars) error

UpdateURITemplateVars updates the template variables in the expander

func (*Expander) Vars added in v0.7.3

func (e *Expander) Vars() Vars

Vars returns the template variables

type Option added in v0.7.3

type Option interface {
	cli.Action
	// contains filtered or unexported methods
}

Option is an option to configure the expander Option can be used as an Action, typically within the Uses or Before pipeline.

func WithAction added in v0.7.3

func WithAction(a cli.Action) Option

WithAction sets up the action to use when Expander is added to a pipeline

func WithDefaultAction added in v0.7.3

func WithDefaultAction() Option

WithDefaultAction sets up the default action to use when Expander.

func WithPartialExpand added in v0.7.3

func WithPartialExpand(b bool) Option

WithPartialExpand sets whether to partially expand the template

func WithURITemplateVar added in v0.7.3

func WithURITemplateVar(v *Var) Option

WithURITemplateVar adds a template variable

func WithURITemplateVars added in v0.7.3

func WithURITemplateVars(v *Vars) Option

WithURITemplateVars adds multiple template variables

type URITemplate

type URITemplate struct {
	// contains filtered or unexported fields
}

URITemplate is a parsed representation of a URI template, which can also be used as a flag Value

func Parse

func Parse(text string) (*URITemplate, error)

Parse obtains a URI template from a string

func (*URITemplate) Expand

func (u *URITemplate) Expand(value any) (string, error)

Expand expands a URI template. The value is Vars, a map[string]any, or an arbitrary struct (or pointer to one). When a struct, reflection is used to obtain the values by name, and the tag `uri` can be used to override the name.

func (*URITemplate) MarshalText

func (u *URITemplate) MarshalText() ([]byte, error)

MarshalText provides the textual representation

func (*URITemplate) Names

func (u *URITemplate) Names() []string

Names retrieves the names of the template variables

func (*URITemplate) PartialExpand

func (u *URITemplate) PartialExpand(value any) (*URITemplate, error)

PartialExpand expands a URI template, leaving any expansions which could not be filled

func (*URITemplate) Set

func (u *URITemplate) Set(arg string) error

Set provides the behavior when the template is used as a flag on the command line

func (*URITemplate) String

func (u *URITemplate) String() string

String converts the template to a string

func (*URITemplate) UnmarshalText

func (u *URITemplate) UnmarshalText(b []byte) error

UnmarshalText converts the textual representation

type Var

type Var struct {
	Name  string
	Value any
	// contains filtered or unexported fields
}

Var is a variable in a URI template

func ArrayVar

func ArrayVar(name string, values ...any) *Var

func MapVar

func MapVar(name string, values map[string]any) *Var

func NewVar added in v0.6.0

func NewVar(name string, value any) *Var

func StringVar

func StringVar(name string, value string) *Var

func (*Var) Copy

func (v *Var) Copy() *Var

func (*Var) NewCounter

func (v *Var) NewCounter() cli.ArgCounter

func (*Var) Reset

func (v *Var) Reset()

func (*Var) Set

func (v *Var) Set(arg string) error

func (*Var) String

func (v *Var) String() string

func (*Var) Synopsis

func (*Var) Synopsis() string

func (*Var) Type

func (v *Var) Type() VarType

type VarType

type VarType int

VarType enumerates the types of variables in the expression of a URI template

const (
	String VarType = iota
	Array
	Map
)

Types of variables

func (VarType) String

func (t VarType) String() string

type Vars

type Vars map[string]any

Vars provides template variables

func (Vars) Add

func (t Vars) Add(v ...*Var)

func (*Vars) Copy

func (t *Vars) Copy() *Vars

func (Vars) Items

func (t Vars) Items() []*Var

func (*Vars) Reset

func (t *Vars) Reset()

func (*Vars) Set

func (t *Vars) Set(arg string) error

func (Vars) String

func (t Vars) String() string

func (Vars) Update

func (t Vars) Update(u map[string]any) (err error)

Jump to

Keyboard shortcuts

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