Skip to content

Commit a3180cb

Browse files
committed
ls: make sure current builder is available in JSON output
While lsBuilder has a field called Current that gets lost because the embedded struct implements custom MarshalJSON method. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent c398e2a commit a3180cb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

commands/ls.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,17 @@ type lsContext struct {
213213
}
214214

215215
func (c *lsContext) MarshalJSON() ([]byte, error) {
216-
return json.Marshal(c.Builder)
216+
// can't marshal c.Builder directly because Builder type has custom MarshalJSON
217+
dt, err := json.Marshal(c.Builder.Builder)
218+
if err != nil {
219+
return nil, err
220+
}
221+
var m map[string]any
222+
if err := json.Unmarshal(dt, &m); err != nil {
223+
return nil, err
224+
}
225+
m["Current"] = c.Builder.Current
226+
return json.Marshal(m)
217227
}
218228

219229
func (c *lsContext) Name() string {

0 commit comments

Comments
 (0)