# HG changeset patch # User Pascal Volk # Date 1356883938 0 # Node ID 50148adebee93ea9ddaf1a8fa5191f3fe76c39e5 # Parent 33d15936b53a02ccdcbf3ff7b0386f6a1fd2370a VMM/cli/main: Adjusted to new argparse functionality. diff -r 33d15936b53a -r 50148adebee9 VirtualMailManager/cli/main.py --- 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. diff -r 33d15936b53a -r 50148adebee9 vmm --- a/vmm Sun Dec 30 16:10:29 2012 +0000 +++ b/vmm Sun Dec 30 16:12:18 2012 +0000 @@ -15,4 +15,4 @@ # Otherwise just remove /usr/local/sbin from sys.path sys.path.remove(sys.path[0]) from VirtualMailManager.cli.main import run - sys.exit(run(sys.argv)) + sys.exit(run())