Skip to content

Commit

Permalink
Merge pull request #370 from mrunalp/info_decode_opt
Browse files Browse the repository at this point in the history
crictl: Fallback if info key is not JSON
  • Loading branch information
feiskyer authored Aug 28, 2018
2 parents b02d752 + ffd9b86 commit 049f828
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/crictl/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,13 @@ func outputStatusInfo(status string, info map[string]string, format string) erro

jsonInfo := "{" + "\"status\":" + status + ","
for _, k := range keys {
jsonInfo += "\"" + k + "\"" + ":" + info[k] + ","
var res interface{}
// We attempt to convert key into JSON if possible else use it directly
if err := json.Unmarshal([]byte(info[k]), res); err != nil {
jsonInfo += "\"" + k + "\"" + ":" + "\"" + info[k] + "\","
} else {
jsonInfo += "\"" + k + "\"" + ":" + info[k] + ","
}
}
jsonInfo = jsonInfo[:len(jsonInfo)-1]
jsonInfo += "}"
Expand Down

0 comments on commit 049f828

Please sign in to comment.