#!/bin/bash

# Function to run the built binary for the local architecture
run_binary() {
    os=$(uname -s | tr '[:upper:]' '[:lower:]')
    arch=$(uname -m)

    case $arch in
        x86_64) arch="amd64" ;;
        arm64) arch="arm64" ;; # Handle M1 Mac correctly
        armv7l) arch="arm/v7" ;;
        *) echo "Unsupported architecture: $arch"; exit 1 ;;
    esac

    output_name="sitemapper"
    if [[ "$os/$arch" != "linux/amd64" ]]; then
        output_name="${output_name}_${os}_${arch}"
    fi

    output_name="dist/${output_name}"
    if [ -f "${output_name}" ]; then
        echo "Running ${output_name} $@"
        ./${output_name} "$@"
    else
        echo "Binary for ${os}/${arch} not found. Please check the build logs."
    fi
}

# Check if arguments are provided
if [ $# -eq 0 ]; then
    echo "Usage: $0 [arguments for the binary]"
    exit 1
fi

run_binary "$@"

