summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Zuna <pzuna@redhat.com>2010-03-24 11:56:39 +0100
committerRob Crittenden <rcritten@redhat.com>2010-03-26 16:56:47 -0400
commitc7a35f95c5f1835c131797124f95f22968fbf8d8 (patch)
treee446562eb867a2c14fcc5ac76a5a1fe6c15c2047
parent4a61ff681c73f7994d885ee2638d8378c11931c1 (diff)
downloadfreeipa-c7a35f95c5f1835c131797124f95f22968fbf8d8.tar.gz
freeipa-c7a35f95c5f1835c131797124f95f22968fbf8d8.tar.xz
freeipa-c7a35f95c5f1835c131797124f95f22968fbf8d8.zip
Fix output for commands that do not return entries.
I also changed the default value of the print_all argument in textui.print_entry from False to True. It think it makes more sense this way, because: 1) if order is None, it will still print something 2) if order is not None, it will print what's in order first and then the rest 3) commands that care about the print_all argument have to set it in any case, those that don't care usually want to print everything
-rw-r--r--ipalib/cli.py4
-rw-r--r--ipalib/frontend.py27
2 files changed, 26 insertions, 5 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index db4a08e8..81269cd4 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -315,7 +315,7 @@ class textui(backend.Backend):
for attr in sorted(entry):
print_attr(attr)
- def print_entries(self, entries, order=None, labels=None, print_all=False, format='%s: %s', indent=1):
+ def print_entries(self, entries, order=None, labels=None, print_all=True, format='%s: %s', indent=1):
assert isinstance(entries, (list, tuple))
first = True
for entry in entries:
@@ -324,7 +324,7 @@ class textui(backend.Backend):
first = False
self.print_entry(entry, order, labels, print_all, format, indent)
- def print_entry(self, entry, order=None, labels=None, print_all=False, format='%s: %s', indent=1):
+ def print_entry(self, entry, order=None, labels=None, print_all=True, format='%s: %s', indent=1):
"""
"""
if isinstance(entry, (list, tuple)):
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 48215c5d..1881510c 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -775,6 +775,10 @@ class Command(HasParam):
This method gets called by `HasParam._create_param_namespace()`.
+ For commnds that return entries two special options are generated:
+ --all makes the command retrieve/dispaly all attribute
+ --raw makes the command display attributes as they are stored
+
Subclasses can override this to customize how the arguments are
determined. For an example of why this can be useful, see the
`ipalib.crud.Create` subclass.
@@ -836,6 +840,18 @@ class Command(HasParam):
yield param
def output_for_cli(self, textui, output, *args, **options):
+ """
+ Generic output method. Prints values the output argument according
+ to their type and self.output.
+
+ Entry attributes are labeled and printed in the order specified in
+ self.output_params. Attributes that aren't present in
+ self.output_params are not printed unless the command was invokend
+ with the --all option. Attribute labelling is disabled if the --raw
+ option was given.
+
+ Subclasses can override this method, if custom output is needed.
+ """
if not isinstance(output, dict):
return
@@ -852,14 +868,19 @@ class Command(HasParam):
labels = dict((p.name, unicode(p.label)) for p in self.output_params())
for o in self.output:
- if 'no_display' in self.output[o].flags:
+ outp = self.output[o]
+ if 'no_display' in outp.flags:
continue
result = output[o]
- if isinstance(result, (tuple, list)):
+ if isinstance(outp, ListOfEntries):
textui.print_entries(result, order, labels, print_all)
- elif isinstance(result, dict):
+ elif isinstance(result, (tuple, list)):
+ textui.print_entries(result)
+ elif isinstance(outp, Entry):
textui.print_entry(result, order, labels, print_all)
+ elif isinstance(result, dict):
+ textui.print_entry(result)
elif isinstance(result, unicode):
if o == 'summary':
textui.print_summary(result)