diff options
author | Harald Welte <laforge@osmocom.org> | 2021-04-06 21:12:25 +0200 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2021-04-06 21:16:16 +0200 |
commit | 1748b9372cb5f12c5a0afd4e37e5f96dbe8a4cf1 (patch) | |
tree | d4bdbc2057362488c31937c40088b631017d9529 /pySim-shell.py | |
parent | c9baa4d91576c7cc6943b22ad3bede63536403df (diff) |
pySim-shell: Add settable parameter on JSON pretty-printing
Change-Id: Ic095c96733de2b0f359bfe067cd719d38712faff
Diffstat (limited to 'pySim-shell.py')
-rwxr-xr-x | pySim-shell.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/pySim-shell.py b/pySim-shell.py index e73ec35..7f48d58 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -72,6 +72,16 @@ class PysimApp(cmd2.Cmd): self.add_settable(cmd2.Settable('conserve_write', bool, 'Read and compare before write', onchange_cb=self._onchange_conserve_write)) self.update_prompt() + self.json_pretty_print = True + self.add_settable(cmd2.Settable('json_pretty_print', bool, 'Pretty-Print JSON output')) + + def poutput_json(self, data, force_no_pretty = False): + """line cmd2.putput() but for a json serializable dict.""" + if force_no_pretty or self.json_pretty_print == False: + output = json.dumps(data) + else: + output = json.dumps(data, indent=4) + self.poutput(output) def _onchange_numeric_path(self, param_name, old, new): self.update_prompt() |