How to use the argcomplete.completers.SuppressCompleter function in argcomplete

To help you get started, we’ve selected a few argcomplete examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alttch / icli / icli / __init__.py View on Github external
if self.interactive_history_file:
                try:
                    readline.write_history_file(
                        os.path.expanduser(self.interactive_history_file))
                except:
                    pass

        if stream:
            input_strings = stream.readlines()
            if not input_strings:
                return
            sidx = 0
        else:
            self._i_completer = argcomplete.CompletionFinder(
                self,
                default_completer=argcomplete.completers.SuppressCompleter())
            readline.set_completer_delims('')
            readline.set_completer(self.interactive_completer)
            readline.parse_and_bind('tab: complete')
            readline.set_history_length(self.interactive_history_length)
            if self.interactive_history_file:
                try:
                    readline.read_history_file(
                        os.path.expanduser(self.interactive_history_file))
                except:
                    pass
        while True:
            try:
                if stream:
                    try:
                        input_str = input_strings[sidx]
                    except IndexError:
github ros2 / ros2cli / ros2run / ros2run / command / run.py View on Github external
def add_arguments(self, parser, cli_name):
        arg = parser.add_argument(
            '--prefix',
            help='Prefix command, which should go before the executable. '
                 'Command must be wrapped in quotes if it contains spaces '
                 "(e.g. --prefix 'gdb -ex run --args').")
        try:
            from argcomplete.completers import SuppressCompleter
        except ImportError:
            pass
        else:
            arg.completer = SuppressCompleter()
        arg = parser.add_argument(
            'package_name',
            help='Name of the ROS package')
        arg.completer = package_name_completer
        arg = parser.add_argument(
            'executable_name',
            help='Name of the executable')
        arg.completer = ExecutableNameCompleter(
            package_name_key='package_name')
        parser.add_argument(
            'argv', nargs=REMAINDER,
            help='Pass arbitrary arguments to the executable')
github kislyuk / argcomplete / argcomplete / __init__.py View on Github external
def _get_option_completions(self, parser, cword_prefix):
        self._display_completions.update(
            [[tuple(ensure_str(x) for x in action.option_strings
             if ensure_str(x).startswith(cword_prefix)), action.help]
             for action in parser._actions
             if action.option_strings])

        option_completions = []
        for action in parser._actions:
            if not self.print_suppressed:
                completer = getattr(action, "completer", None)
                if isinstance(completer, SuppressCompleter) and completer.suppress():
                    continue
                if action.help == argparse.SUPPRESS:
                    continue
            if not self._action_allowed(action, parser):
                continue
            if not isinstance(action, argparse._SubParsersAction):
                option_completions += self._include_options(action, cword_prefix)
        return option_completions
github kislyuk / argcomplete / argcomplete / __init__.py View on Github external
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:
                if active_action.choices is not None and not isinstance(active_action, argparse._SubParsersAction):
                    completer = completers.ChoicesCompleter(active_action.choices)
                elif not isinstance(active_action, argparse._SubParsersAction):
                    completer = self.default_completer

            if completer:
                if isinstance(completer, SuppressCompleter) and completer.suppress():
                    continue

                if callable(completer):
                    completions_from_callable = [c for c in completer(
                        prefix=cword_prefix, action=active_action, parser=parser, parsed_args=parsed_args)
                        if self.validator(c, cword_prefix)]

                    if completions_from_callable:
                        completions += completions_from_callable
                        if isinstance(completer, completers.ChoicesCompleter):
                            self._display_completions.update(
                                [[(x,), active_action.help] for x in completions_from_callable])
                        else:
                            self._display_completions.update(
                                [[(x,), ""] for x in completions_from_callable])
                else: