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

Method MarshalJSON

internal/cmdhelp/types.go:107–122  ·  view source on GitHub ↗

MarshalJSON serializes the union per spec §5.2.

()

Source from the content-addressed store, hash-verified

105
106// MarshalJSON serializes the union per spec §5.2.
107func (e ExitCode) MarshalJSON() ([]byte, error) {
108 hasRich := e.When != "" || e.Recovery != "" || e.MessageTemplate != ""
109 if e.Description != "" && !hasRich {
110 return json.Marshal(e.Description)
111 }
112 type rich struct {
113 When string `json:"when,omitempty"`
114 Recovery string `json:"recovery,omitempty"`
115 MessageTemplate string `json:"message_template,omitempty"`
116 }
117 return json.Marshal(rich{
118 When: e.When,
119 Recovery: e.Recovery,
120 MessageTemplate: e.MessageTemplate,
121 })
122}
123
124// Example is a canonical invocation. Same source feeds both --format json
125// and --format md (spec §6); MD rendering wraps cmd in a fenced bash block

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected