summaryrefslogtreecommitdiffstats
path: root/ipalib/cli.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-12 23:33:02 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-12 23:33:02 +0000
commit64054a673c23b543450741fa11333bc627efeca3 (patch)
tree96846533e67791f728c6f31eda8dfbb737b3fa17 /ipalib/cli.py
parentb72cfa5dcc488f3b497fa05a88985cc8f790cc00 (diff)
downloadfreeipa-64054a673c23b543450741fa11333bc627efeca3.tar.gz
freeipa-64054a673c23b543450741fa11333bc627efeca3.tar.xz
freeipa-64054a673c23b543450741fa11333bc627efeca3.zip
122: The dictorary interface to CLI now has keys build using to_cli(), rather than converting at each call
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r--ipalib/cli.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index ad54d77a..a0b8800f 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -49,6 +49,8 @@ def _(arg):
class CLI(object):
+ __d = None
+
def __init__(self, api):
self.__api = api
@@ -61,12 +63,23 @@ class CLI(object):
print to_cli(cmd.name)
def __contains__(self, key):
- return from_cli(key) in self.api.cmd
+ assert self.__d is not None, 'you must call finalize() first'
+ return key in self.__d
def __getitem__(self, key):
- return self.api.cmd[from_cli(key)]
+ assert self.__d is not None, 'you must call finalize() first'
+ return self.__d[key]
+
+ def finalize(self):
+ api = self.api
+ api.finalize()
+ def d_iter():
+ for cmd in api.cmd:
+ yield (to_cli(cmd.name), cmd)
+ self.__d = dict(d_iter())
def run(self):
+ self.finalize()
if len(sys.argv) < 2:
self.print_commands()
print 'Usage: ipa COMMAND [OPTIONS]'