#!/bin/sh

# exit gracefully if not bash
if test -z "$BASH_VERSION"; then exit 0; fi

shopt -s extglob # enable pattern matching for 'case'

DOCFILE=docs/wget2.md
if [ -n "$1" ]; then
  DOCFILE="$1"
fi

WGET2=src/wget2
if [ -n "$2" ]; then
  WGET2="$2"
fi

err=0

# won't process these options
excludes="+(--no-quiet|--html-extension)"

for opt in `$WGET2 --help|egrep -o -- '--[a-zA-Z0-9-]+'|sort -u`; do
  # skip if in $excludes
  case $opt in $excludes) continue;; esac

  if ! egrep -q -- " \`$opt(=|\`|\[)" $DOCFILE; then
    # search for the --no- variant
    noopt="--no-`echo $opt|cut -c3-`"
    if ! egrep -q -- " \`$noopt\`" $DOCFILE; then
      echo "Failed to find \`$opt in $DOCFILE"
      err=1
    fi
  fi
done

exit $err
