浏览代码

Fix completion for semicolon separated commands

Mike Naberezny 11 年之前
父节点
当前提交
b580ac634e
共有 2 个文件被更改,包括 17 次插入4 次删除
  1. 7 4
      supervisor/supervisorctl.py
  2. 10 0
      supervisor/tests/test_supervisorctl.py

+ 7 - 4
supervisor/supervisorctl.py

@@ -233,15 +233,18 @@ class Controller(cmd.Cmd):
             import readline
             line = readline.get_line_buffer()
 
+        # take the last phrase from a line like "stop foo; start bar"
+        phrase = line.split(';')[-1]
+
         results = []
-        # blank line completes to action list
-        if not line.strip():
+        # blank phrase completes to action list
+        if not phrase.strip():
             results = self._complete_actions(text)
         else:
-            words = line.split()
+            words = phrase.split()
             action = words[0]
             # incomplete action completes to action list
-            if len(words) == 1 and not line.endswith(' '):
+            if len(words) == 1 and not phrase.endswith(' '):
                 results = self._complete_actions(text)
             # actions that accept an action name
             elif action in ('help'):

+ 10 - 0
supervisor/tests/test_supervisorctl.py

@@ -255,6 +255,16 @@ class ControllerTests(unittest.TestCase):
         result = controller.complete('', 1, line='reload ')
         self.assertTrue(result is None)
 
+    def test_complete_semicolon_separated_commands(self):
+        options = DummyClientOptions()
+        controller = self._makeOne(options)
+        controller.stdout=StringIO()
+        controller.vocab = ['help', 'start']
+        result = controller.complete('f', 0, line='help;start f')
+        self.assertEqual(result, 'foo ')
+        result = controller.complete('f', 1, line='help;start f')
+        self.assertTrue(result is None)
+
     def test_nohelp(self):
         options = DummyClientOptions()
         controller = self._makeOne(options)