From 0c5e457a3bdcc4adde0364894ca35c9cf9b3f07f Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 2 Apr 2025 17:17:53 -0600 Subject: [PATCH] Fix help text. Add the -h|--help option. Fix a mistake with setting up the HEREDOC. Add an error message on stderr when the wrong number of arguments are detected, rather than just printing the help text. Print the help text when the wrong number of arguments are detected, rather than calling a non-existent function. Fix the help text to properly note grouped required options vs optional, and when optional arguments require prior optional arguments. --- git-identity | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/git-identity b/git-identity index 88901f1..4a8c88f 100755 --- a/git-identity +++ b/git-identity @@ -3,20 +3,22 @@ # TODO: Support non-stardard identity store # shellcheck disable=SC2034 -USAGE="$(cat <<'EOF' -[-d | --define] [] [] - or: git identity [--define-gpg] - or: git identity [--define-ssh] [] - or: git identity [-p | --print] [] - or: git identity [-s | --get-settings] - or: git identity [-r | --remove] - or: git identity [-l | --list] - or: git identity [-R | --list-raw] - or: git identity [-u | --update] - or: git identity [-c | --get-shell-command] [] [] +USAGE="$(cat < [ []] + or: git identity (-h | --help) + or: git identity --define-gpg + or: git identity --define-ssh [] + or: git identity (-p | --print) [] + or: git identity (-s | --get-settings] + or: git identity (-r | --remove) + or: git identity (-l | --list) + or: git identity (-R | --list-raw) + or: git identity (-u | --update) + or: git identity (-c | --get-shell-command) [ | ( | "") ...] or: git identity Specific git-identity actions: + -h, --help show this help message -d, --define define new identity and optionally specify ssh-file and gpg key --define-gpg add gpg signature to the identity --define-ssh add ssh key to an identity. If it does not have a path, assume '~/.ssh' @@ -323,14 +325,15 @@ IDENTITY="$1" check_arguments () { if [ "$1" -lt "$2" ]; then - usage + echo >&2 "ERROR: Wrong number of arguments" + echo "$USAGE" exit 1 fi } # For the some commands, it is ok not being in a git folder case $IDENTITY in - -l|--list|-R|--list-raw|-d|--define|--define-gpg|--define-ssh|-r|--remove|-p|--print|-c|--set-shell-command) + -l|--list|-R|--list-raw|-d|--define|--define-gpg|--define-ssh|-r|--remove|-p|--print|-c|--set-shell-command|-h|--help) # To prevent git-sh-setup to error out with 'fatal: not a git repository (or any of the parent directories): .git' NONGIT_OK=1 esac @@ -341,6 +344,11 @@ SUBDIRECTORY_OK=1 case $IDENTITY in "") print_current_identity ;; + -h|--help) + echo "$USAGE" + exit 0 + ;; + -d|--define) shift check_arguments $# 3