summaryrefslogtreecommitdiffstats
path: root/ipalib/cli.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-12-09 09:09:53 -0700
committerJason Gerard DeRose <jderose@redhat.com>2009-12-10 08:29:15 -0700
commitb6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7 (patch)
tree7e5329a51af169ce34a7d275a1bbd63c1e31c026 /ipalib/cli.py
parentd08b8858ddc3bf6265f6ea8acae6661b9fff5112 (diff)
downloadfreeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.tar.gz
freeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.tar.xz
freeipa-b6e4972e7f6aa08e0392a2cf441b60ab0e7d88b7.zip
Take 2: Extensible return values and validation; steps toward a single output_for_cli(); enable more webUI stuff
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r--ipalib/cli.py58
1 files changed, 55 insertions, 3 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 64ace0359..d0feaaea3 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -312,6 +312,37 @@ class textui(backend.Backend):
for attr in sorted(entry):
print_attr(attr)
+ def print_entries(self, entries, params=None, format='%s: %s', indent=1):
+ assert isinstance(entries, (list, tuple))
+ first = True
+ for entry in entries:
+ if not first:
+ print ''
+ first = False
+ self.print_entry(entry, params, format, indent)
+
+ def print_entry(self, entry, params=None, format='%s: %s', indent=1):
+ """
+ """
+ if isinstance(entry, (list, tuple)):
+ entry = dict(entry)
+ assert isinstance(entry, dict)
+ if params:
+ order = list(params)
+ labels = dict((p.name, p.label) for p in params())
+ else:
+ order = sorted(entry)
+ labels = dict((k, k) for k in order)
+ for key in order:
+ if key not in entry:
+ continue
+ label = labels[key]
+ value = entry[key]
+ if isinstance(value, (list, tuple)):
+ value = ', '.join(value)
+ self.print_indented(format % (label, value), indent)
+
+
def print_dashed(self, string, above=True, below=True, indent=0, dash='-'):
"""
Print a string with a dashed line above and/or below.
@@ -383,6 +414,23 @@ class textui(backend.Backend):
"""
self.print_dashed('%s:' % to_cli(name))
+ def print_header(self, msg, output):
+ self.print_dashed(msg % output)
+
+ def print_summary(self, msg):
+ """
+ Print a summary at the end of a comand's output.
+
+ For example:
+
+ >>> ui = textui()
+ >>> ui.print_summary('Added user "jdoe"')
+ -----------------
+ Added user "jdoe"
+ -----------------
+ """
+ self.print_dashed(msg)
+
def print_count(self, count, singular, plural=None):
"""
Print a summary count.
@@ -408,7 +456,7 @@ class textui(backend.Backend):
``len(count)`` is used as the count.
"""
if type(count) is not int:
- assert type(count) in (list, tuple)
+ assert type(count) in (list, tuple, dict)
count = len(count)
self.print_dashed(
self.choose_number(count, singular, plural)
@@ -515,6 +563,8 @@ class help(frontend.Command):
takes_args = (Bytes('command?'),)
+ has_output = tuple()
+
_PLUGIN_BASE_MODULE = 'ipalib.plugins'
def _get_command_module(self, module):
@@ -614,6 +664,8 @@ class help(frontend.Command):
class console(frontend.Command):
"""Start the IPA interactive Python console."""
+ has_output = tuple()
+
def run(self):
code.interact(
'(Custom IPA interactive Python console)',
@@ -814,8 +866,8 @@ class cli(backend.Executioner):
error = None
while True:
if error is not None:
- print '>>> %s: %s' % (param.cli_name, error)
- raw = self.Backend.textui.prompt(param.cli_name, default)
+ print '>>> %s: %s' % (param.label, error)
+ raw = self.Backend.textui.prompt(param.label, default)
try:
value = param(raw, **kw)
if value is not None: