Permalink
Browse files

Handle giving help a nonexistent command

The CLI would show an unhandled exception when running:
$ docker-compose help foobar

Now, it lists the commands.

Signed-off-by: Danny Guo <dannyguo91@gmail.com>
  • Loading branch information...
dguo committed Jun 17, 2016
1 parent 9bfb855 commit fbcc1510cca36c6e2e049b7692b11eccc8c33327
Showing with 15 additions and 9 deletions.
  1. +3 −0 .gitignore
  2. +6 −9 compose/cli/main.py
  3. +6 −0 tests/acceptance/cli_test.py
View
@@ -9,3 +9,6 @@
/venv
README.rst
compose/GITSHA
+*.swo
+*.swp
+.DS_Store
View
@@ -58,9 +58,8 @@
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)
@@ -150,6 +150,12 @@ def test_help(self):
# 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://')),

0 comments on commit fbcc151

Please sign in to comment.