args

package
v0.0.0-...-f46f4bb Latest Latest
Warning

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

Go to latest
Published: May 19, 2022 License: Apache-2.0 Imports: 13 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 interface{}) bool

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

func MarshalStruct

func MarshalStruct(data interface{}) (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 interface{}) (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 interface{}, marshalFunc MarshalFunc)

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

func RegisterUnmarshalFunc

func RegisterUnmarshalFunc(i interface{}, 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 interface{}) 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 interface{}
}

func (*CannotSetNestedFieldError) Error

func (e *CannotSetNestedFieldError) Error() string

type CannotUnmarshalError

type CannotUnmarshalError struct {
	Dest interface{}
	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 interface{}) (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 interface{}
}

func (*MissingStructFieldError) Error

func (e *MissingStructFieldError) Error() string

type NotMarshalableTypeError

type NotMarshalableTypeError struct {
	Src interface{}
}

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 interface{}) error

type UnmarshalableTypeError

type UnmarshalableTypeError struct {
	Dest interface{}
}

func (*UnmarshalableTypeError) Error

func (e *UnmarshalableTypeError) Error() string

type Unmarshaler

type Unmarshaler interface {
	UnmarshalArgs(value string) error
}

type ValueIsNotMarshalableError

type ValueIsNotMarshalableError struct {
	Interface interface{}
}

func (*ValueIsNotMarshalableError) Error

Jump to

Keyboard shortcuts

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