#!/usr/bin/env bash

usage() {
  # shellcheck disable=SC2312
  printf '%s\n' "$(sed '0,/^:<<.__USAGE__.$/d' "$0")"
}

usage

: <<'__USAGE__'
NAME

    foo - script/command/function that does something

SYNOPSIS

    foo [-1|--option1] [ -2|--option2 optionarg ] arg1 [arg2 ...] \
        [fee] [dfsdfs] [sfsdfsf]

DESCRIPTION

    Describe in general terms what foo does.

ARGUMENTS

    arg
        Describe what arg does, should be, etc. Add a new line for each distinct arg.

OPTIONS

    -1|--option1
        Describe what --option1 does.

    -2|--option2
        Describe what --option2 does. Describe what optionarg does.

        * A choice for optionarg

        * Another choice for optionarg

__USAGE__

while [ "$#" -gt 0 ]; do
  case "$1" in
    -h | --help)
      usage
      exit 0
      ;;
    -1 | --option1)
      optionarg="$1"
      # shift past argument and value
      shift
      shift
      ;;
    -2 | --option2)
      optionarg="$2"
      # shift past argument and value
      shift
      shift
      ;;
    *)
      # unknown option
      usage
      exit 1
      ;;
  esac
done
