Documentation ¶
Index ¶
- Variables
- func GetArgType(argType reflect.Type, name string) (reflect.Type, error)
- func IsUmarshalableValue(data interface{}) bool
- func ListArgTypeFields(argType reflect.Type) []string
- func MarshalStruct(data interface{}) (args []string, err error)
- func MarshalValue(data interface{}) (string, error)
- func RegisterMarshalFunc(i interface{}, marshalFunc MarshalFunc)
- func RegisterUnmarshalFunc(i interface{}, unmarshalFunc UnmarshalFunc)
- func SplitRaw(rawArgs []string) [][2]string
- func SplitRawMap(rawArgs []string) map[string]struct{}
- func UnmarshalStruct(args []string, data interface{}) error
- type CannotParseBoolError
- type CannotParseDateError
- type CannotSetNestedFieldError
- type CannotUnmarshalError
- type ConflictArgError
- type DataMustBeAMarshalableValueError
- type DataMustBeAPointerError
- type DuplicateArgError
- type InvalidArgNameError
- type InvalidIndexError
- type MarshalFunc
- type Marshaler
- type MissingIndexOnArrayError
- type MissingIndicesInArrayError
- type MissingMapKeyError
- type MissingStructFieldError
- type NotMarshalableTypeError
- type RawArgs
- func (a RawArgs) Add(name string, value string) RawArgs
- func (a RawArgs) ExistsArgByName(name string) bool
- func (a RawArgs) Get(argName string) (string, bool)
- func (a RawArgs) GetAll(argName string) []string
- func (a RawArgs) GetPositionalArgs() []string
- func (a RawArgs) GetSliceOrMapKeys(prefix string) []string
- func (a RawArgs) Has(argName string) bool
- func (a RawArgs) Remove(argName string) RawArgs
- func (a RawArgs) RemoveAllPositional() RawArgs
- type UnknownArgError
- type UnmarshalArgError
- type UnmarshalFunc
- type UnmarshalableTypeError
- type Unmarshaler
- type ValueIsNotMarshalableError
Constants ¶
This section is empty.
Variables ¶
var TestForceNow *time.Time
Functions ¶
func GetArgType ¶
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 ListArgTypeFields ¶ added in v2.13.0
ListArgTypeFields take a go struct and return a list of name that comply with ArgSpec name notation (e.g "friends.{index}.name")
func MarshalStruct ¶
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 ¶
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 ¶
SplitRaw creates a slice that maps arg names to their values. ["arg1=1", "arg2=2", "arg3"] => { {"arg1", "1"}, {"arg2", "2"}, {"arg3",""} }
func SplitRawMap ¶
SplitRaw creates a map that maps arg names to their values. ["arg1=1", "arg2=2", "arg3"] => {"arg1": "1", "arg2": "2", "arg3":"" }
func UnmarshalStruct ¶
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 ¶
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 ¶
func (e *DataMustBeAMarshalableValueError) Error() string
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 MissingIndexOnArrayError ¶
type MissingIndexOnArrayError struct{}
func (*MissingIndexOnArrayError) Error ¶
func (e *MissingIndexOnArrayError) Error() string
type MissingIndicesInArrayError ¶
func (*MissingIndicesInArrayError) Error ¶
func (e *MissingIndicesInArrayError) Error() string
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) ExistsArgByName ¶
ExistsArgByName checks if the given argument exists in the raw args
func (RawArgs) GetPositionalArgs ¶
func (RawArgs) GetSliceOrMapKeys ¶
func (RawArgs) RemoveAllPositional ¶
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 UnmarshalableTypeError ¶
type UnmarshalableTypeError struct {
Dest interface{}
}
func (*UnmarshalableTypeError) Error ¶
func (e *UnmarshalableTypeError) Error() string
type Unmarshaler ¶
type ValueIsNotMarshalableError ¶
type ValueIsNotMarshalableError struct {
Interface interface{}
}
func (*ValueIsNotMarshalableError) Error ¶
func (e *ValueIsNotMarshalableError) Error() string