From 2c199e1ec4a226ccecb5282879f284965c5c9b39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Hajdan=2C=20Jr?= Date: Fri, 12 May 2017 16:49:45 +0200 Subject: [PATCH] gclient: return non-zero exit code on unknown command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: none Change-Id: I447f66765679b7b66b5748af1cf1f501610603bf Reviewed-on: https://chromium-review.googlesource.com/504408 Reviewed-by: Andrii Shyshkalov Commit-Queue: Paweł Hajdan Jr. --- subcommand.py | 13 +++++-------- tests/gclient_smoketest.py | 3 ++- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/subcommand.py b/subcommand.py index a9ebae098..ae0705bcb 100644 --- a/subcommand.py +++ b/subcommand.py @@ -66,13 +66,8 @@ def epilog(text): def CMDhelp(parser, args): """Prints list of commands or help for a specific command.""" - # This is the default help implementation. It can be disabled or overriden if - # wanted. - if not any(i in ('-h', '--help') for i in args): - args = args + ['--help'] - _, args = parser.parse_args(args) - # Never gets there. - assert False + parser.print_help() + return 0 def _get_color_module(): @@ -255,7 +250,9 @@ class CommandDispatcher(object): if cmdhelp: # Not a known command. Default to help. self._add_command_usage(parser, cmdhelp) - return cmdhelp(parser, args) + # Make sure we return a non-zero exit code for unknown commands. + rc = cmdhelp(parser, args) + return rc if rc != 0 else 2 # Nothing can be done. return 2 diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index e549786ea..7bd6df014 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -165,7 +165,8 @@ class GClientSmoke(GClientSmokeBase): self.assertTrue(1000 < len(result[0]) and len(result[0]) < 2300, 'Too much written to stdout: %d bytes' % len(result[0])) self.assertEquals(0, len(result[1])) - self.assertEquals(0, result[2]) + # An unknown command should result in non-zero exit code. + self.assertEquals(2, result[2]) def testNotConfigured(self): res = ('', 'Error: client not configured; see \'gclient config\'\n', 1)