diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-12 23:33:02 +0000 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-08-12 23:33:02 +0000 |
commit | 64054a673c23b543450741fa11333bc627efeca3 (patch) | |
tree | 96846533e67791f728c6f31eda8dfbb737b3fa17 /ipalib/cli.py | |
parent | b72cfa5dcc488f3b497fa05a88985cc8f790cc00 (diff) | |
download | freeipa-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.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py index ad54d77ae..a0b8800ff 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]' |