本文整理匯總了Python中argcomplete.CompletionFinder方法的典型用法代碼示例。如果您正苦於以下問題:Python argcomplete.CompletionFinder方法的具體用法?Python argcomplete.CompletionFinder怎麽用?Python argcomplete.CompletionFinder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類argcomplete
的用法示例。
在下文中一共展示了argcomplete.CompletionFinder方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _make_argparser
# 需要導入模塊: import argcomplete [as 別名]
# 或者: from argcomplete import CompletionFinder [as 別名]
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)
示例2: enable_autocomplete
# 需要導入模塊: import argcomplete [as 別名]
# 或者: from argcomplete import CompletionFinder [as 別名]
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 _: ())
示例3: __init__
# 需要導入模塊: import argcomplete [as 別名]
# 或者: from argcomplete import CompletionFinder [as 別名]
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