From b0f64583bf02f84cadcfad9b610d9c02ec6c4ec2 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sun, 24 Jan 2021 02:17:48 -0300 Subject: Support -h and --help flags --- remembering | 30 ++++++++++++++++++++++++++---- 1 file 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 -- cgit v1.2.3