"""Provisioning command execution."""

from __future__ import annotations

import shlex

from .config import JailConfig
from .runner import run


def run_provision(jail: JailConfig, *, log_file: str | None = None) -> int:
    """Run the provisioning command inside the jail."""
    cmd = ["jexec", jail.name] + shlex.split(jail.cmds["provision"])
    result = run(cmd, env=jail.env, log_file=log_file)
    return result.returncode
