Fixes ambiguous cli output between "None" and NoneType
Print hyphen(-) in python client output when attribute value is not set(NoneType) so that it is distinguishable between "None" string and NoneType value. Cherry-Pick: I5ec0f39f13aca45fa95ddb59472c20207c63bf91 Change-Id: I8a907e7453df711605d28bb97492f747adc282e0 Closes-Bug: #1266414
This commit is contained in:
@@ -152,6 +152,8 @@ def print_list(objs, fields, formatters={}, sortby_index=None):
|
||||
else:
|
||||
field_name = field.lower().replace(' ', '_')
|
||||
data = getattr(o, field_name, '')
|
||||
if data is None:
|
||||
data = '-'
|
||||
row.append(data)
|
||||
pt.add_row(row)
|
||||
|
||||
@@ -222,6 +224,8 @@ def print_dict(d, dict_property="Property", dict_value="Value", wrap=0):
|
||||
pt.add_row([col1, line])
|
||||
col1 = ''
|
||||
else:
|
||||
if v is None:
|
||||
v = '-'
|
||||
pt.add_row([k, v])
|
||||
print(strutils.safe_encode(pt.get_string()))
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@ class ShellTest(utils.TestCase):
|
||||
'+------+------------+----------+------+-------------+\n'
|
||||
'| name | id | username | tags | description |\n'
|
||||
'+------+------------+----------+------+-------------+\n'
|
||||
'| fake | aaa-bb-ccc | you | | None |\n'
|
||||
'| fake | aaa-bb-ccc | you | | - |\n'
|
||||
'+------+------------+----------+------+-------------+\n'
|
||||
)
|
||||
self.make_env()
|
||||
|
||||
Reference in New Issue
Block a user