本文整理汇总了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