from typing import Union
import pathlib


def clean_mirror_path(mirror: str) -> Union[str, pathlib.Path]:
    """Convert the user input from command line to an acceptable format for the app.

    Note: If the user provided an URL, it will remove any trailing '/'.

    :param mirror: User input
    :return: Either a Path object or a string
    """
    # First, detect if the string is an url
    mirror_path: Union[str, pathlib.Path] = (
        pathlib.Path(mirror) if "http" not in mirror else mirror
    )

    # Remove trailing '/' if needed
    if isinstance(mirror_path, str) and mirror_path.endswith("/"):
        mirror_path = mirror_path[:-1]

    return mirror_path