#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )"
CP="$DIR/lib/*"

if [ -z "$1" ]; then
    echo "=============================================="
    echo "   BahasaLang Compiler & Runtime v1.0.0"
    echo "=============================================="
    echo "Penggunaan:"
    echo "  bahasa compile <fail.bah>   (Kompilasi ke bytecode .class)"
    echo "  bahasa run <NamaProgram>    (Laksanakan program yang dikompilasi)"
    echo "  bahasa --version            (Papar versi kompiler)"
    echo ""
    echo "Contoh:"
    echo "  ./bin/bahasa compile examples/helo.bah"
    echo "  ./bin/bahasa run Helo"
    echo "=============================================="
    exit 1
fi

if [ "$1" == "run" ]; then
    shift
    java -cp ".:$CP" "$@"
    exit $?
fi

if [ "$1" == "compile" ]; then
    shift
    java -cp "$CP" com.bahasalang.cli.CompilerCLIKt compile "$@"
    exit $?
fi

java -cp "$CP" com.bahasalang.cli.CompilerCLIKt "$@"
