#!/bin/sh
set -e

echo "=========================================="
echo "Testing wmbusmeters help output..."
echo "=========================================="

# Capture help output
HELP_OUTPUT=$(wmbusmeters --help 2>&1)

echo ""
echo "Displaying help output:"
echo "----------------------------------------"
echo "$HELP_OUTPUT"
echo "----------------------------------------"
echo ""

# Check for expected keywords in help output
echo "Verifying help output contains expected keywords..."

check_keyword() {
    keyword="$1"
    if echo "$HELP_OUTPUT" | grep -qi "$keyword"; then
        echo "  ✓ Found: $keyword"
        return 0
    else
        echo "  ✗ Missing: $keyword"
        return 1
    fi
}

FAILED=0

# Check for common expected terms
check_keyword "wmbusmeters" || FAILED=1
check_keyword "usage\|Usage\|USAGE" || FAILED=1
check_keyword "option\|Option\|OPTIONS" || FAILED=1
check_keyword "meter\|Meter\|METER" || FAILED=1

echo ""
if [ $FAILED -eq 0 ]; then
    echo "=========================================="
    echo "OK: All help output checks passed"
    echo "=========================================="
else
    echo "=========================================="
    echo "ERROR: Some help output checks failed"
    echo "=========================================="
    exit 1
fi
