VirtualMailManager/cli/main.py
branchv0.7.x
changeset 666 50148adebee9
parent 643 df1e3b67882a
child 676 2bc11dada296
--- a/VirtualMailManager/cli/main.py	Sun Dec 30 16:10:29 2012 +0000
+++ b/VirtualMailManager/cli/main.py	Sun Dec 30 16:12:18 2012 +0000
@@ -14,10 +14,9 @@
 from VirtualMailManager.config import BadOptionError, ConfigValueError
 from VirtualMailManager.cli import w_err
 from VirtualMailManager.cli.handler import CliHandler
-from VirtualMailManager.constants import DATABASE_ERROR, EX_MISSING_ARGS, \
-     EX_SUCCESS, EX_UNKNOWN_COMMAND, EX_USER_INTERRUPT, INVALID_ARGUMENT
-from VirtualMailManager.cli.subcommands import RunContext, cmd_map, \
-     update_cmd_map, usage
+from VirtualMailManager.constants import DATABASE_ERROR, EX_SUCCESS, \
+     EX_USER_INTERRUPT, INVALID_ARGUMENT
+from VirtualMailManager.cli.subcommands import RunContext, setup_parser
 
 
 _ = lambda msg: msg
@@ -35,27 +34,13 @@
         return handler
 
 
-def run(argv):
-    update_cmd_map()
-    if len(argv) < 2:
-        usage(EX_MISSING_ARGS, _("You must specify a subcommand at least."))
-
-    sub_cmd = argv[1].lower()
-    if sub_cmd in cmd_map:
-        cmd_func = cmd_map[sub_cmd].func
-    else:
-        for cmd in cmd_map.values():
-            if cmd.alias == sub_cmd:
-                cmd_func = cmd.func
-                sub_cmd = cmd.name
-                break
-        else:
-            usage(EX_UNKNOWN_COMMAND, _("Unknown subcommand: '%s'") % sub_cmd)
-
+def run():
+    parser = setup_parser()
+    args = parser.parse_args()
     handler = _get_handler()
-    run_ctx = RunContext(argv, handler, sub_cmd)
+    run_ctx = RunContext(args, handler)
     try:
-        cmd_func(run_ctx)
+        args.func(run_ctx)
     except (EOFError, KeyboardInterrupt):
         # TP: We have to cry, because root has killed/interrupted vmm
         # with Ctrl+C or Ctrl+D.