summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-10-23 21:22:26 (EDT)
committer P. J. McDermott <pjm@nac.net>2013-10-23 21:22:26 (EDT)
commitad0571b72af86980a42cafdc005f064243b2fe1e (patch)
tree58e0f10df9f744f44a0f45c80da5e3e95cdba545
parent09a410df8490dce69996ef4555e4658dd4721cb4 (diff)
get_options(): Determine optstring and prefix.
-rw-r--r--lib/getopt.sh13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/getopt.sh b/lib/getopt.sh
index 9292af2..537892b 100644
--- a/lib/getopt.sh
+++ b/lib/getopt.sh
@@ -22,11 +22,18 @@ _GETOPT_SM=1
get_options()
{
- local optstring="${1}"
- local prefix="${2}"
- shift 2
+ local optstring=
+ local prefix=
local opt=
+ if [ "x${running_cmd}" = 'x' ]; then
+ optstring="${OPTSTRING}"
+ prefix='opt_'
+ else
+ eval "optstring=\"\${cmd_${running_cmd}_optstring}\""
+ prefix="cmd_${running_cmd}_opt_"
+ fi
+
unset OPTARG
while getopts "${optstring}" opt; do
eval "${prefix}${opt}=\"\${OPTARG:-true}\""