#!/usr/bin/env bash

# PHARO_VM=${PHARO_VM:-./pharo}
# PILLAR_IMAGE=${PILLAR_IMAGE:-./Pharo.image}

PHARO_VM=${PHARO_VM}
# ./pharo has a higher priority than PHARO_VM env if it exists
if [ -f pharo ]; then
	PHARO_VM="./pharo"
fi

PILLAR_IMAGE=${PILLAR_IMAGE}
# Pharo.image has a higher priority than PILLAR_IMAGE env if it exists
if [ -f Pharo.image ]; then
	PILLAR_IMAGE="./Pharo.image"
fi

command=$1
shift

# disable parameter expansion to forward all arguments unprocessed to the VM
set -f

# TODO: when Pharo knows how to return the correct "current working directory", we
# can remove the --baseDirectory from here. The current solution is
# problematic because it overrides any baseDirectory parameter of the
# pillar.conf file.
exec "$PHARO_VM" "$PILLAR_IMAGE" --no-default-preferences pillar "$command" --baseDirectory="$PWD" "$@"
