args

package
v2.60.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestForceNow *time.Time

Functions

func GetArgType

func GetArgType(argType reflect.Type, name string) (reflect.Type, error)

This function take a go struct and a name that comply with ArgSpec name notation (e.g "friends.{index}.name")

func IsUmarshalableValue

func IsUmarshalableValue(data any) bool

IsUmarshalableValue returns true if data type could be unmarshalled with args.UnmarshalValue

func ListArgTypeFields added in v2.13.0

func ListArgTypeFields(argType reflect.Type) []string

ListArgTypeFields take a go struct and return a list of name that comply with ArgSpec name notation (e.g "friends.{index}.name")

func MarshalStruct

func MarshalStruct(data any) (args []string, err error)

MarshalStruct marshals a go struct using reflection to args like ["arg1=1", "arg2=2"]. This function only marshal struct. If you wish to unmarshal a single value ( the part on the right of the `=` in arg notation ) you should use MarshalValue instead.

func MarshalValue

func MarshalValue(data any) (string, error)

MarshalValue marshals a single value. While MarshalStruct will convert a go struct to an argument list like ["arg1=1", "arg2=2"], MarshalValue will only marshal a single argument an return the arg value ( right part of the `=` )

func RegisterMarshalFunc

func RegisterMarshalFunc(i any, marshalFunc MarshalFunc)

RegisterMarshalFunc registers a MarshalFunc for a given interface. i must be a pointer.

func RegisterUnmarshalFunc

func RegisterUnmarshalFunc(i any, unmarshalFunc UnmarshalFunc)

RegisterUnmarshalFunc registers an UnmarshalFunc for a given interface. i must be a pointer.

func SplitRaw

func SplitRaw(rawArgs []string) [][2]string

SplitRaw creates a slice that maps arg names to their values. ["arg1=1", "arg2=2", "arg3"] => { {"arg1", "1"}, {"arg2", "2"}, {"arg3",""} }

func SplitRawMap

func SplitRawMap(rawArgs []string) map[string]struct{}

SplitRaw creates a map that maps arg names to their values. ["arg1=1", "arg2=2", "arg3"] => {"arg1": "1", "arg2": "2", "arg3":"" }

func UnmarshalStruct

func UnmarshalStruct(args []string, data any) error

UnmarshalStruct parses args like ["arg1=1", "arg2=2"] to a Go structure using reflection.

args: slice of args passed through the command line data: Go structure to fill

Types

type CannotParseBoolError

type CannotParseBoolError struct {
	Value string
}

func (*CannotParseBoolError) Error

func (e *CannotParseBoolError) Error() string

type CannotParseDateError

type CannotParseDateError struct {
	ArgValue               string
	AbsoluteTimeParseError error
	RelativeTimeParseError error
}

func (*CannotParseDateError) Error

func (e *CannotParseDateError) Error() string

type CannotSetNestedFieldError

type CannotSetNestedFieldError struct {
	Dest any
}

func (*CannotSetNestedFieldError) Error

func (e *CannotSetNestedFieldError) Error() string

type CannotUnmarshalError

type CannotUnmarshalError struct {
	Dest any
	Err  error
}

func (*CannotUnmarshalError) Error

func (e *CannotUnmarshalError) Error() string

type ConflictArgError

type ConflictArgError struct {
	ArgName1 string
	ArgName2 string
}

ConflictArgError is return when two args that are in conflict with each other are used together. e.g cluster=prod cluster.name=test are conflicting args

func (*ConflictArgError) Error

func (e *ConflictArgError) Error() string

type DataMustBeAMarshalableValueError

type DataMustBeAMarshalableValueError struct{}

func (*DataMustBeAMarshalableValueError) Error

type DataMustBeAPointerError

type DataMustBeAPointerError struct{}

func (*DataMustBeAPointerError) Error

func (e *DataMustBeAPointerError) Error() string

type DuplicateArgError

type DuplicateArgError struct{}

func (*DuplicateArgError) Error

func (e *DuplicateArgError) Error() string

type InvalidArgNameError

type InvalidArgNameError struct{}

func (*InvalidArgNameError) Error

func (e *InvalidArgNameError) Error() string

type InvalidIndexError

type InvalidIndexError struct {
	Index string
}

func (*InvalidIndexError) Error

func (e *InvalidIndexError) Error() string

type MarshalFunc

type MarshalFunc func(src any) (string, error)

type Marshaler

type Marshaler interface {
	MarshalArgs() (string, error)
}

type MissingIndexOnArrayError

type MissingIndexOnArrayError struct{}

func (*MissingIndexOnArrayError) Error

func (e *MissingIndexOnArrayError) Error() string

type MissingIndicesInArrayError

type MissingIndicesInArrayError struct {
	IndexToInsert int
	CurrentLength int
}

func (*MissingIndicesInArrayError) Error

type MissingMapKeyError

type MissingMapKeyError struct{}

func (*MissingMapKeyError) Error

func (e *MissingMapKeyError) Error() string

type MissingStructFieldError

type MissingStructFieldError struct {
	Dest any
}

func (*MissingStructFieldError) Error

func (e *MissingStructFieldError) Error() string

type NotMarshalableTypeError

type NotMarshalableTypeError struct {
	Src any
}

func (*NotMarshalableTypeError) Error

func (e *NotMarshalableTypeError) Error() string

type RawArgs

type RawArgs []string

RawArgs allows to retrieve a simple []string using UnmarshalStruct()

func (*RawArgs) Add

func (a *RawArgs) Add(name string, value string) RawArgs

func (*RawArgs) ExistsArgByName

func (a *RawArgs) ExistsArgByName(name string) bool

ExistsArgByName checks if the given argument exists in the raw args

func (*RawArgs) Get

func (a *RawArgs) Get(argName string) (string, bool)

func (*RawArgs) GetAll

func (a *RawArgs) GetAll(argName string) []string

func (*RawArgs) GetPositionalArgs

func (a *RawArgs) GetPositionalArgs() []string

func (*RawArgs) GetSliceOrMapKeys

func (a *RawArgs) GetSliceOrMapKeys(prefix string) []string

func (*RawArgs) Has

func (a *RawArgs) Has(argName string) bool

func (*RawArgs) Remove

func (a *RawArgs) Remove(argName string) RawArgs

func (*RawArgs) RemoveAllPositional

func (a *RawArgs) RemoveAllPositional() RawArgs

type UnknownArgError

type UnknownArgError struct{}

func (*UnknownArgError) Error

func (e *UnknownArgError) Error() string

type UnmarshalArgError

type UnmarshalArgError struct {
	// ArgName is the name of the argument which causes the error.
	ArgName string

	// ArgValue is the value of the argument which causes the error.
	ArgValue string

	// Err is the wrapped error.
	Err error
}

func (*UnmarshalArgError) Error

func (e *UnmarshalArgError) Error() string

func (*UnmarshalArgError) Unwrap

func (e *UnmarshalArgError) Unwrap() error

type UnmarshalFunc

type UnmarshalFunc func(value string, dest any) error

type UnmarshalableTypeError

type UnmarshalableTypeError struct {
	Dest any
}

func (*UnmarshalableTypeError) Error

func (e *UnmarshalableTypeError) Error() string

type Unmarshaler

type Unmarshaler interface {
	UnmarshalArgs(value string) error
}

type ValueIsNotMarshalableError

type ValueIsNotMarshalableError struct {
	Interface any
}

func (*ValueIsNotMarshalableError) Error

Jump to

Keyboard shortcuts

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