#!/bin/bash

# Parse arguments
ROOT_PATH=""
PATCHES_SOURCE=""

while [[ "$#" -gt 0 ]]; do
    case $1 in
        --path)
            ROOT_PATH="$2"
            shift
            ;;
        --patches)
            PATCHES_SOURCE="$2"
            shift
            ;;
        *)
            echo "Unknown parameter: $1"
            echo "Usage: $0 --path <path-to-apply> --patches <patches-directory>"
            exit 1
            ;;
    esac
    shift
done

# Validate arguments
if [[ -z "$ROOT_PATH" ]] || [[ -z "$PATCHES_SOURCE" ]]; then
    echo "Both --path and --patches arguments are required."
    echo "Usage: $0 --path <path-to-apply> --patches <patches-directory>"
    exit 1
fi

# Log paths for debugging
echo "Root path: $ROOT_PATH"
echo "Patches source: $PATCHES_SOURCE"

# Verify the patches directory exists
if [[ ! -d "$PATCHES_SOURCE" ]]; then
    echo "Failed to access patches source: $PATCHES_SOURCE does not exist."
    exit 1
fi

# Run the Go application with the specified path and patches
go run main.go pref.go standard.go new.go copy.go --path "$ROOT_PATH" --patches "$PATCHES_SOURCE"

# Exit with the status of the last command
exit $?

