#!/bash/bash
# -*- shell-script -*-
# Copyright 2008-2009 Bob Hepple
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# http://sourceforge.net/projects/process-getopt
# http://process-getopt.sourceforge.net
# http://bhepple.freeshell.org/oddmuse/wiki.cgi/process-getopt

# $Id: tiny,v 1.2 2009/04/10 09:46:18 bhepple Exp $

# error on first failed command or unreferencing a undefined variable:
set -eu

PROG=$(basename $0)
VERSION='$Revision: 1.2 $'
USAGE="A tiny example using process-getopt(1)"

# call process-getopt functions to define some options:
source ./process-getopt

SLOT=""
SLOT_func()   { [ "${1:-""}" ] && SLOT="yes"; }      # callback for SLOT option
add_opt SLOT "boolean option" s "" slot

TOKEN=""
TOKEN_func()  { [ "${1:-""}" ] && TOKEN="$2"; }      # callback for TOKEN option
add_opt TOKEN "this option takes a value" t n token number

add_std_opts     # define the standard options --help etc:

# The next 4 lines call the callbacks and remove the options from the
# command line so all we need to deal with in the rest of our script
# is the arguments in $@

# Re-order options and call option callbacks:
TEMP=$(call_getopt "$@") || exit 1
eval set -- "$TEMP"

# remove the options from the command line
process_opts "$@" || shift "$?"

echo "SLOT=$SLOT"
echo "TOKEN=$TOKEN"
echo "args=$@"
