Fixed issue 476

This commit is contained in:
Nick Bolton 2010-05-31 11:39:28 +00:00
parent 6c63e83e99
commit fea12827d4
1 changed files with 13 additions and 9 deletions

22
hm.py
View File

@ -96,14 +96,8 @@ def start_cmd(argv):
if len(cmd_map) != 0: if len(cmd_map) != 0:
print 'Mapping command: %s' % ' -> '.join(cmd_map) print 'Mapping command: %s' % ' -> '.join(cmd_map)
# pass args and optarg data to command handler, which figures out run_cmd(cmd, argv[2:])
# how to handle the arguments
optarg_data = cmd_dict[cmd]
handler = commands.CommandHandler(argv[2:], optarg_data)
# use reflection to get the function pointer
cmd_func = getattr(handler, cmd)
cmd_func()
return 0 return 0
else: else:
@ -117,12 +111,22 @@ def start_cmd(argv):
print 'No command specified, showing usage.\n' print 'No command specified, showing usage.\n'
else: else:
print 'Command not recognised: %s\n' % cmd_arg print 'Command not recognised: %s\n' % cmd_arg
commands.usage(argv[2:]) run_cmd('usage')
# generic error code if not returned sooner # generic error code if not returned sooner
return 1 return 1
def run_cmd(cmd, args = []):
# pass args and optarg data to command handler, which figures out
# how to handle the arguments
optarg_data = cmd_dict[cmd]
handler = commands.CommandHandler(args, optarg_data)
# use reflection to get the function pointer
cmd_func = getattr(handler, cmd)
cmd_func()
def main(argv): def main(argv):
if sys.version_info < (2, 4): if sys.version_info < (2, 4):