import textwrap


def _get_var_label(attrs: dict, var_name: str, max_line_length: int = 30):
    """ Get the label for the variable on the colorbar

    Args:
        attrs (dict):
            Variable aattribute dict
        var_name (str):
            Short name of variable
        max_line_length (int, optional):
            Max number of characters on each line of returned label.
            Defaults to 30.

    Returns:
        var_label (str)
            long_name [units], var_name [units] or var_name depending on attrs
    """
    if "long_name" in attrs:
        var_label = attrs["long_name"]
    else:
        var_label = var_name
    if "units" in attrs:
        var_label += f" [{attrs['units']}]"
    return "\n".join(textwrap.wrap(var_label, max_line_length))