usage() {
  cat <<EOS
  $(basename "$0")
    a simple script/command/function that does something

  usage: [NONINTERACTIVE=1] [CI=1] install.sh [options]

  commands:
    [h]elp        - Display this message.
    [l]ist        - List all entries.
    [s]how [name] - Show password for an entry.

  flags:
    -h, --help    - Display this message.
EOS
}

# string formatters
if [ -t 1 ]; then
  tty_escape() { printf "\033[%sm" "$1"; }
else
  tty_escape() { :; }
fi
tty_mkbold() { tty_escape "1;$1"; }
tty_red="$(tty_mkbold 31)"
tty_reset="$(tty_escape 0)"

chomp() {
  # printf '%s' "${1/"$'\n'"/}"
  printf '%s' "$1" | sed -e "s/'/'\\\\''/g"
}

warn() {
  # shellcheck disable=SC2312
  printf "${tty_red}Warning${tty_reset}: %s\n" "$(chomp "$1")" >&2
}

if [ "$#" -eq 0 ]; then
  usage
  exit 1
fi

while [ "$#" -gt 0 ]; do
  case "$1" in
    -h | --help)
      usage
      exit 0
      ;;
    *)
      warn "Unrecognized option: '$1'"
      usage
      exit 1
      ;;
  esac
done
