Documentation
¶
Overview ¶
Package coerce converts raw CLI values to Go types using built-in and registered parsers.
Index ¶
- Variables
- func Map(raws []string, sep string) (map[string]string, error)
- func Scalar(raw string, targetType reflect.Type) (any, error)
- func ScalarWith(raw string, targetType reflect.Type, reg Registry, decodeContext DecodeContext) (any, error)
- func SliceWith(raws []string, sliceType reflect.Type, sep string, reg Registry, ...) (any, error)
- func SplitMapItems(raws []string, sep string) []string
- func Value[T any](raw string) (T, error)
- type DecodeContext
- type MapEntry
- type Registry
- type TypeParser
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func ScalarWith ¶
func ScalarWith(raw string, targetType reflect.Type, reg Registry, decodeContext DecodeContext) (any, error)
ScalarWith converts a raw string value into the target type represented by targetType, first checking if a custom parser is registered for targetType in reg. decodeContext carries the owning field's declared custom tags and the engine-configured standard streams for context-aware text unmarshaling.
func SliceWith ¶
func SliceWith(raws []string, sliceType reflect.Type, sep string, reg Registry, decodeContext DecodeContext) (any, error)
SliceWith converts a slice of raw string tokens into a slice of targetType using the supplied custom registry. decodeContext carries the owning field's declared custom tags and the engine-configured standard streams for context-aware text unmarshaling of each element.
func SplitMapItems ¶
SplitMapItems splits raw string tokens into trimmed KEY=VALUE items using sep.
Types ¶
type DecodeContext ¶
type DecodeContext struct {
// Tags holds the owning field's declared custom tags (see
// conga.TagSpecProvider); nil for fields that declare no registered tags.
Tags spec.FieldTags
// Stdin is the engine-configured standard input (App.Stdin); nil selects
// os.Stdin for types implementing "-" conventions.
Stdin io.Reader
// Stdout is the engine-configured standard output (App.Stdout); nil
// selects os.Stdout.
Stdout io.Writer
}
DecodeContext carries the ambient input for coercing one raw value into its target type: the owning field's declared custom tags and the engine-configured standard streams. The zero value selects no tags and process defaults (os.Stdin/os.Stdout), so values decoded outside an App run behave identically to direct UnmarshalText calls. It is a plain value struct: unlike context.Context it carries no cancellation or deadlines.
type Registry ¶
type Registry map[reflect.Type]TypeParser
Registry maps reflect.Type to custom TypeParser functions.
type TypeParser ¶
TypeParser parses a raw string token into a concrete value of the registered target type.