diff options
-rwxr-xr-x | remembering | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/remembering b/remembering index b31924e..b6432ec 100755 --- a/remembering +++ b/remembering @@ -2,16 +2,33 @@ set -eu usage() { - printf 'Usage: %s: -p PROFILE -c "COMMAND"\n' "$0" >&2 + printf 'Usage: %s -p PROFILE -c "COMMAND"\n' "$0" +} + +help() { + echo ' +Options: + -p profile to be used for gathering and storing data + -c command to be run, reading from STDIN, writing to STDOUT + +See manpages for more information.' } missing() { printf 'Missing option: %s\n' "$1" >&2 } +for flag in $@; do + if [ "$flag" = '--help' ]; then + usage + help + exit 0 + fi +done + COMMANDFLAG= PROFILEFLAG= -while getopts 'c:p:' name; do +while getopts 'hc:p:' name; do case "$name" in c) COMMANDFLAG="$OPTARG" @@ -19,6 +36,11 @@ while getopts 'c:p:' name; do p) PROFILEFLAG="$OPTARG" ;; + h) + usage + help + exit 0 + ;; *) echo "Ignoring unrecognized flag '$name'" >&2 ;; @@ -27,13 +49,13 @@ done if [ -z "$COMMANDFLAG" ]; then missing '-c "COMMAND"' - usage + usage >&2 exit 2 fi if [ -z "$PROFILEFLAG" ]; then missing '-p PROFILE' - usage + usage >&2 exit 2 fi |