#!/bin/bash

PARSE_PARSER=${PARSE_PARSER:=$PARSER}

# Create a parser program
parser=$({
  $PARSER new $0 -d "argparsh example" -e "bye!"
  $PARSER add_arg \
    --choice a --choice b --choice c \
    --helptext "single letter arg" \
    -- "a"
  $PARSER add_arg --type int --default 10 -- "-i" "--interval"
  $PARSER add_arg --action store_true -- "-f"

  $PARSER add_subparser foobar --required
  $PARSER add_subcommand foo
  $PARSER add_subcommand bar

  $PARSER add_arg --subcommand foo "qux"
  $PARSER add_arg --subcommand bar "baz"
})

# Parse cli arguments as shell variables prefixg ed with "arg_"
#   cli arguments can be placed in the environment with "-e" or "--export"
#   cli arguments can be declared as local with "-l" or "--local"
eval $($PARSER parse $parser -p "arg_" -- "$@")

echo "Parsed args as shell variables"
