summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. J. McDermott <pj@pehjota.net>2015-10-27 12:42:41 (EDT)
committer P. J. McDermott <pj@pehjota.net>2015-10-27 12:42:41 (EDT)
commit9635a87d9476f0a8e4a3050399724698bb831c02 (patch)
treee0dfa3473ca3200ca992794c6c6ae300d1442813
parent16ef03adae1c34b5beaad300274bfa39408d0721 (diff)
downloadfirman.sh-9635a87d9476f0a8e4a3050399724698bb831c02.zip
firman.sh-9635a87d9476f0a8e4a3050399724698bb831c02.tar.gz
firman.sh-9635a87d9476f0a8e4a3050399724698bb831c02.tar.bz2
src/main.sh: Add option parsing
-rw-r--r--src/main.sh57
1 files changed, 56 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>.
+usage()
+{
+ printf 'Usage: %s [option ...]\n' "${0}"
+}
+
+help()
+{
+ usage
+ cat <<EOF
+Options:
+ -h Display this information
+ -V Display version information
+ -i {cli|tui} Select either a textual user interface or a command line
+ interface (default: cli)
+EOF
+}
+
+version()
+{
+ cat <<EOF
+firman ${PACKAGE_VERSION}
+Copyright (C) 2015 Patrick "P. J." McDermott
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
+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!'
}