diff --git a/.gitignore b/.gitignore index 4b318e232..ef04ca15f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ /venv README.rst compose/GITSHA +*.swo +*.swp +.DS_Store diff --git a/compose/cli/main.py b/compose/cli/main.py index 2f94e37c0..850c4bc85 100644 --- a/compose/cli/main.py +++ b/compose/cli/main.py @@ -58,9 +58,8 @@ console_handler = logging.StreamHandler(sys.stderr) def main(): - command = dispatch() - try: + command = dispatch() command() except (KeyboardInterrupt, signals.ShutdownException): log.error("Aborting.") @@ -78,6 +77,10 @@ def main(): except NeedsBuildError as e: log.error("Service '%s' needs to be built, but --no-build was passed." % e.service.name) sys.exit(1) + except NoSuchCommand as e: + commands = "\n".join(parse_doc_section("commands:", getdoc(e.supercommand))) + log.error("No such command: %s\n\n%s", e.command, commands) + sys.exit(1) except (errors.ConnectionError, StreamParseError): sys.exit(1) @@ -88,13 +91,7 @@ def dispatch(): TopLevelCommand, {'options_first': True, 'version': get_version_info('compose')}) - try: - options, handler, command_options = dispatcher.parse(sys.argv[1:]) - except NoSuchCommand as e: - commands = "\n".join(parse_doc_section("commands:", getdoc(e.supercommand))) - log.error("No such command: %s\n\n%s", e.command, commands) - sys.exit(1) - + options, handler, command_options = dispatcher.parse(sys.argv[1:]) setup_console_handler(console_handler, options.get('--verbose')) return functools.partial(perform_command, options, handler, command_options) diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index d0f7031f1..6121e7ed3 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -152,6 +152,12 @@ class CLITestCase(DockerClientTestCase): # Prevent tearDown from trying to create a project self.base_dir = None + def test_help_nonexistent(self): + self.base_dir = 'tests/fixtures/no-composefile' + result = self.dispatch(['help', 'foobar'], returncode=1) + assert 'No such command' in result.stderr + self.base_dir = None + def test_shorthand_host_opt(self): self.dispatch( ['-H={0}'.format(os.environ.get('DOCKER_HOST', 'unix://')),