Visits the active parsers and their actions, executes their completers or introspects them to collect their
        option strings. Returns the resulting completions as a list of strings.

        This method is exposed for overriding in subclasses; there is no need to use it directly.

def collect_completions(self, active_parsers, parsed_args, cword_prefix, debug):
        '''
        Visits the active parsers and their actions, executes their completers or introspects them to collect their
        option strings. Returns the resulting completions as a list of strings.

        This method is exposed for overriding in subclasses; there is no need to use it directly.
        '''
        completions = []
        for parser in active_parsers:
            debug("Examining parser", parser)
            for action in parser._actions:
                debug("Examining action", action)
                if isinstance(action, argparse._SubParsersAction):
                    subparser_activated = False
                    for subparser in action._name_parser_map.values():
                        if subparser in active_parsers:
                            subparser_activated = True
                    if subparser_activated:
                        # Parent parser completions are not valid in the subparser, so flush them
                        completions = []
                    else:
                        completions += [subcmd for subcmd in action.choices.keys() if subcmd.startswith(cword_prefix)]
                elif self.always_complete_options or (len(cword_prefix) > 0 and cword_prefix[0] in parser.prefix_chars):
                    completions += [option for option in action.option_strings if option.startswith(cword_prefix)]

            debug("Active actions (L={l}): {a}".format(l=len(parser.active_actions), a=parser.active_actions))

            # Only run completers if current word does not start with - (is not an optional)
            if len(cword_prefix) == 0 or cword_prefix[0] not in parser.prefix_chars:
                for active_action in parser.active_actions:
                    if not active_action.option_strings: # action is a positional
                        if action_is_satisfied(active_action) and not action_is_open(active_action):
                            debug("Skipping", active_action)
                            continue

                    debug("Activating completion for", active_action, active_action._orig_class)
                    #completer = getattr(active_action, 'completer', DefaultCompleter())
                    completer = getattr(active_action, 'completer', None)

                    if completer is None and active_action.choices is not None:
                        if not isinstance(active_action, argparse._SubParsersAction):
                            completer = completers.ChoicesCompleter(active_action.choices)

                    if completer:
                        if len(active_action.option_strings) > 0: # only for optionals
                            if not action_is_satisfied(active_action):
                                # This means the current action will fail to parse if the word under the cursor is not given
                                # to it, so give it exclusive control over completions (flush previous completions)
                                debug("Resetting completions because", active_action, "is unsatisfied")
                                completions = []
                        if callable(completer):
                            completions += [c for c in completer(prefix=cword_prefix, action=active_action,
                                                                 parsed_args=parsed_args)
                                            if self.validator(c, cword_prefix)]
                        else:
                            debug("Completer is not callable, trying the readline completer protocol instead")
                            for i in range(9999):
                                next_completion = completer.complete(cword_prefix, i)
                                if next_completion is None:
                                    break
                                if self.validator(next_completion, cword_prefix):
                                    completions.append(next_completion)
                        debug("Completions:", completions)
                    elif not isinstance(active_action, argparse._SubParsersAction):
                        pass
                        """
                        debug("Completer not available, falling back")
                        try:
                            # TODO: what happens if completions contain newlines? How do I make compgen use IFS?
                            bashcomp_cmd = ['bash', '-c', "compgen -A file -- '{p}'".format(p=cword_prefix)]
                            completions += subprocess.check_output(bashcomp_cmd).decode(sys_encoding).splitlines()
                        except subprocess.CalledProcessError:
                            pass
                        """
        return completions