#!/bin/sh

dryrun=
verbose=
msg=hello

while getopts hM:nv myflag ; do
  case "$myflag" in
    h)
      cat <<EOF
Usage summary:
$0 -h
$0 [-M MSG] [-n] [-v] FILENAME...
Default MSG is $msg
EOF
      exit 0
      ;;
    n)
      dryrun=y
      ;;
    v)
      verbose=y
      ;;
    M)
      msg=$OPTARG
      ;;
    ?)
      echo "For usage summary, please run: $0 -h" >&2
      exit 1
      ;;
  esac
done

# Now can get rid of options.
shift $((OPTIND - 1))
# Now $@ has just the filenames.

for f in "$@" ; do
  case "$f" in
    *.py)
      if [ -n "$verbose" ]; then
        echo "deleting $f" 
      fi
      if [ -z "$dryrun" ]; then
        rm "$f"
      fi
      ;;
    *)
      [ -z "$verbose" ] || echo "not deleting $f"
      echo "$msg $f"
      ;;
  esac
done
