nk412/optparse — pull request #10 by K-Ko (2014-07-15 11:30:34+00:00)
Title: Add handling of "--"

* Add handling of "**--**" to split script arguments from not to parse arguments
* Add **-h** as also possible help request
* Mark args with **value=...** as flags
* Add optional **ARGUMENTS** variable for additional arguments for usage()

Test script:

#!/bin/bash
. optparse.bash
# Test is used as flag (0|1)
optparse.define short=t long=test desc='Test run' variable=TEST value=1 default=0
optparse.define short=n long=nice desc='Nice level' variable=NICE default=10
# additional arguments for usage()
ARGUMENTS="-- arg1 arg2 ..."
source $( optparse.build )
echo "Test: $TEST"
echo "Nice: $NICE"
echo "Remaining arguments: $@"

Results:

# ./t.sh -h
usage: ./t.sh [OPTIONS] -- arg1 arg2 ...

OPTIONS:

-t --test: Test run [flag]
-n --nice: Nice level [default:10]
-? -h --help: usage

# ./t.sh
Test: 0
Nice: 10
Remaining arguments:

# ./t.sh --test -n 5
Test: 1
Nice: 5
Remaining arguments:

# ./t.sh --test -n 5 a b c
Test: 1
Nice: 5
Remaining arguments: a b c

# ./t.sh --test -n 5 -- ~/script --with -x --arguments a b c
Test: 1
Nice: 5
Remaining arguments: /var/www/script --with -x --arguments a b c