comparison cmd2.py @ 302:b4b22dd087dc

refactored, unit tests pass
author catherine@dellzilla
date Tue, 26 Jan 2010 18:11:12 -0500
parents 30af90fd46c5
children c3b9b2256dd6
comparison
equal deleted inserted replaced
301:30af90fd46c5 302:b4b22dd087dc
110 optionParser.add_option(opt) 110 optionParser.add_option(opt)
111 optionParser.set_usage("%s [options] arg" % func.__name__.strip('do_')) 111 optionParser.set_usage("%s [options] arg" % func.__name__.strip('do_'))
112 optionParser._func = func 112 optionParser._func = func
113 def new_func(instance, arg): 113 def new_func(instance, arg):
114 try: 114 try:
115 if hasattr(arg, 'parsed'): 115 opts, newArgList = optionParser.parse_args(arg.split())
116 args = arg.parsed.raw
117 else:
118 print 'raw arg passed to new_func!'
119 args = arg
120 opts, newArgList = optionParser.parse_args(args.split())
121 # Must find the remaining args in the original argument list, but 116 # Must find the remaining args in the original argument list, but
122 # mustn't include the command itself 117 # mustn't include the command itself
123 if hasattr(arg, 'parsed') and newArgList[0] == arg.parsed.command: 118 #if hasattr(arg, 'parsed') and newArgList[0] == arg.parsed.command:
124 newArgList = newArgList[1:] 119 # newArgList = newArgList[1:]
125 newArgs = remaining_args(args, newArgList) 120 newArgs = remaining_args(arg, newArgList)
126 if isinstance(arg, ParsedString): 121 if isinstance(arg, ParsedString):
127 arg = arg.with_args_replaced(newArgs) 122 arg = arg.with_args_replaced(newArgs)
128 else: 123 else:
129 arg = newArgs 124 arg = newArgs
130 except (optparse.OptionValueError, optparse.BadOptionError, 125 except (optparse.OptionValueError, optparse.BadOptionError,