本文整理匯總了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