import re
import click


def validate_valid_duration(_ctx, _param, value: str) -> str:
    """Validate the validity period for a GPG key.

    The format for these values are listed in the command's help message.

    :param _ctx: The click context
    :param _param: The parameter that is being validated
    :param value: The value that was provided by the user
    :return: The user-supplied value, if it is valid
    """
    value = value.strip()
    match = re.search(r"\d+[wmy]?$", value)
    if match:
        return value

    raise click.BadParameter("must be in the format specified in the command's help message")