Exemplo n.º 1
0
    def complete(self, line, text, state):
        tokens = merge_escaped(line.split())
        complete_cmd = len(tokens) == 0 or (len(tokens) == 1
                                            and not line.endswith(' '))

        values = []
        if complete_cmd:
            values = self._cmds.get_commands()
        elif (len(tokens) > 0) and text.startswith('-'):
            values = self._cmds.get_options(tokens[0])
        else:
            tokens = self._strip_options(tokens)
            item_path = self._get_item_path(
                tokens[1] if len(tokens) > 1 else '')
            if item_path != self._last_path:
                self._last_path = item_path
                self._last_item = self._next_item(item_path)

            for c in self._last_item.children_conts:
                values.append(c + "/")

            for c in self._last_item.children_leaves:
                values.append(c)

        options = [i for i in values if i.startswith(text)]
        options.sort()
        if state < len(options):
            return self._escape(options[state])
Exemplo n.º 2
0
    def complete(self, line, text, state):
        tokens = merge_escaped(line.split())
        complete_cmd = len(tokens) == 0 or (len(tokens) == 1 and not line.endswith(" "))

        values = []
        if complete_cmd:
            values = self._cmds.get_commands()
        elif (len(tokens) > 0) and text.startswith("-"):
            values = self._cmds.get_options(tokens[0])
        else:
            tokens = self._strip_options(tokens)
            item_path = self._get_item_path(tokens[1] if len(tokens) > 1 else "")
            if item_path != self._last_path:
                self._last_path = item_path
                self._last_item = self._next_item(item_path)

            for c in self._last_item.children_conts:
                values.append(c + "/")

            for c in self._last_item.children_leaves:
                values.append(c)

        options = [i for i in values if i.startswith(text)]
        options.sort()
        if state < len(options):
            return self._escape(options[state])
Exemplo n.º 3
0
 def execute_line(self, line):
     # Strip comments out
     index = line.find('#')
     if index >= 0:
         line = line[0:index]
     line = line.strip()
     # If line is empty, do nothing
     if line != '':
         args = merge_escaped(line.split())
         self._execute(args)
Exemplo n.º 4
0
 def execute_line(self, line):
     # Strip comments out
     index = line.find('#')
     if index >= 0:
         line = line[0:index]
     line = line.strip()
     # If line is empty, do nothing
     if line != '':
         args = merge_escaped(line.split())
         self._execute(args)
Exemplo n.º 5
0
 def test_merge_escaped(self):
     result = utils.merge_escaped(["a", "test\\", "1\\", "2"])
     self.assertEqual(result, ["a", "test 1 2"])
Exemplo n.º 6
0
 def test_merge_escaped(self):
     result = utils.merge_escaped(["a", "test\\", "1\\", "2"])
     self.assertEqual(result, ["a", "test 1 2"])