From 3fdc256143d03d2c5b95aab673028b893abeb508 Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Tue, 16 Jul 2013 14:49:54 -0500 Subject: Add dict2columns() Add ShowOne.dict2columns() to handle the common process of displaying a single dict as two columns of key and value. --- cliff/show.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cliff/show.py b/cliff/show.py index 39e94b1..855b2d2 100644 --- a/cliff/show.py +++ b/cliff/show.py @@ -44,3 +44,12 @@ class ShowOne(DisplayCommandBase): self.app.stdout, parsed_args) return 0 + + def dict2columns(self, data): + """Implement the common task of converting a dict-based object + to the two-column output that ShowOne expects. + """ + if not data: + return ({}, {}) + else: + return zip(*sorted(data.items())) -- cgit v1.2.1