#!/bin/sh

DOCKER_IMAGE=docker.io/semarchy/xdg-harvester:2024.2.0-ga

filtered_arguments=""
is_help_cmd=0
while [[ "$#" -gt 0 ]]; do
    case $1 in
        -e|--env-file) env_file="$2"; shift ;;
        --help) is_help_cmd=1; filtered_arguments="$filtered_arguments $1" ;;
        *) filtered_arguments="$filtered_arguments $1" ;;
    esac
    shift
done

if [ ! -z "$env_file" ]; then
  ENV_FILE_ARG="--env-file $env_file"
fi

docker run --rm \
    --pull=always \
    --network host \
    --workdir=/dir \
    --mount type=bind,source="$(pwd)",target=/dir \
    $ENV_FILE_ARG \
    $DOCKER_IMAGE \
    ingest $filtered_arguments

if [[ "$is_help_cmd" -gt 0 && $filtered_arguments == *" run "* ]]; then
  echo "  -e, --env-file FILE             Environment file to parameterize execution."
fi
