浏览代码

Merge pull request #3263 from twitherspoon/3191_2_help_cli_feature

Added code to support no argument help command
Aanand Prasad 9 年之前
父节点
当前提交
984f839d33
共有 2 个文件被更改,包括 10 次插入5 次删除
  1. 7 3
      compose/cli/main.py
  2. 3 2
      tests/unit/cli_test.py

+ 7 - 3
compose/cli/main.py

@@ -372,10 +372,14 @@ class TopLevelCommand(object):
         """
         Get help on a command.
 
-        Usage: help COMMAND
+        Usage: help [COMMAND]
         """
-        handler = get_handler(cls, options['COMMAND'])
-        raise SystemExit(getdoc(handler))
+        if options['COMMAND']:
+            subject = get_handler(cls, options['COMMAND'])
+        else:
+            subject = cls
+
+        print(getdoc(subject))
 
     def kill(self, options):
         """

+ 3 - 2
tests/unit/cli_test.py

@@ -5,6 +5,7 @@ from __future__ import unicode_literals
 import os
 import shutil
 import tempfile
+from io import StringIO
 
 import docker
 import py
@@ -83,10 +84,10 @@ class CLITestCase(unittest.TestCase):
         self.assertTrue(project.services)
 
     def test_command_help(self):
-        with pytest.raises(SystemExit) as exc:
+        with mock.patch('sys.stdout', new=StringIO()) as fake_stdout:
             TopLevelCommand.help({'COMMAND': 'up'})
 
-        assert 'Usage: up' in exc.exconly()
+        assert "Usage: up" in fake_stdout.getvalue()
 
     def test_command_help_nonexistent(self):
         with pytest.raises(NoSuchCommand):