summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-24 05:35:40 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-24 05:35:40 +0000
commiteaf15d5a52b8438d1a0a5b59a9ace9660a703dce (patch)
tree55cfa7d097d0de1b70dd1847c7776321497e3249
parentf3ac709922c33425c211b79787f1dedc03bb6508 (diff)
downloadfreeipa-eaf15d5a52b8438d1a0a5b59a9ace9660a703dce.tar.gz
freeipa-eaf15d5a52b8438d1a0a5b59a9ace9660a703dce.tar.xz
freeipa-eaf15d5a52b8438d1a0a5b59a9ace9660a703dce.zip
327: Improved formatting on show-api cli command
-rw-r--r--ipalib/cli.py40
-rw-r--r--ipalib/frontend.py2
2 files changed, 32 insertions, 10 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 36a5bd1b..8918206f 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -94,26 +94,46 @@ class console(frontend.Application):
)
-class namespaces(frontend.Application):
- 'Show details of plugable namespaces'
- def run(self):
- lines = self.__traverse()
+class show_api(text_ui):
+ 'Show attributes on dynamic API object'
+
+ takes_args = ('namespaces*',)
+
+ def run(self, namespaces):
+ if namespaces is None:
+ names = tuple(self.api)
+ else:
+ for name in namespaces:
+ if name not in self.api:
+ exit_error('api has no such namespace: %s' % name)
+ names = namespaces
+ lines = self.__traverse(names)
ml = max(len(l[1]) for l in lines)
+ self.print_name()
+ first = True
for line in lines:
- if line[0] == 0:
+ if line[0] == 0 and not first:
print ''
+ if first:
+ first = False
print '%s%s %r' % (
' ' * line[0],
line[1].ljust(ml),
line[2],
)
+ if len(lines) == 1:
+ s = '1 attribute shown.'
+ else:
+ s = '%d attributes show.' % len(lines)
+ self.print_dashed(s)
+
- def __traverse(self):
+ def __traverse(self, names):
lines = []
- for name in self.api:
+ for name in names:
namespace = self.api[name]
- self.__traverse_namespace(name, namespace, lines)
+ self.__traverse_namespace('%s' % name, namespace, lines)
return lines
def __traverse_namespace(self, name, namespace, lines, tab=0):
@@ -155,7 +175,7 @@ class plugins(text_ui):
cli_application_commands = (
help,
console,
- namespaces,
+ show_api,
plugins,
)
@@ -253,6 +273,8 @@ class CLI(object):
def run_interactive(self, cmd, kw):
for param in cmd.params():
if param.name not in kw:
+ if not param.required:
+ continue
default = param.get_default(**kw)
if default is None:
prompt = '%s: ' % param.name
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index dbc3a62d..d4550f87 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -356,7 +356,7 @@ class Command(plugable.Plugin):
kw = self.convert(**kw)
kw.update(self.get_default(**kw))
self.validate(**kw)
- args = tuple(kw.pop(name) for name in self.args)
+ args = tuple(kw.pop(name, None) for name in self.args)
return self.run(*args, **kw)
def run(self, *args, **kw):