usage: take exit code as param

thus it can correctly indicate success/fail status instead of always
indicating failure. when a user asks for usage with -u|--usage then we
should exit in success mode rather than failure as when usage in printed
in response to incorrect usage.

Gbp-Dch: Short
This commit is contained in:
Lyndon Brown 2020-03-30 17:32:07 +01:00 committed by Raphaël Hertzog
parent 6b7c8ed4bf
commit b3bba232ac
18 changed files with 25 additions and 22 deletions

View File

@ -25,7 +25,7 @@ Arguments frontend "${@}"
eval set -- "${REMAINING_ARGS}" eval set -- "${REMAINING_ARGS}"
if [ -z "${1}" ]; then if [ -z "${1}" ]; then
Usage Usage 1
fi fi
COMMAND="${1}" COMMAND="${1}"

View File

@ -127,7 +127,7 @@ Arguments ()
fi fi
exit 0 exit 0
elif [ "${IS_FRONTEND}" = "true" ]; then elif [ "${IS_FRONTEND}" = "true" ]; then
Usage Usage 0
fi fi
;; ;;
@ -137,7 +137,7 @@ Arguments ()
;; ;;
-u|--usage) -u|--usage)
Usage Usage 0
shift shift
;; ;;

View File

@ -11,6 +11,10 @@
Usage () Usage ()
{ {
if [ -z "${1}" ]; then
Echo_error "Usage() requires an exit code"
fi
echo "${PROGRAM_NAME} - ${DESCRIPTION}" echo "${PROGRAM_NAME} - ${DESCRIPTION}"
printf "\nUsage:\n\n" printf "\nUsage:\n\n"
@ -25,5 +29,5 @@ Usage ()
echo echo
echo "Try \"${PROGRAM} --help\" for more information." echo "Try \"${PROGRAM} --help\" for more information."
exit 1 exit $1
} }

View File

@ -217,6 +217,6 @@ case "${1}" in
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -23,7 +23,7 @@ _ACTION="${2}"
shift 2 shift 2
if ! In_list "${_PASS}" "binary" "chroot" "source"; then if ! In_list "${_PASS}" "binary" "chroot" "source"; then
Usage Usage 1
fi fi
# Processing arguments and configuration files # Processing arguments and configuration files
@ -441,6 +441,6 @@ case "${_ACTION}" in
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -67,6 +67,6 @@ case "${1}" in
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -63,6 +63,6 @@ case "${1}" in
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -84,6 +84,6 @@ EOF
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -77,6 +77,6 @@ EOF
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -83,6 +83,6 @@ EOF
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -67,6 +67,6 @@ case "${1}" in
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -95,6 +95,6 @@ case "${1}" in
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -64,6 +64,6 @@ case "${1}" in
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -61,6 +61,6 @@ case "${1}" in
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -73,6 +73,6 @@ EOF
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -66,6 +66,6 @@ case "${1}" in
;; ;;
*) *)
Usage Usage 1
;; ;;
esac esac

View File

@ -144,7 +144,7 @@ do
;; ;;
-u|--usage) -u|--usage)
Usage Usage 0
;; ;;
-v|--version) -v|--version)
@ -153,8 +153,7 @@ do
;; ;;
*) *)
Usage Usage 1
exit 1
;; ;;
esac esac
done done

View File

@ -294,7 +294,7 @@ Local_arguments ()
;; ;;
-u|--usage) -u|--usage)
Usage Usage 0
shift shift
;; ;;