aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/command/serve_commands.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@tremily.us>2012-09-03 09:36:56 -0400
committerW. Trevor King <wking@tremily.us>2012-09-03 09:36:56 -0400
commit13e6d6ecfef7ff68fa24c2744e0f6621d6cf3491 (patch)
treec2e4ba0adf69e0e5391e0db85c2ada20cc0683b2 /libbe/command/serve_commands.py
parent7c1db6f55380c3511ac305a6fe3c16315216b527 (diff)
downloadbugseverywhere-13e6d6ecfef7ff68fa24c2744e0f6621d6cf3491.tar.gz
command:serve_commands: allow unspecified parameters (use defaults).
Also raise UnknownCommand if there is no `command` key in the posted dict (malformed request). With the new code, you can run commands with: $ wget --post-data='command: list' http://localhost:8000/run/ instead of having to go through and specify all the parameters explicitly. This will make the command server more robust for use with older clients (who may not know about all the parameters that the server knows about). Parameters sent by the client that the server does not know about are silently ignored.
Diffstat (limited to 'libbe/command/serve_commands.py')
-rw-r--r--libbe/command/serve_commands.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/libbe/command/serve_commands.py b/libbe/command/serve_commands.py
index d8598e2..607cb74 100644
--- a/libbe/command/serve_commands.py
+++ b/libbe/command/serve_commands.py
@@ -85,8 +85,12 @@ class ServerApp (libbe.util.wsgi.WSGI_AppObject,
self.check_login(environ)
data = self.post_data(environ)
source = 'post'
- name = data['command']
- parameters = data['parameters']
+ try:
+ name = data['command']
+ except KeyError:
+ raise libbe.util.wsgi.HandlerError(
+ self.http_user_error, 'UnknownCommand')
+ parameters = data.get('parameters', {})
try:
Class = libbe.command.get_command_class(command_name=name)
except libbe.command.UnknownCommand, e:
@@ -94,6 +98,12 @@ class ServerApp (libbe.util.wsgi.WSGI_AppObject,
self.http_user_error, 'UnknownCommand {}'.format(e))
command = Class(ui=self.ui)
self.ui.setup_command(command)
+ arguments = [option.arg for option in command.options
+ if option.arg is not None]
+ arguments.extend(command.args)
+ for argument in arguments:
+ if argument.name not in parameters:
+ parameters[argument.name] = argument.default
command.status = command._run(**parameters) # already parsed params
assert command.status == 0, command.status
stdout = self.ui.io.get_stdout()