"""Shared input helpers for wiki CLI commands."""

from __future__ import annotations

import sys
from pathlib import Path

import click


def resolve_content(
    content: str | None,
    content_file: str | None,
) -> str | None:
    """Resolve --content / --content-file to a text string.

    Returns ``None`` when neither option was provided. Returns the resolved
    text otherwise. ``--content-file -`` reads stdin.
    """
    if content is not None and content_file is not None:
        raise click.ClickException(
            "--content and --content-file are mutually exclusive."
        )
    if content_file is not None:
        if content_file == "-":
            return sys.stdin.read()
        return Path(content_file).read_text()
    return content
