Allow CLI commands to add presentation functions to control how
field values are displayed in CLI tables.
Use this to display the logical device datapath_id in hex
as opposed to dec.
Change-Id: Iac45fb75f7bd4c468c53c4bc769cc24c1e8478ef
diff --git a/cli/main.py b/cli/main.py
index 218d384..441b292 100755
--- a/cli/main.py
+++ b/cli/main.py
@@ -206,8 +206,11 @@
'desc.serial_number',
'switch_features.capabilities'
}
+ presfns = {
+ 'datapath_id': lambda x: "{0:0{1}x}".format(int(x), 16)
+ }
print_pb_list_as_table('Logical devices:', res.items, omit_fields,
- self.poutput)
+ self.poutput, presfns=presfns)
def do_device(self, line):
"""Enter device level command mode"""
diff --git a/cli/table.py b/cli/table.py
index 867aa3b..f91b1f0 100644
--- a/cli/table.py
+++ b/cli/table.py
@@ -89,7 +89,8 @@
def print_pb_list_as_table(header, items, fields_to_omit=None,
- printfn=_printfn, dividers=10, show_nulls=False):
+ printfn=_printfn, dividers=10, show_nulls=False,
+ presfns={}):
from cli.utils import pb2dict
t = TablePrinter()
@@ -105,8 +106,9 @@
add(_row, value, fname + '.',
100 * (number + field.number))
else:
+ presentationfn = presfns[fname] if fname in presfns else lambda x: x
t.add_cell(_row, number + field.number, fname,
- pd_dict.get(field.name))
+ presentationfn(pd_dict.get(field.name)))
def add(_row, pb, prefix='', number=0):
d = pb2dict(pb)