Skip to content

Commit 4feb05b

Browse files
authored
Merge pull request #3179 from tonistiigi/ls-format-json-current
ls: make sure current builder is available in JSON output
2 parents 277548e + a3180cb commit 4feb05b

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)