Example #1
0
def convert_flip(ctx, param, value):
    if value is None:
        return
    value = value.lower()
    if value in ('lr', 'leftright'):
        return (Image.FLIP_LEFT_RIGHT, 'left to right')
    if value in ('tb', 'topbottom', 'upsidedown', 'ud'):
        return (Image.FLIP_LEFT_RIGHT, 'top to bottom')
    raise click.BadParameter('invalid flip "%s"' % value)
Example #2
0
def convert_rotation(ctx, param, value):
    if value is None:
        return
    value = value.lower()
    if value in ('90', 'r', 'right'):
        return (Image.ROTATE_90, 90)
    if value in ('180', '-180'):
        return (Image.ROTATE_180, 180)
    if value in ('-90', '270', 'l', 'left'):
        return (Image.ROTATE_270, 270)
    raise click.BadParameter('invalid rotation "%s"' % value)
Example #3
0
def cli(count, foo, url):
    """Validation.

    This example validates parameters in different ways.  It does it
    through callbacks, through a custom type as well as by validating
    manually in the function.
    """
    if foo is not None and foo != 'wat':
        raise click.BadParameter(
            'If a value is provided it needs to be the '
            'value "wat".',
            param_hint=['--foo'])
    click.echo('count: %s' % count)
    click.echo('foo: %s' % foo)
    click.echo('url: %s' % repr(url))
Example #4
0
 def validate_pos_int(ctx, param, value):
     if value < 0:
         raise click.BadParameter('Value needs to be positive')
     return value
Example #5
0
def validate_count(ctx, param, value):
    if value < 0 or value % 2 != 0:
        raise click.BadParameter('Should be a positive, even integer.')
    return value