Return-Path: X-Original-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-allura-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 939D2D42C for ; Tue, 28 May 2013 16:01:13 +0000 (UTC) Received: (qmail 82732 invoked by uid 500); 28 May 2013 16:01:13 -0000 Delivered-To: apmail-incubator-allura-commits-archive@incubator.apache.org Received: (qmail 82575 invoked by uid 500); 28 May 2013 16:01:13 -0000 Mailing-List: contact allura-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: allura-dev@incubator.apache.org Delivered-To: mailing list allura-commits@incubator.apache.org Received: (qmail 80039 invoked by uid 99); 28 May 2013 16:00:56 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 May 2013 16:00:56 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A0A0889BB1D; Tue, 28 May 2013 16:00:55 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: johnsca@apache.org To: allura-commits@incubator.apache.org Date: Tue, 28 May 2013 16:01:17 -0000 Message-Id: <0d1d8655c8b24ac6b535eb28c6eebb46@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [25/50] git commit: [#6270] ticket:359 Change task state to error on invalid args to paster command [#6270] ticket:359 Change task state to error on invalid args to paster command Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/1e9c2510 Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/1e9c2510 Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/1e9c2510 Branch: refs/heads/cj/5913 Commit: 1e9c25102172da3c112cf00944e8039216ba5ea9 Parents: 6686bcf Author: Igor Bondarenko Authored: Fri May 24 08:07:07 2013 +0000 Committer: Tim Van Steenburgh Committed: Fri May 24 13:22:14 2013 +0000 ---------------------------------------------------------------------- Allura/allura/command/base.py | 8 +++++++- Allura/allura/tests/test_commands.py | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1e9c2510/Allura/allura/command/base.py ---------------------------------------------------------------------- diff --git a/Allura/allura/command/base.py b/Allura/allura/command/base.py index d433643..536159d 100644 --- a/Allura/allura/command/base.py +++ b/Allura/allura/command/base.py @@ -40,7 +40,13 @@ def run_command(command, args): mod, cls = command.rsplit('.', 1) mod = __import__(mod, fromlist=[str(cls)]) command = getattr(mod, cls) - return command(command.__name__).run(shlex.split(args or '')) + command = command(command.__name__) + arg_list = shlex.split(args or '') + try: + command.parser.parse_args(arg_list) + except SystemExit: + raise Exception("Error parsing args: '%s'" % args) + return command.run(arg_list) class EmptyClass(object): pass http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/1e9c2510/Allura/allura/tests/test_commands.py ---------------------------------------------------------------------- diff --git a/Allura/allura/tests/test_commands.py b/Allura/allura/tests/test_commands.py index 5f4963c..fee6e21 100644 --- a/Allura/allura/tests/test_commands.py +++ b/Allura/allura/tests/test_commands.py @@ -341,6 +341,15 @@ class TestBackgroundCommand(object): base.run_command(self.cmd, 'dev.ini -p "project 3"') command(command.__name__).run.assert_called_with(['dev.ini', '-p', 'project 3']) + def test_invalid_args(self): + M.MonQTask.query.remove() + show_models.ReindexCommand.post('--invalid-option') + with td.raises(Exception): + M.MonQTask.run_ready() + task = M.MonQTask.query.get(task_name=self.task_name) + assert_equal(task.state, 'error') + assert_in('Error parsing args', task.result) + class TestReindexCommand(object):