- added ability for Tcl commands to have optional arguments with None value (meaning missing value). This case should be treated for each Tcl command in execute() method
This commit is contained in:
@@ -177,19 +177,26 @@ class TclCommand(object):
|
||||
arguments = []
|
||||
n = len(args)
|
||||
|
||||
name = None
|
||||
option_name = None
|
||||
|
||||
for i in range(n):
|
||||
match = re.search(r'^-([a-zA-Z].*)', args[i])
|
||||
if match:
|
||||
assert name is None
|
||||
name = match.group(1)
|
||||
# assert option_name is None
|
||||
if option_name is not None:
|
||||
options[option_name] = None
|
||||
|
||||
option_name = match.group(1)
|
||||
continue
|
||||
|
||||
if name is None:
|
||||
if option_name is None:
|
||||
arguments.append(args[i])
|
||||
else:
|
||||
options[name] = args[i]
|
||||
name = None
|
||||
options[option_name] = args[i]
|
||||
option_name = None
|
||||
|
||||
if option_name is not None:
|
||||
options[option_name] = None
|
||||
|
||||
return arguments, options
|
||||
|
||||
@@ -211,6 +218,7 @@ class TclCommand(object):
|
||||
for argument in arguments:
|
||||
if len(self.arg_names) > idx:
|
||||
key, arg_type = arg_names_items[idx]
|
||||
|
||||
try:
|
||||
named_args[key] = arg_type(argument)
|
||||
except Exception as e:
|
||||
@@ -226,7 +234,12 @@ class TclCommand(object):
|
||||
self.raise_tcl_error('Unknown parameter: %s' % key)
|
||||
try:
|
||||
if key != 'timeout':
|
||||
named_args[key] = self.option_types[key](options[key])
|
||||
# None options are allowed; if None then the defaults are used
|
||||
# - must be implemented in the Tcl commands
|
||||
if options[key] is not None:
|
||||
named_args[key] = self.option_types[key](options[key])
|
||||
else:
|
||||
named_args[key] = options[key]
|
||||
else:
|
||||
named_args[key] = int(options[key])
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user