summaryrefslogtreecommitdiffstats
path: root/ipalib/cli.py
diff options
context:
space:
mode:
Diffstat (limited to 'ipalib/cli.py')
-rw-r--r--ipalib/cli.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 5e257f709..639883375 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -21,6 +21,8 @@
Functionality for Command Line Inteface.
"""
+import sys
+import re
def to_cli(name):
"""
@@ -38,3 +40,32 @@ def from_cli(cli_name):
"""
assert isinstance(cli_name, basestring)
return cli_name.replace('-', '_')
+
+
+class CLI(object):
+ def __init__(self, api):
+ self.__api = api
+
+ def __get_api(self):
+ return self.__api
+ api = property(__get_api)
+
+ def print_commands(self):
+ for cmd in self.api.cmd:
+ print to_cli(cmd.name)
+
+ 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
+ sys.exit(2)
+ api.cmd[name]()