From 4ccf85bed5a7c35e0c7e18e10a95445f961333fe Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Mon, 20 Apr 2020 04:54:29 +0800 Subject: [PATCH] Add help dialog --- comfortable-swipe | 81 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 4 deletions(-) diff --git a/comfortable-swipe b/comfortable-swipe index 222881d..d42c72c 100755 --- a/comfortable-swipe +++ b/comfortable-swipe @@ -1,9 +1,55 @@ #!/bin/bash ## Comfortable Swipe (comfortable-swipe) +basename="$(basename "$0")" +version="$(cat VERSION)" # this will be hardcoded upon install + # turn on errors per line set -e +usage= + + +# show help +function help { +cat < [] + + -h, --help show this help text + -v, --version print the program version + +Commands: + start + starts 3/4-finger gesture service + + stop + stops 3/4-finger gesture service + + restart + restarts 3/4-finger gesture service + + autostart [on|off|toggle|status|path] + toggle to automatically run on startup automatically run on startup (toggleable) + + buffer + parses output of libinput debug-events + + help + shows the help dialog + + config + shows the location of the config file + + debug + logs raw output from input events taken from libinput + + status + checks status of program and autostart + +Report bugs to https://github.com/Hikari9/comfortable-swipe/issues/new +EOF +} + # start comfortable-swipe # internally pipes debug text to the buffer @@ -124,11 +170,38 @@ function status { } -# make sure we actually pass a valid function name -if declare -f "$1" >/dev/null 2>&1; then - # invoke that function, passing arguments through +#################### +# COMMAND OPTIONS # +#################### +for i in "$@"; do +case $i in + -h | --help) # eagerly show help + help + exit 0 + ;; + -v | --version) # eagerly print version + echo "$version" + exit 0 + ;; + *) # unknown option + echo "Unknown option: $i" >&2 + exit 1 + ;; +esac +done + +############ +# DISPATCH # +############ + +if [[ $# -eq 0 ]]; then + # no options; just show help + help +elif declare -f "$1" >/dev/null 2>&1; then + # invoke subcommand function, passing arguments through "$@" # same as "$1" "$2" "$3" ... for full argument list else - echo "Function $1 not recognized" >&2 + echo "error: function $1 not recognized" >&2 + echo "full usage: comfortable-swipe --help" >&2 exit 1 fi