summaryrefslogtreecommitdiffstats
path: root/src/main.sh
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-04-14 13:39:09 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-04-14 13:39:09 (EDT)
commitcc38daccc0e83bd521ce4b8eb68b1d7e6a9e822b (patch)
tree37805aa53653af0b384f2f6769e9863d7b8ccdff /src/main.sh
parente519f3bf4f9df459023ab72cce7289c998764dab (diff)
src/main.sh: Move init(), fini(), etc. below main()
Diffstat (limited to 'src/main.sh')
-rw-r--r--src/main.sh106
1 files changed, 53 insertions, 53 deletions
diff --git a/src/main.sh b/src/main.sh
index 3aa9e08..0c4ca77 100644
--- a/src/main.sh
+++ b/src/main.sh
@@ -41,6 +41,59 @@ conf_key=
lock=
exit_status=
+_get_options()
+{
+ local opt=
+
+ unset OPTARG
+ while getopts "${OPTSTRING}" opt; do
+ if [ "x${opt}" != 'x?' ]; then
+ eval "opt_${opt}=\"\${OPTARG:-true}\""
+ fi
+ unset OPTARG
+ done
+
+ return 0
+}
+
+main()
+{
+ local cmd=
+ local status=
+
+ if [ -f "$(dirname -- "${0}")/.builddirstamp" ]; then
+ in_place=true
+ builddir="$(dirname -- "${0}")"
+ else
+ in_place=false
+ builddir=''
+ fi
+
+ load_locale
+
+ _get_options "${@}"
+ shift $((${OPTIND} - 1))
+
+ base_dir="${opt_b:-.}"
+
+ 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 1
+ fi
+
+ run_cmd "${cmd}" "${@}"
+ status=${?}
+
+ return ${status}
+}
+
_lock()
{
mkdir -p -- "${base_dir}/.db"
@@ -89,21 +142,6 @@ _init_sigs()
done
}
-_get_options()
-{
- local opt=
-
- unset OPTARG
- while getopts "${OPTSTRING}" opt; do
- if [ "x${opt}" != 'x?' ]; then
- eval "opt_${opt}=\"\${OPTARG:-true}\""
- fi
- unset OPTARG
- done
-
- return 0
-}
-
_get_conf()
{
local old_dir=
@@ -153,41 +191,3 @@ fini()
collect_garbage
_unlock
}
-
-main()
-{
- local cmd=
- local status=
-
- if [ -f "$(dirname -- "${0}")/.builddirstamp" ]; then
- in_place=true
- builddir="$(dirname -- "${0}")"
- else
- in_place=false
- builddir=''
- fi
-
- load_locale
-
- _get_options "${@}"
- shift $((${OPTIND} - 1))
-
- base_dir="${opt_b:-.}"
-
- 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 1
- fi
-
- run_cmd "${cmd}" "${@}"
- status=${?}
-
- return ${status}
-}