summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2013-10-23 16:50:19 (EDT)
committer P. J. McDermott <pjm@nac.net>2013-10-23 16:50:19 (EDT)
commit304a658035718765ba9a5b7a7df22223fb5631c9 (patch)
tree999d8eb7c2ffd320f23581957376c31e98da9d91
parent9794ee38738c156d28c78f208d19273bdd3f027a (diff)
prokit: Parse options.
-rw-r--r--src/prokit.sh18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/prokit.sh b/src/prokit.sh
index eec634a..41b250a 100644
--- a/src/prokit.sh
+++ b/src/prokit.sh
@@ -26,6 +26,7 @@ PACKAGE_NAME='@PACKAGE_NAME@'
PACKAGE_VERSION='@PACKAGE_VERSION@'
PKGDATADIR='@pkgdatadir@'
PKGDATACMDDIR='@pkgdatacmddir@'
+OPTSTRING='hV'
# Global variables
loading_cmd=
@@ -66,6 +67,7 @@ use()
use locale
use cmd
+use getopt
main()
{
@@ -74,8 +76,20 @@ main()
load_locale
load_cmds
- cmd="${1}"
- shift
+ get_options "${OPTSTRING}" 'opt_' "${@}"
+ shift $(($OPTIND - 1))
+
+ if ${opt_h:-false}; then
+ cmd='help'
+ elif ${opt_V:-false}; then
+ cmd='version'
+ elif [ ${#} -lt 1 ]; then
+ cmd_help_main >&2
+ exit 1
+ else
+ cmd="${1}"
+ shift
+ fi
run_cmd "${cmd}" "${@}"