summaryrefslogtreecommitdiffstats
path: root/ipalib/cli.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-11 21:38:30 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-11 21:38:30 +0000
commitafdbc42b2e721012daf7020430353c0686fcc5c3 (patch)
tree9ad1fbc88ea45247dbd5e20605b0a7529f289fc7 /ipalib/cli.py
parentc1a125256b302eceebcee5464f1447fc8e49fdf7 (diff)
downloadfreeipa-afdbc42b2e721012daf7020430353c0686fcc5c3.tar.gz
freeipa-afdbc42b2e721012daf7020430353c0686fcc5c3.tar.xz
freeipa-afdbc42b2e721012daf7020430353c0686fcc5c3.zip
112: More work on cli.py
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r--ipalib/cli.py24
1 files changed, 15 insertions, 9 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 63988337..e0ba11f8 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -24,6 +24,7 @@ Functionality for Command Line Inteface.
import sys
import re
+
def to_cli(name):
"""
Takes a Python identifier and transforms it into form suitable for the
@@ -54,18 +55,23 @@ class CLI(object):
for cmd in self.api.cmd:
print to_cli(cmd.name)
+ def __contains__(self, key):
+ return from_cli(key) in self.api.cmd
+
+ def __getitem__(self, key):
+ return self.api.cmd[from_cli(key)]
+
def run(self):
if len(sys.argv) < 2:
self.print_commands()
print 'Usage: ipa COMMAND [OPTIONS]'
sys.exit(2)
- return
- name= sys.argv[1]
- if name == '_api_':
- print_api()
- sys.exit()
- elif name not in api.cmd:
- print_commands()
- print 'ipa: ERROR: unknown command %r' % name
+ cmd = sys.argv[1]
+ if cmd not in self:
+ self.print_commands()
+ print 'ipa: ERROR: unknown command %r' % cmd
sys.exit(2)
- api.cmd[name]()
+ self.run_cmd(cmd)
+
+ def run_cmd(self, cmd):
+ print self[cmd]