mirror of
https://github.com/notwa/rc
synced 2025-02-05 15:43:22 -08:00
tweak exit codes of argc
This commit is contained in:
parent
1b0ac32463
commit
195ed1f046
1 changed files with 5 additions and 5 deletions
10
sh/argc
10
sh/argc
|
@ -22,7 +22,7 @@ argc() { ### @- validate the number of arguments in a function.
|
||||||
# note that $zero can be empty, but must be set.
|
# note that $zero can be empty, but must be set.
|
||||||
if [ $# -ne 4 ] || [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
|
if [ $# -ne 4 ] || [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
|
||||||
printf "$usage" argc >&2
|
printf "$usage" argc >&2
|
||||||
return 2
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local argc="$1"; shift
|
local argc="$1"; shift
|
||||||
|
@ -34,7 +34,7 @@ argc() { ### @- validate the number of arguments in a function.
|
||||||
|
|
||||||
if [ "$argc" != "${argc%%[!0-9]*}" ]; then
|
if [ "$argc" != "${argc%%[!0-9]*}" ]; then
|
||||||
printf "$usage" argc >&2
|
printf "$usage" argc >&2
|
||||||
return 2
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$cond" in
|
case "$cond" in
|
||||||
|
@ -43,14 +43,14 @@ argc() { ### @- validate the number of arguments in a function.
|
||||||
('-ge') many='at least';;
|
('-ge') many='at least';;
|
||||||
(*)
|
(*)
|
||||||
printf "$usage" argc >&2
|
printf "$usage" argc >&2
|
||||||
return 2;;
|
return 1;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$want" in
|
case "$want" in
|
||||||
([0-9]) :;; # no error, continue.
|
([0-9]) :;; # no error, continue.
|
||||||
(*)
|
(*)
|
||||||
printf "$usage" argc >&2
|
printf "$usage" argc >&2
|
||||||
return 2;;
|
return 1;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ "$argc" "$cond" "$want" ] 2>/dev/null; then
|
if [ "$argc" "$cond" "$want" ] 2>/dev/null; then
|
||||||
|
@ -58,7 +58,7 @@ argc() { ### @- validate the number of arguments in a function.
|
||||||
else
|
else
|
||||||
local err="expected $many $want argument$plural, got"
|
local err="expected $many $want argument$plural, got"
|
||||||
printf '%s: %s %s\n' "$zero" "$err" "$argc" >&2
|
printf '%s: %s %s\n' "$zero" "$err" "$argc" >&2
|
||||||
return 1
|
return 64
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue