From b3bba232ac6e1feff9e506506247aa20cd7f467c Mon Sep 17 00:00:00 2001 From: Lyndon Brown Date: Mon, 30 Mar 2020 17:32:07 +0100 Subject: [PATCH] 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 --- frontend/lb | 2 +- functions/arguments.sh | 4 ++-- functions/usage.sh | 6 +++++- scripts/build/chroot_apt | 2 +- scripts/build/chroot_archives | 4 ++-- scripts/build/chroot_debianchroot | 2 +- scripts/build/chroot_devpts | 2 +- scripts/build/chroot_dpkg | 2 +- scripts/build/chroot_hostname | 2 +- scripts/build/chroot_hosts | 2 +- scripts/build/chroot_proc | 2 +- scripts/build/chroot_resolv | 2 +- scripts/build/chroot_selinuxfs | 2 +- scripts/build/chroot_sysfs | 2 +- scripts/build/chroot_sysv-rc | 2 +- scripts/build/chroot_tmpfs | 2 +- scripts/build/clean | 5 ++--- scripts/build/config | 2 +- 18 files changed, 25 insertions(+), 22 deletions(-) diff --git a/frontend/lb b/frontend/lb index 1d8b89ab6..4f4aa2ead 100755 --- a/frontend/lb +++ b/frontend/lb @@ -25,7 +25,7 @@ Arguments frontend "${@}" eval set -- "${REMAINING_ARGS}" if [ -z "${1}" ]; then - Usage + Usage 1 fi COMMAND="${1}" diff --git a/functions/arguments.sh b/functions/arguments.sh index a8dd33251..2c1266f78 100755 --- a/functions/arguments.sh +++ b/functions/arguments.sh @@ -127,7 +127,7 @@ Arguments () fi exit 0 elif [ "${IS_FRONTEND}" = "true" ]; then - Usage + Usage 0 fi ;; @@ -137,7 +137,7 @@ Arguments () ;; -u|--usage) - Usage + Usage 0 shift ;; diff --git a/functions/usage.sh b/functions/usage.sh index 19a91c110..388763895 100755 --- a/functions/usage.sh +++ b/functions/usage.sh @@ -11,6 +11,10 @@ Usage () { + if [ -z "${1}" ]; then + Echo_error "Usage() requires an exit code" + fi + echo "${PROGRAM_NAME} - ${DESCRIPTION}" printf "\nUsage:\n\n" @@ -25,5 +29,5 @@ Usage () echo echo "Try \"${PROGRAM} --help\" for more information." - exit 1 + exit $1 } diff --git a/scripts/build/chroot_apt b/scripts/build/chroot_apt index f7f2326f2..cbb0baff0 100755 --- a/scripts/build/chroot_apt +++ b/scripts/build/chroot_apt @@ -217,6 +217,6 @@ case "${1}" in ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_archives b/scripts/build/chroot_archives index 399d4d439..f36f79ccd 100755 --- a/scripts/build/chroot_archives +++ b/scripts/build/chroot_archives @@ -23,7 +23,7 @@ _ACTION="${2}" shift 2 if ! In_list "${_PASS}" "binary" "chroot" "source"; then - Usage + Usage 1 fi # Processing arguments and configuration files @@ -441,6 +441,6 @@ case "${_ACTION}" in ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_debianchroot b/scripts/build/chroot_debianchroot index 7ab3edfa2..3a2050565 100755 --- a/scripts/build/chroot_debianchroot +++ b/scripts/build/chroot_debianchroot @@ -67,6 +67,6 @@ case "${1}" in ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_devpts b/scripts/build/chroot_devpts index 754422dab..0083548ea 100755 --- a/scripts/build/chroot_devpts +++ b/scripts/build/chroot_devpts @@ -63,6 +63,6 @@ case "${1}" in ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_dpkg b/scripts/build/chroot_dpkg index 9b6546671..32460c298 100755 --- a/scripts/build/chroot_dpkg +++ b/scripts/build/chroot_dpkg @@ -84,6 +84,6 @@ EOF ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_hostname b/scripts/build/chroot_hostname index 02578485a..d90e3710d 100755 --- a/scripts/build/chroot_hostname +++ b/scripts/build/chroot_hostname @@ -77,6 +77,6 @@ EOF ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_hosts b/scripts/build/chroot_hosts index 2bf3b1d7a..53fa4f7d4 100755 --- a/scripts/build/chroot_hosts +++ b/scripts/build/chroot_hosts @@ -83,6 +83,6 @@ EOF ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_proc b/scripts/build/chroot_proc index e44248a58..4c845498e 100755 --- a/scripts/build/chroot_proc +++ b/scripts/build/chroot_proc @@ -67,6 +67,6 @@ case "${1}" in ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_resolv b/scripts/build/chroot_resolv index b7957259e..b035c5698 100755 --- a/scripts/build/chroot_resolv +++ b/scripts/build/chroot_resolv @@ -95,6 +95,6 @@ case "${1}" in ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_selinuxfs b/scripts/build/chroot_selinuxfs index ef6ed361c..9bab5eb05 100755 --- a/scripts/build/chroot_selinuxfs +++ b/scripts/build/chroot_selinuxfs @@ -64,6 +64,6 @@ case "${1}" in ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_sysfs b/scripts/build/chroot_sysfs index cc2cf9f52..f95cacb43 100755 --- a/scripts/build/chroot_sysfs +++ b/scripts/build/chroot_sysfs @@ -61,6 +61,6 @@ case "${1}" in ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_sysv-rc b/scripts/build/chroot_sysv-rc index 8b9d2822c..5316ff212 100755 --- a/scripts/build/chroot_sysv-rc +++ b/scripts/build/chroot_sysv-rc @@ -73,6 +73,6 @@ EOF ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/chroot_tmpfs b/scripts/build/chroot_tmpfs index 340f10791..c1cbad68f 100755 --- a/scripts/build/chroot_tmpfs +++ b/scripts/build/chroot_tmpfs @@ -66,6 +66,6 @@ case "${1}" in ;; *) - Usage + Usage 1 ;; esac diff --git a/scripts/build/clean b/scripts/build/clean index c1cf3bba7..82bf052f6 100755 --- a/scripts/build/clean +++ b/scripts/build/clean @@ -144,7 +144,7 @@ do ;; -u|--usage) - Usage + Usage 0 ;; -v|--version) @@ -153,8 +153,7 @@ do ;; *) - Usage - exit 1 + Usage 1 ;; esac done diff --git a/scripts/build/config b/scripts/build/config index 9805e2af0..dbe01d585 100755 --- a/scripts/build/config +++ b/scripts/build/config @@ -294,7 +294,7 @@ Local_arguments () ;; -u|--usage) - Usage + Usage 0 shift ;;