commit: adeb72581e0b6030af14441129059241e009a58a
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Mar 31 15:35:48 2014 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Mon Mar 31 15:35:48 2014 +0000
URL:
http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=adeb7258
hook functions: die_cannot_run()
+ qwhich(): use "hash" instead of "which"
---
doc/rst/usage.rst | 12 +++++++++++-
files/shlib/functions.sh | 16 ++++++++++++++--
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/doc/rst/usage.rst b/doc/rst/usage.rst
index c2d8bc9..f27e933 100644
--- a/doc/rst/usage.rst
+++ b/doc/rst/usage.rst
@@ -2509,10 +2509,17 @@ when included in the hook script, most of the
enviroment variables readonly.
+-----------------+-------------------------------------------------------+
| DEVNULL | */dev/null* target (could also be a file) |
+-----------------+-------------------------------------------------------+
+ | EX_OK | *success* exit code |
+ +-----------------+-------------------------------------------------------+
| EX_ERR | default error exit code |
+-----------------+-------------------------------------------------------+
| EX_ARG_ERR | default exit code for arg errors |
+-----------------+-------------------------------------------------------+
+ | EX_CANNOT_RUN | default exit code when a hook cannot run, |
+ | | e.g. if an essential program is missing |
+ | | |
+ | | Defaults to ``$EX_OK``. |
+ +-----------------+-------------------------------------------------------+
| EX_GIT_ERR | git-related error codes |
| EX_GIT_ADD_ERR | |
| EX_GIT_COMMIT\ | |
@@ -2558,6 +2565,9 @@ when included in the hook script, most of the enviroment
variables readonly.
# @noreturn die ( [message], [exit_code] ), raises exit()
# Lets the script die with the given message/exit code.
#
+ # @noreturn die_cannot_run ( [reason] ), raises die (**EX_CANNOT_RUN)
+ # Lets the script die due to missing preconditions.
+ #
# @noreturn OUT_OF_BOUNDS(), raises die()
# Lets the script die due to insufficient arg count.
#
@@ -2582,7 +2592,7 @@ when included in the hook script, most of the enviroment
variables readonly.
# Returns 0 if $word is in the given list, else 1.
#
# int qwhich ( *command )
- # Returns 0 if all listed commands are found by "which", else 1.
+ # Returns 0 if all listed commands could be found, else 1.
#
# int sync_allowed ( action_name, [msg_nosync], [msg_sync] )
# Returns 0 if syncing for the given action is allowed, else 1.
diff --git a/files/shlib/functions.sh b/files/shlib/functions.sh
index 1603376..fb616dc 100644
--- a/files/shlib/functions.sh
+++ b/files/shlib/functions.sh
@@ -20,6 +20,7 @@
#
# core:
# @noreturn die ( [message], [exit_code] ), raises exit()
+# @noreturn die_cannot_run ( [reason] ), raises die()
# @noreturn OUT_OF_BOUNDS(), raises die()
# int run_command ( *cmdv )
# int run_command_logged ( *cmdv )
@@ -133,8 +134,11 @@ readonly IFS_NEWLINE='
: ${DEVNULL:=/dev/null}
readonly DEVNULL
+readonly EX_OK=0
readonly EX_ERR=2
readonly EX_ARG_ERR=5
+# EX_CANNOT_RUN: configurable
+EX_CANNOT_RUN=${EX_OK}
readonly EX_GIT_ERR=30
readonly EX_GIT_ADD_ERR=35
@@ -193,6 +197,14 @@ die() {
exit "${2:-${EX_ERR?}}"
}
+# @noreturn die_cannot_run ( [reason] ), raises die (**EX_CANNOT_RUN)
+#
+# Lets the script die due to missing preconditions.
+#
+die_cannot_run() {
+ die "${1:-cannot run.}" "${EX_CANNOT_RUN}"
+}
+
# @noreturn OUT_OF_BOUNDS(), raises die (**EX_ARG_ERR)
#
# Catches non-zero shift return and calls die().
@@ -302,11 +314,11 @@ list_has() {
# int qwhich ( *command )
#
-# Returns true if 'which' finds all listed commands, else false.
+# Returns true if all listed commands could be found, else false.
#
qwhich() {
while [ $# -gt 0 ]; do
- which "${1}" 1>>${DEVNULL} 2>>${DEVNULL} || return 1
+ hash "${1}" 1>>${DEVNULL} 2>>${DEVNULL} || return 1
shift
done
return 0