import click
from typing import Union
from typing import Optional
from pathlib import Path
import tempfile
import uuid


def get_workspace_dir(
    ctx: click.core.Context,
    param: Union[click.core.Option, click.core.Parameter],
    value: Optional[Path],
) -> Path:
    """
    Get a new workspace directory, within the given directory if one is given.
    """
    # We "use" variables to satisfy linting tools.
    for _ in (ctx, param):
        pass

    base_workspace_dir = value or Path(tempfile.gettempdir())
    workspace_dir = base_workspace_dir / uuid.uuid4().hex
    workspace_dir.mkdir(parents=True)
    return workspace_dir