print usage after argparse error

This commit is contained in:
Denis Lehmann 2022-04-02 19:12:33 +02:00
parent c3e2fc0850
commit 526aeeebfc
2 changed files with 15 additions and 15 deletions

File diff suppressed because one or more lines are too long

24
sf
View file

@ -20,16 +20,6 @@ sftm=$'\e[35m'
sftc=$'\e[36m'
sftw=$'\e[97m'
# Public output functions
function sferr {
echo "${sftbf}${sftr}ERROR${sftrs} $1"
[ -z "$2" ] && exit 1
}
function sfwarn {
echo "${sftbf}${sfty}WARNING${sftrs} $1"
}
# Public input functions
function sfask {
if [ -n "$2" ]; then
@ -242,13 +232,22 @@ function _sfusage {
if [ -n "${sfextra}" ]; then
echo -e "\n$sfextra"
fi
exit 0
}
# Public output functions
function sferr {
echo "${sftbf}${sftr}ERROR${sftrs} $1"
[ -z "$2" ] && _sfusage && exit 1
}
function sfwarn {
echo "${sftbf}${sfty}WARNING${sftrs} $1"
}
# Check for help flag
for a in "$@"; do
# Check if help flag ist set
[ "$a" == "-h" ] || [ "$a" == "--help" ] && _sfusage
[ "$a" == "-h" ] || [ "$a" == "--help" ] && _sfusage && exit 0
done
# Check if dependencies are available
@ -307,6 +306,7 @@ if [ "${#_sfpargs[@]}" -gt 0 ]; then
for p in "${_sfpargs[@]}"; do
sferr "Positional argument ${sftbf}${p}${sftrs} missing" 0
done
_sfusage
exit 1
fi