Python argcomplete.CompletionFinder() Examples

The following are 3 code examples of argcomplete.CompletionFinder(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module argcomplete , or try the search function .
Example #1
Source File: shell.py    From imagemounter with MIT License 6 votes vote down vote up
def _make_argparser(self):
        """Makes a new argument parser."""
        self.argparser = ShellArgumentParser(prog='')
        subparsers = self.argparser.add_subparsers()

        for name in self.get_names():
            if name.startswith('parser_'):
                parser = subparsers.add_parser(name[7:])
                parser.set_defaults(func=getattr(self, 'arg_' + name[7:]))
                getattr(self, name)(parser)

        self.argparser_completer = None

        try:
            import argcomplete
        except ImportError:
            pass
        else:
            os.environ.setdefault("_ARGCOMPLETE_COMP_WORDBREAKS", " \t\"'")
            self.argparser_completer = argcomplete.CompletionFinder(self.argparser) 
Example #2
Source File: completion.py    From knack with MIT License 5 votes vote down vote up
def enable_autocomplete(self, parser):
        if self.cli_ctx.data['completer_active']:
            argcomplete.autocomplete = argcomplete.CompletionFinder()
            argcomplete.autocomplete(parser, validator=lambda c, p: c.lower().startswith(p.lower()),
                                     default_completer=lambda _: ()) 
Example #3
Source File: commands.py    From gxf with MIT License 5 votes vote down vote up
def __init__(self, cmdname, cmdtype, repeat, prefix):

        self.cmdname = cmdname
        self.cmdtype = cmdtype
        self.repeat = repeat
        self.prefix = prefix

        # Setup a parser for this command.
        self.parser = ArgumentParser(
            prog=self.cmdname,
            description=self.__doc__)
        self.setup(self.parser)

        # We need to set the .completer hints in order for
        # argcomplete to know what to do on types we known.
        for action in self.parser._actions:
            if hasattr(action.type, "argcompleter"):
                action.completer = action.type.argcompleter

        # And prepare everything for autocompletion.
        self.completer = argcomplete.CompletionFinder(
            self.parser, always_complete_options=True)

        # gdb generates its help from the docstring.
        # We temporarilly overwrite it with argparse's output.
        old_doc, self.__doc__ = self.__doc__, self.parser.format_help().strip()

        # Call gdb's init. This will cause the command to be registerd.
        super().__init__(cmdname, cmdtype, prefix=prefix)

        # Restore the docstring so that it is usefull when looking
        # up help in python or when used for any other puprpose.
        self.__doc__ = old_doc