import click


def validate_umask(ctx, param, value):
    # pylint: disable=unused-argument
    """Validate a umask setting"""
    try:
        umaskint = int(value, base=8)
        if umaskint < 0:
            raise click.BadParameter(
                "%s is smaller than the minimum valid value 0" % value
            )
        if umaskint > 0o777:
            raise click.BadParameter(
                "%s is larger than the maximum valid value 0777" % value
            )

        return umaskint
    except ValueError:
        # pylint: disable=raise-missing-from
        raise click.BadParameter("%s is not a valid octal value" % value)