summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2011-12-21 14:44:58 +0100
committerMartin Kosek <mkosek@redhat.com>2012-01-12 10:45:37 +0100
commit688f630c6be44ae3fb977ec0f280ffde9179fba8 (patch)
tree15a11486327faf20700bbbc4376a7c91f7a44b46 /ipalib
parentbff9101a9fe8eecbe01d9aa33808363f6ed8b3fa (diff)
downloadfreeipa.git-688f630c6be44ae3fb977ec0f280ffde9179fba8.tar.gz
freeipa.git-688f630c6be44ae3fb977ec0f280ffde9179fba8.tar.xz
freeipa.git-688f630c6be44ae3fb977ec0f280ffde9179fba8.zip
Improve CLI output for complex commands
Complex commands may have many options or non-standard output. This patch adds 2 improvements to handle these commands better: 1) Add "option_group" parameter attribute Make command help more readable by specifying an option group for the parameter. All parameters in the same option group are then placed to one named option group 2) Allow nested entries in the output Current CLI output module cannot handle a list of nested entries (dictionaries) contained in an entry attribute. Make sure they are printed properly (with indentation) https://fedorahosted.org/freeipa/ticket/2082
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/cli.py27
-rw-r--r--ipalib/parameters.py1
2 files changed, 24 insertions, 4 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 7d79775e..667a7cdc 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -375,9 +375,16 @@ class textui(backend.Backend):
indent=indent+1
)
else:
- self.print_attribute(
- label, value, format, indent, one_value_per_line
- )
+ if isinstance(value, (list, tuple)) and \
+ all(isinstance(val, dict) for val in value):
+ # this is a list of entries (dicts), not values
+ self.print_attribute(label, u'', format, indent)
+ self.print_entries(value, order, labels, flags, print_all,
+ format, indent+1)
+ else:
+ self.print_attribute(
+ label, value, format, indent, one_value_per_line
+ )
del entry[key]
if print_all:
for key in sorted(entry):
@@ -1002,6 +1009,7 @@ class cli(backend.Executioner):
parser = optparse.OptionParser(
usage=' '.join(self.usage_iter(cmd))
)
+ option_groups = {}
for option in cmd.options():
kw = dict(
dest=option.name,
@@ -1025,7 +1033,18 @@ class cli(backend.Executioner):
o = optparse.make_option('-%s' % option.cli_short_name, '--%s' % to_cli(option.cli_name), **kw)
else:
o = optparse.make_option('--%s' % to_cli(option.cli_name), **kw)
- parser.add_option(o)
+
+ if option.option_group is not None:
+ option_group = option_groups.get(option.option_group)
+ if option_group is None:
+ option_group = optparse.OptionGroup(parser,
+ option.option_group)
+ parser.add_option_group(option_group)
+ option_groups[option.option_group] = option_group
+
+ option_group.add_option(o)
+ else:
+ parser.add_option(o)
return parser
def usage_iter(self, cmd):
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 22144b7c..be210864 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -384,6 +384,7 @@ class Param(ReadOnly):
('csv', bool, False),
('csv_separator', str, ','),
('csv_skipspace', bool, True),
+ ('option_group', unicode, None),
# The 'default' kwarg gets appended in Param.__init__():
# ('default', self.type, None),