#!/bin/bash

# SPDX-FileCopyrightText: 2026 Contributors to brew-proxy <https://codeberg.org/HastD/brew-proxy>
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

set -euo pipefail

cmd="$1"
shift

while (( "$#" > 0)); do
    case "$1" in
        --status=*)
            status=$(( "${1#--status=}" ))
            shift
            ;;
        --delay=*)
            delay="${1#--delay=}"
            shift
            ;;
        *) break ;;
    esac
done

if [[ -n "${delay-}" ]]; then
    sleep "${delay}"
fi

echo "mock command: brew ${cmd}" "$@"

read -r -t 0.2 stdin || true
if [[ -n "${stdin-}" ]]; then
    echo "stdin: ${stdin}"
fi

exit "${status-0}"
