#!/usr/bin/env bash

set -euo pipefail

source "$(cd "$(dirname "$0")" && pwd)/scripts/rho-common.sh"

rho_parse_extension_flags "$@"
set -- "${RHO_REMAINING_ARGS[@]}"

rho_require_user "${1:-}"
USER_NAME="$1"
shift

rho_prepare_user "$USER_NAME"
rho_prepare_pi_env

PI_ARGS=()

if (( ${#RHO_EXTENSION_ARGS[@]} > 0 )); then
  PI_ARGS+=("${RHO_EXTENSION_ARGS[@]}")
fi

PI_ARGS+=(
  --session "$RHO_SESSION_FILE"
)

if [[ $# -gt 0 ]]; then
  PI_ARGS+=("$@")
fi

rho_run_pi "${PI_ARGS[@]}"
