Merge "Improve output of --json option"
This commit is contained in:
commit
585575eb8d
ironicclient
releasenotes/notes
@ -154,7 +154,8 @@ def print_list(objs, fields, formatters=None, sortby_index=0,
|
||||
:param json_flag: print the list as JSON instead of table
|
||||
"""
|
||||
if json_flag:
|
||||
print(json.dumps([o._info for o in objs]))
|
||||
print(json.dumps([o._info for o in objs], indent=4,
|
||||
separators=(',', ': ')))
|
||||
return
|
||||
formatters = formatters or {}
|
||||
mixed_case_fields = mixed_case_fields or []
|
||||
@ -205,7 +206,7 @@ def print_dict(dct, dict_property="Property", wrap=0, dict_value='Value',
|
||||
:param json_flag: print `dict` as JSON instead of table
|
||||
"""
|
||||
if json_flag:
|
||||
print(json.dumps(dct))
|
||||
print(json.dumps(dct, indent=4, separators=(',', ': ')))
|
||||
return
|
||||
pt = prettytable.PrettyTable([dict_property, dict_value])
|
||||
pt.align = 'l'
|
||||
|
@ -12,6 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import sys
|
||||
|
||||
import fixtures
|
||||
@ -597,12 +598,7 @@ class PrintResultStringTestCase(test_base.BaseTestCase):
|
||||
out = sys.stdout.getvalue()
|
||||
sys.stdout.close()
|
||||
sys.stdout = orig
|
||||
expected = ['''\
|
||||
[{"name": "k1", "value": 1}]
|
||||
''', '''\
|
||||
[{"value": 1, "name": "k1"}]
|
||||
''']
|
||||
self.assertIn(out, expected)
|
||||
self.assertEqual([objs[0]._info], json.loads(out))
|
||||
|
||||
def test_print_dict_string(self):
|
||||
orig = sys.stdout
|
||||
@ -628,12 +624,8 @@ class PrintResultStringTestCase(test_base.BaseTestCase):
|
||||
out = sys.stdout.getvalue()
|
||||
sys.stdout.close()
|
||||
sys.stdout = orig
|
||||
expected = ['''\
|
||||
{"K": "k", "Key": "Value"}
|
||||
''', '''\
|
||||
{"Key": "Value", "K": "k"}
|
||||
''']
|
||||
self.assertIn(out, expected)
|
||||
expected = {"K": "k", "Key": "Value"}
|
||||
self.assertEqual(expected, json.loads(out))
|
||||
|
||||
def test_print_dict_string_custom_headers(self):
|
||||
orig = sys.stdout
|
||||
|
4
releasenotes/notes/add-json-option-0cf29be2a97e0212.yaml
Normal file
4
releasenotes/notes/add-json-option-0cf29be2a97e0212.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- Add a --json option to the client to display the JSON
|
||||
response body from the Ironic API without formatting it.
|
Loading…
x
Reference in New Issue
Block a user