diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-08 21:37:02 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-09-08 21:37:02 +0000 |
commit | e74713a076a72e75d6ca44d12df8500fb5cad8d2 (patch) | |
tree | 021c4af1ac13b0e021e936efa6c1d7841cd8582f /ipalib/cli.py | |
parent | 641403278e00c30f24d9a6b4938b1e4ab3ecb427 (diff) | |
download | freeipa.git-e74713a076a72e75d6ca44d12df8500fb5cad8d2.tar.gz freeipa.git-e74713a076a72e75d6ca44d12df8500fb5cad8d2.tar.xz freeipa.git-e74713a076a72e75d6ca44d12df8500fb5cad8d2.zip |
267: Finished builtin CLI api command
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r-- | ipalib/cli.py | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index 05acad92..e4de6031 100644 --- a/ipalib/cli.py +++ b/ipalib/cli.py @@ -27,6 +27,7 @@ import code import optparse import public import errors +import plugable def to_cli(name): @@ -70,6 +71,37 @@ class console(public.Application): class print_api(public.Application): 'Print details on the loaded plugins.' + def __call__(self): + lines = self.__traverse() + ml = max(len(l[1]) for l in lines) + for line in lines: + if line[0] == 0: + print '' + print '%s%s %r' % ( + ' ' * line[0], + line[1].ljust(ml), + line[2], + ) + + def __traverse(self): + lines = [] + for name in self.api: + namespace = self.api[name] + self.__traverse_namespace(name, namespace, lines) + return lines + + def __traverse_namespace(self, name, namespace, lines, tab=0): + lines.append((tab, name, namespace)) + for member_name in namespace: + member = namespace[member_name] + lines.append((tab + 1, member_name, member)) + if not hasattr(member, '__iter__'): + continue + for n in member: + attr = member[n] + if isinstance(attr, plugable.NameSpace): + self.__traverse_namespace(n, attr, lines, tab + 2) + class KWCollector(object): def __init__(self): @@ -89,7 +121,6 @@ class KWCollector(object): return dict(self.__d) - class CLI(object): __d = None __mcl = None @@ -184,8 +215,6 @@ class CLI(object): error = e.error cmd(*args, **kw) - - def parse(self, cmd, argv): parser = self.build_parser(cmd) (kwc, args) = parser.parse_args(argv, KWCollector()) @@ -202,8 +231,6 @@ class CLI(object): ) return parser - - def __get_mcl(self): """ Returns the Max Command Length. |