From 9635a87d9476f0a8e4a3050399724698bb831c02 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 27 Oct 2015 12:42:41 -0400 Subject: src/main.sh: Add option parsing --- (limited to 'src') diff --git a/src/main.sh b/src/main.sh index 35156b3..c62262e 100644 --- a/src/main.sh +++ b/src/main.sh @@ -15,8 +15,63 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +usage() +{ + printf 'Usage: %s [option ...]\n' "${0}" +} + +help() +{ + usage + cat <. +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +EOF +} + main() { - init_ui 'cli' + local opt= + local ui='cli' + + unset OPTARG + while getopts 'hVi:' opt; do + case "${opt}" in + 'h') + help + exit + ;; + 'V') + version + exit + ;; + 'i') + ui="${OPTARG}" + ;; + esac + unset OPTARG + done + shift $(($OPTIND - 1)) + + if [ ${#} -ne 0 ]; then + usage >&2 + exit 1 + fi + + init_ui "${ui}" info 'Hello, world!' } -- cgit v0.9.1