From 13e6d6ecfef7ff68fa24c2744e0f6621d6cf3491 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 3 Sep 2012 09:36:56 -0400 Subject: [PATCH] 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. --- libbe/command/serve_commands.py | 14 ++++++++++++-- 1 file 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() -- 2.26.2