MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / FormatFieldValue

Function FormatFieldValue

internal/cli/format.go:424–438  ·  view source on GitHub ↗

FormatFieldValue renders one field value for a human: a string as itself, a structured value (a json field's object or array) as compact JSON, anything else as Go prints it. Go's own `%v` printed a json field as `[map[name:target …]]`, which is neither JSON nor readable (BUG-3448). Decode the field

(v any)

Source from the content-addressed store, hash-verified

422// above 2^53. A JSON null prints as null, which an empty value
423// would not say.
424func FormatFieldValue(v any) string {
425 switch t := v.(type) {
426 case nil:
427 return "null"
428 case string:
429 return t
430 case json.Number:
431 return t.String()
432 case map[string]any, []any:
433 if b, err := json.Marshal(t); err == nil {
434 return string(b)
435 }
436 }
437 return fmt.Sprintf("%v", v)
438}
439
440// summariseFieldValue is FormatFieldValue for a one-line summary: a
441// structured value is reported by its size, so one json field cannot turn

Callers 3

formatItemAsMarkdownFunction · 0.92
showCmdFunction · 0.92
summariseFieldValueFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected