Merge pull request #3617 from dguo/help-nonexistent-command

Handle giving help a nonexistent command
This commit is contained in:
Joffrey F 2017-03-01 16:31:37 -08:00 committed by GitHub
commit eca3146c9c
3 changed files with 15 additions and 9 deletions

3
.gitignore vendored
View File

@ -9,3 +9,6 @@
/venv
README.rst
compose/GITSHA
*.swo
*.swp
.DS_Store

View File

@ -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)

View File

@ -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://')),