From: Alex Dehnert Date: Sat, 15 Dec 2012 11:51:05 +0000 (-0500) Subject: sshroot: handle unknown args correctly X-Git-Url: https://www.dehnerts.com/gitweb/?p=user%2Falex%2Fsoftware%2Fmy-snippets.git;a=commitdiff_plain;h=f4b8c66b46165fb7c4a5c4cc8ae1b331febc3934 sshroot: handle unknown args correctly --- diff --git a/sshroot b/sshroot index f4d8996..845a04a 100755 --- a/sshroot +++ b/sshroot @@ -8,12 +8,26 @@ hostopt="" [ -z "$hostopt" ] && hostopt="${HOSTNAME}" [ -z "$hostopt" ] && hostopt=`uname -n 2>/dev/null || echo unknown` -while getopts "H:k:l:" opt; do +function usage +{ + echo "Usage: $0 [-H hostname] [-k keysuffix] [-l lifetime] command" + echo + echo "Available commands:" + echo " add" + echo " list" + echo " destroy" + echo " shell" + echo " ssh [args]" + echo " [cmd]" +} + +while getopts ":H:k:l:h" opt; do case "$opt" in H) hostopt="$OPTARG";; k) keysuffix="$OPTARG";; l) lifetime="$OPTARG";; - \?) die "$0 [-H hostname] [-k keysuffix] [-l lifetime]" + h) usage; exit 0;; + \?) usage >&2; exit 1;; esac done shift $(($OPTIND - 1)) @@ -65,13 +79,7 @@ case "$command" in ;; *) if [ -z "$command" ]; then - echo "Usage: $0 init" >&2 - echo " $0 add" >&2 - echo " $0 list" >&2 - echo " $0 destroy" >&2 - echo " $0 shell" >&2 - echo " $0 ssh [args]" >&2 - echo " $0 [cmd]" >&2 + usage >&2 else echo Executing: "$command" "$@" with-agent "$command" "$@"