Skip to main content

Module coerce

Module coerce 

Source
Expand description

CLI-facing value construction for set/add: a bare VALUE/FIELD=VALUE is always Value::String with zero coercion — no shape-guessing, no type prefixes. An exact type is requested explicitly via ValueType (set’s --value-type flag); guard_bare_overwrite is the heterogeneous-overwrite guard that turns a bare VALUE silently rewriting what is already at the path — a scalar of another type, or a whole container — into an argument error instead.

Enums§

BareOverwrite
What a bare VALUE would overwrite, and the --value-type that would keep it — see guard_bare_overwrite.
ScalarKind
The four AFDATA scalar “kinds” the heterogeneous-overwrite guard distinguishes. Number covers Integer/Unsigned/Float/ Value::Number — the guard cares whether VALUE would change a scalar from one of these kinds to a bare string, not which numeric representation was in play.
ValueType
The exact type an explicit --value-type requests for a set VALUE.

Functions§

coerce_toward
Coerce a CLI string toward the type already present at existing, for a consumer that knows the target type from the value it is replacing (a config setter reading typed leaves out of a serialized document).
coerce_values_toward
Coerce a CLI value slice toward the type at existing via coerce_toward: one value becomes a scalar, several become an array whose elements are each coerced toward the existing array’s element type. An empty slice is an error.
guard_bare_overwrite
The heterogeneous-overwrite guard, which closes the “no silent type rewrites” rule: a bare VALUE (implicit --value-type string) is always a string, so writing one over anything that is not already a string rewrites what is there. That is an argument error, not a coercion decision. Returns what would be overwritten so the caller can name both escape hatches (--value-type <kind> to keep it, --value-type string to convert deliberately).
scalar_kind
The scalar kind of value, or None for an array/object.
value_from_type
Construct a Value from a CLI string per an explicit ValueType.
value_matches_type
Whether value satisfies expected for a typed read — the GET-side counterpart to value_from_type. Json matches any value; Number matches every numeric representation; the rest match their one kind. A consumer that asks for a type gets a value back only when it actually is that type, so a wrong-typed leaf is a caught error rather than a surprise.