qmp-shell: Sort by key when pretty-printing

If the user selects pretty-printing (-p) the contents of any
dictionaries in the output are sorted by key.

Signed-off-by: David Edmondson <david.edmondson@oracle.com>
Message-Id: <20201013141414.18398-1-david.edmondson@oracle.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
David Edmondson 2020-10-13 15:14:14 +01:00 committed by Markus Armbruster
parent 1dc887329a
commit fca9d72323

View File

@ -260,7 +260,7 @@ class QMPShell(qmp.QEMUMonitorProtocol):
indent = None
if self._pretty:
indent = 4
jsobj = json.dumps(qmp, indent=indent)
jsobj = json.dumps(qmp, indent=indent, sort_keys=self._pretty)
print(str(jsobj))
def _execute_cmd(self, cmdline):