args

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: Apache-2.0, MIT Imports: 12 Imported by: 0

Documentation

Overview

Package args provides the type that represents the Arguments passed to a command within an invocation.Token as well as a convenient Add method to incrementally build the underlying map.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("key not found in meta")

Functions

This section is empty.

Types

type Args

type Args struct {
	Keys   []string
	Values map[string]ipld.Node
}

Args are the Command's arguments when an invocation Token is processed by the executor. This also serves as a way to construct the underlying IPLD data with minimum allocations and transformations, while hiding the IPLD complexity from the caller.

func New

func New() *Args

New returns a pointer to an initialized Args value.

func (*Args) Add

func (a *Args) Add(key string, val any) error

Add inserts a key/value pair in the Args set.

Accepted types for val are any CBOR compatible type, or directly IPLD values.

func (*Args) Clone

func (a *Args) Clone() *Args

Clone makes a deep copy.

func (*Args) Equals

func (a *Args) Equals(other *Args) bool

Equals tells if two Args hold the same values.

func (*Args) GetNode

func (a *Args) GetNode(key string) (ipld.Node, error)

GetNode retrieves a value as a raw IPLD node. Returns ErrNotFound if the given key is missing.

func (*Args) Include

func (a *Args) Include(other Iterator)

Include merges the provided arguments into the existing arguments.

If duplicate keys are encountered, the new value is silently dropped without causing an error.

func (*Args) Iter

func (a *Args) Iter() iter.Seq2[string, ipld.Node]

Iter iterates over the args key/values

func (*Args) Len

func (a *Args) Len() int

Len return the number of arguments.

func (*Args) ReadOnly

func (a *Args) ReadOnly() ReadOnly

ReadOnly returns a read-only version of Args.

func (*Args) String

func (a *Args) String() string

func (*Args) ToIPLD

func (a *Args) ToIPLD() (ipld.Node, error)

ToIPLD wraps an instance of an Args with an ipld.Node.

func (*Args) Validate

func (a *Args) Validate() error

Validate checks that all values in the Args are valid according to UCAN specs

type Builder

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

Builder allows the fluid construction of an Args.

func NewBuilder

func NewBuilder() *Builder

NewBuilder returns a Builder which will assemble the Args.

func (*Builder) Add

func (b *Builder) Add(key string, val any) *Builder

Add inserts a new key/val into the Args being assembled while collecting any errors caused by duplicate keys.

func (*Builder) Build

func (b *Builder) Build() (*Args, error)

Build returns the assembled Args or an error containing a list of errors encountered while trying to build the Args.

func (*Builder) BuildIPLD

func (b *Builder) BuildIPLD() (ipld.Node, error)

BuildIPLD is the same as Build except it takes the additional step of converting the Args to an ipld.Node.

func (*Builder) MustBuild

func (b *Builder) MustBuild() *Args

MustBuild is the same as Build except it panics if an error occurs.

func (*Builder) MustBuildIPLD

func (b *Builder) MustBuildIPLD() ipld.Node

MustBuildIPLD is the same as BuildIPLD except it panics if an error occurs.

type Iterator

type Iterator interface {
	Iter() iter.Seq2[string, ipld.Node]
}

type ReadOnly

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

func (ReadOnly) Equals

func (r ReadOnly) Equals(other ReadOnly) bool

func (ReadOnly) GetNode

func (r ReadOnly) GetNode(key string) (ipld.Node, error)

func (ReadOnly) Iter

func (r ReadOnly) Iter() iter.Seq2[string, ipld.Node]

func (ReadOnly) Len

func (r ReadOnly) Len() int

func (ReadOnly) String

func (r ReadOnly) String() string

func (ReadOnly) ToIPLD

func (r ReadOnly) ToIPLD() (ipld.Node, error)

func (ReadOnly) WriteableClone

func (r ReadOnly) WriteableClone() *Args

Jump to

Keyboard shortcuts

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