from typing import Iterable


def override_option(ctx, param, value):
    """
    Use another click option as the default value.

    If `value` is None, remove the prefix from `param` and take the
    value from that option.

    Parameters
    ----------
    ctx : click.core.Context
        Click context to take value from.
    param : click.core.Option
        Name option to override
    value
        Value to potentially override.

    Returns
    -------
    value
        Final value of option.
    """
    if value is None or (isinstance(value, Iterable) and len(value) == 0):  # type: ignore # noqa: E501
        value = ctx.params['_'.join(param.name.split('_')[1:])]
    return value