commit 1c95e1fc2b9b8011c98a5370ad716fa030a0cdef parent b131e501e0f6ecb2914b3f82227f8ff88d6c0855 Author: Jacob R. Edwards <n/a> Date: Wed, 28 Dec 2022 16:42:12 -0800 Improve error reporting in buf script Show what caused usage to be displayed on an invalid command and show usage when no command is given. Diffstat:
| M | local/bin/bin/buf | | | 20 | ++++++++++++++------ |
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/local/bin/bin/buf b/local/bin/bin/buf @@ -86,8 +86,21 @@ default() cat "$config"/default summerize() awk 'NR>1{printf " [...]"; exit}{printf "%s", $0}END{printf "\n"}' +usage() { + echo "${1:+"error: $1 +"}"'usage: buf list [regex] + buf show [regex] + buf get [buf] + buf set [buf] + buf swap buf1 [buf2]' 1>&2 + exit 1 +} + set -eu +test $# -eq 0 && + usage 'No command' + mkdir -p "$bufs" com="$1" shift @@ -107,10 +120,5 @@ case "$#$com" in ([12]swap) swap "$1" "${2:-"$(default)"}" ;; (*) - echo 'usage: buf list [regex] - buf show [regex] - buf get [buf] - buf set [buf] - buf swap buf1 [buf2]' 1>&2 - exit 1 + usage "$com: Command not found" esac