本文整理匯總了Python中click.BOOL屬性的典型用法代碼示例。如果您正苦於以下問題:Python click.BOOL屬性的具體用法?Python click.BOOL怎麽用?Python click.BOOL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類click
的用法示例。
在下文中一共展示了click.BOOL屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: convert
# 需要導入模塊: import click [as 別名]
# 或者: from click import BOOL [as 別名]
def convert(self, value, param, ctx):
assert param.nargs == 2
if self.current_key is None:
if value not in SETTINGS:
self.fail('Unknown setting %s' % value)
self.current_key = value
return value
assert self.current_key in SETTINGS
setting = SETTINGS[self.current_key]
self.current_key = None
if setting.type is bool:
return click.BOOL(value)
return setting.type(value)
示例2: params_factory
# 需要導入模塊: import click [as 別名]
# 或者: from click import BOOL [as 別名]
def params_factory(schema: dict, add_message: bool) -> list:
"""
Generates list of :class:`click.Option` based on a JSON schema
:param schema: JSON schema to operate on
:return: Lists of created :class:`click.Option` object to be added to a :class:`click.Command`
"""
# Immediately create message as an argument
params = []
if add_message:
params.append(click.Argument(["message"], required=False))
for property, prpty_schema in schema.items():
multiple = False
choices = None
if any(char in property for char in ["@"]):
continue
if prpty_schema.get("type") in COMPLEX_TYPES:
continue
if prpty_schema.get("duplicate"):
continue
if property == "message":
continue
elif not prpty_schema.get("oneOf"):
click_type, description, choices = json_schema_to_click_type(prpty_schema)
else:
click_type, multiple, description = handle_oneof(prpty_schema["oneOf"])
# Not all oneOf schema can be handled by click
if not click_type:
continue
# Convert bool values into flags
if click_type == click.BOOL:
param_decls = [get_flag_param_decals_from_bool(property)]
click_type = None
else:
param_decls = [get_param_decals_from_name(property)]
if description:
description = description.capitalize()
if multiple:
if not description.endswith("."):
description += "."
description += " Multiple usages of this option are allowed"
# Construct the base command options
option = partial(
click.Option, param_decls=param_decls, help=description, multiple=multiple
)
if choices:
option = option(type=choices)
elif click_type:
option = option(type=click_type)
else:
option = option()
params.append(option)
return params