Commit ee7c74fb authored by Jelte Jansen's avatar Jelte Jansen
Browse files

positional arguments for bigtool; if the command arguments are not in 'name =...

positional arguments for bigtool; if the command arguments are not in 'name = value' pairs, the arguments are parsed based on their position. The parser then adds the names again (so for the application the params is still a {name:value} dict


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/jelte-datadef@342 e5f2f494-b856-4b98-b285-d166d9295462
parent 7e2512b0
......@@ -60,13 +60,33 @@ class BigTool(Cmd):
raise CmdUnknownParamSyntaxError(cmd.module, cmd.command,
list(params.keys())[0])
elif params:
param_name = None
for name in params:
if not name in all_params:
# either the name of the parameter must be known, or
# the 'name' must be an integer (ie. the position of
# an unnamed argument
if type(name) == int:
# (-1, help is always in the all_params list)
if name >= len(all_params) - 1:
# add to last known param
if param_name:
cmd.params[param_name] += cmd.params[name]
else:
raise CmdUnknownParamSyntaxError(cmd.module, cmd.command, cmd.params[name])
else:
# replace the numbered items by named items
param_name = command_info.get_param_name_by_position(name+1)
cmd.params[param_name] = cmd.params[name]
del cmd.params[name]
elif not name in all_params:
raise CmdUnknownParamSyntaxError(cmd.module, cmd.command, name)
param_nr = 0
for name in manda_params:
if not name in params:
if not name in params and not param_nr in params:
raise CmdMissParamSyntaxError(cmd.module, cmd.command, name)
param_nr += 1
def _handle_cmd(self, cmd):
#to do, consist xml package and send to bind10
......
......@@ -72,7 +72,7 @@ class BigToolCmd:
if param and param.group('name') == "help":
self.params["help"] = "help"
return
while True:
if not param_text.strip():
break
......@@ -80,9 +80,16 @@ class BigToolCmd:
groups = PARAM_PATTERN.match(param_text) or \
PARAM_WITH_QUOTA_PATTERN.match(param_text)
if not groups:
raise CmdParamFormatError(self.module, self.command)
else:
if not groups:
#raise CmdParamFormatError(self.module, self.command)
# ok, fill in the params in the order entered
params = re.findall("([^\" ]+|\".*\")", param_text)
i = 0
for p in params:
self.params[i] = p
i += 1
break
else:
self.params[groups.group('param_name')] = groups.group('param_value')
param_text = groups.group('next_params')
if not param_text or (not param_text.strip()):
......
......@@ -81,7 +81,17 @@ class CommandInfo:
return [name for name in all_names
if not self.params[name].is_optional]
def get_param_name_by_position(self, pos):
if type(pos) == int:
i = 0
for k in self.params.keys():
if i == pos:
return k
i += 1
raise KeyError(str(pos) + " out of range")
else:
raise KeyError(str(pos) + " is not an integer")
def need_instance_param(self):
return self.need_inst_param
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment