本文整理汇总了Python中inquirer.Checkbox方法的典型用法代码示例。如果您正苦于以下问题:Python inquirer.Checkbox方法的具体用法?Python inquirer.Checkbox怎么用?Python inquirer.Checkbox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inquirer
的用法示例。
在下文中一共展示了inquirer.Checkbox方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prompt_targets
# 需要导入模块: import inquirer [as 别名]
# 或者: from inquirer import Checkbox [as 别名]
def prompt_targets(question, targets=None, instances=None, multiple=True, config=None, type=InstanceType.ALL, filter_sources=tuple()):
if targets == None and instances == None or targets != None and instances != None:
raise RuntimeError("Provide exactly one of either 'targets' or 'instances'")
if targets:
instances = inventory.search(config, targets, filter_sources=filter_sources, type=type)
if len(instances) == 0:
return []
if len(instances) == 1:
return instances
display_instances = collections.OrderedDict()
# TODO: fix cap'd length... it's pretty arbitraty
maxLen = min(max([len(instance.name) for instance in instances]), 55)
for instance in sorted(instances):
display = str("%-" + str(maxLen+3) + "s (%s)") % (instance.name, instance.address)
display_instances[display] = instance
questions = []
if multiple:
question = inquirer.Checkbox('instance',
message="%s%s%s (space to multi-select, enter to finish)" % (utils.term.bold + utils.term.underline, question, utils.term.normal),
choices=list(display_instances.keys()) + ['all'],
# default='all'
)
else:
question = inquirer.List('instance',
message="%s%s%s (enter to select)" % (utils.term.bold, question, utils.term.normal),
choices=list(display_instances.keys()),
)
questions.append(question)
answers = None
try:
answers = inquirer.prompt(questions, theme=THEMER, raise_keyboard_interrupt=True)
except KeyboardInterrupt:
logger.error("Cancelled by user")
sys.exit(1)
if 'all' in answers["instance"]:
selected_hosts = instances
else:
selected_hosts = []
if not multiple:
answers["instance"] = [answers["instance"]]
for answer in answers["instance"]:
selected_hosts.append(display_instances[answer])
return selected_hosts