我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用click.ParamType()。
def init(): """patch click to support enhanced completion""" import click click.types.ParamType.complete = param_type_complete click.types.Choice.complete = choice_complete click.core.MultiCommand.get_command_short_help = multicommand_get_command_short_help click.core._bashcomplete = _shellcomplete
def __init__(self, name, repr, ast, default=NoDefault, description=None): import q2cli.util super().__init__(name, repr, ast, default=default, description=description) # TODO: just create custom click.ParamType to avoid this silliness if ast['type'] == 'collection': ast, = ast['fields'] self.type = q2cli.util.convert_primitive(ast)
def __init__(self): click.ParamType.__init__(self)
def convert(self, value, param, ctx): """ ParamType.convert() is the actual processing method that takes a provided parameter and parses it. """ # passthrough conditions: None or already processed if value is None or isinstance(value, tuple): return value # split the value on the first colon, leave the rest intact splitval = value.split(':', 1) # first element is the endpoint_id endpoint_id = click.UUID(splitval[0]) # get the second element, defaulting to `None` if there was no colon in # the original value try: path = splitval[1] except IndexError: path = None # coerce path="" to path=None # means that we treat "enpdoint_id" and "endpoint_id:" equivalently path = path or None if path is None and self.path_required: self.fail('The path component is required', param=param) return (endpoint_id, path)