summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorPavel Zuna <pzuna@redhat.com>2009-08-25 14:05:40 +0200
committerRob Crittenden <rcritten@redhat.com>2009-09-08 13:41:54 -0400
commit34970fef5e6ab882ac10b6fbf8f3a531f0c8787c (patch)
tree7f5cddb93b7ec9c644eebc144c8214169f2c0551 /ipalib
parentf294bee09dbbe109bc8291eb1bd9d6156ff2aa33 (diff)
downloadfreeipa.git-34970fef5e6ab882ac10b6fbf8f3a531f0c8787c.tar.gz
freeipa.git-34970fef5e6ab882ac10b6fbf8f3a531f0c8787c.tar.xz
freeipa.git-34970fef5e6ab882ac10b6fbf8f3a531f0c8787c.zip
Improve attribute printing in the CLI.
- allow choice between single/multiple value per line - word wrapping
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/cli.py33
1 files changed, 28 insertions, 5 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 5f782235..ef669b4a 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -234,7 +234,7 @@ class textui(backend.Backend):
for (key, value) in rows:
self.print_indented('%s = %r' % (key, value), indent)
- def print_attribute(self, attr, value, indent=1):
+ def print_attribute(self, attr, value, indent=1, one_value_per_line=True):
"""
Print an ldap attribute.
@@ -254,9 +254,28 @@ class textui(backend.Backend):
self.print_indented('%s: %s' % (attr, value), indent)
else:
# multi-value attribute
- self.print_indented('%s: %s' % (attr, ', '.join(value)), indent)
+ if one_value_per_line:
+ for v in value:
+ self.print_indented('%s: %s' % (attr, v), indent)
+ else:
+ text = ', '.join(value)
+ line_len = self.get_tty_width()
+ if line_len:
+ s_indent = '%s%s' % (
+ CLI_TAB * indent, ' ' * (len(attr) + 2)
+ )
+ line_len -= len(s_indent)
+ text = textwrap.wrap(
+ text, line_len, break_long_words=False
+ )
+ else:
+ text = [text]
+ self.print_indented('%s: %s' % (attr, text[0]), indent)
+ for line in text[1:]:
+ self.print_plain('%s%s' % (s_indent, line))
- def print_entry(self, entry, indent=1, attr_map={}, attr_order=['dn']):
+ def print_entry(self, entry, indent=1, attr_map={}, attr_order=['dn'],
+ one_value_per_line=True):
"""
Print an ldap entry dict.
@@ -275,9 +294,13 @@ class textui(backend.Backend):
def print_attr(a):
if attr in attr_map:
- self.print_attribute(attr_map[attr], entry[attr], indent)
+ self.print_attribute(
+ attr_map[attr], entry[attr], indent, one_value_per_line
+ )
else:
- self.print_attribute(attr, entry[attr], indent)
+ self.print_attribute(
+ attr, entry[attr], indent, one_value_per_line
+ )
for attr in attr_order:
if attr in entry: