#!/bin/bash

# Parse options FIRST
echo "DEBUG: Arguments received: $@"
echo "DEBUG: Number of arguments: $#"

while [[ $# -gt 0 ]]; do
    echo "DEBUG: Processing argument: $1"
    case "$1" in
        --non-interactive)
            export NON_INTERACTIVE="true"
            echo "DEBUG: NON_INTERACTIVE set to $NON_INTERACTIVE"
            shift
            ;;
        --debug)
            export CONFIG_DEBUG="true"
            echo "DEBUG: CONFIG_DEBUG set to $CONFIG_DEBUG"
            shift
            ;;
        -*)
            echo "Unknown option: $1"
            exit 1
            ;;
        *)
            # This is the command - stop parsing options
            echo "DEBUG: Found command argument: $1, breaking"
            break
            ;;
    esac
done

# NOW set the command after options are parsed
local_command="${1:-setup}"
echo "DEBUG: Command is: $local_command"
echo "DEBUG: NON_INTERACTIVE is: ${NON_INTERACTIVE:-unset}"
echo "DEBUG: CONFIG_DEBUG is: ${CONFIG_DEBUG:-unset}"

# Test the conditional logic
if [[ "$NON_INTERACTIVE" != "true" ]]; then
    echo "WOULD SHOW: Interactive banner and prompt"
else
    echo "WOULD SKIP: Interactive banner and prompt (non-interactive mode)"
fi