from typing import Union
from typing import Sequence
import shlex


def prepare_shell_command(command: Union[str, Sequence[str]]) -> str:
    """Format command parts into one shell command"""
    if isinstance(command, str):
        return command
    # This means the whole command is already preformatted for us
    if len(command) == 1 and " " in command[0]:
        return command[0]

    return " ".join([shlex.quote(c) for c in command])