1 |
commit: adeb72581e0b6030af14441129059241e009a58a |
2 |
Author: André Erdmann <dywi <AT> mailerd <DOT> de> |
3 |
AuthorDate: Mon Mar 31 15:35:48 2014 +0000 |
4 |
Commit: André Erdmann <dywi <AT> mailerd <DOT> de> |
5 |
CommitDate: Mon Mar 31 15:35:48 2014 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=adeb7258 |
7 |
|
8 |
hook functions: die_cannot_run() |
9 |
|
10 |
+ qwhich(): use "hash" instead of "which" |
11 |
|
12 |
--- |
13 |
doc/rst/usage.rst | 12 +++++++++++- |
14 |
files/shlib/functions.sh | 16 ++++++++++++++-- |
15 |
2 files changed, 25 insertions(+), 3 deletions(-) |
16 |
|
17 |
diff --git a/doc/rst/usage.rst b/doc/rst/usage.rst |
18 |
index c2d8bc9..f27e933 100644 |
19 |
--- a/doc/rst/usage.rst |
20 |
+++ b/doc/rst/usage.rst |
21 |
@@ -2509,10 +2509,17 @@ when included in the hook script, most of the enviroment variables readonly. |
22 |
+-----------------+-------------------------------------------------------+ |
23 |
| DEVNULL | */dev/null* target (could also be a file) | |
24 |
+-----------------+-------------------------------------------------------+ |
25 |
+ | EX_OK | *success* exit code | |
26 |
+ +-----------------+-------------------------------------------------------+ |
27 |
| EX_ERR | default error exit code | |
28 |
+-----------------+-------------------------------------------------------+ |
29 |
| EX_ARG_ERR | default exit code for arg errors | |
30 |
+-----------------+-------------------------------------------------------+ |
31 |
+ | EX_CANNOT_RUN | default exit code when a hook cannot run, | |
32 |
+ | | e.g. if an essential program is missing | |
33 |
+ | | | |
34 |
+ | | Defaults to ``$EX_OK``. | |
35 |
+ +-----------------+-------------------------------------------------------+ |
36 |
| EX_GIT_ERR | git-related error codes | |
37 |
| EX_GIT_ADD_ERR | | |
38 |
| EX_GIT_COMMIT\ | | |
39 |
@@ -2558,6 +2565,9 @@ when included in the hook script, most of the enviroment variables readonly. |
40 |
# @noreturn die ( [message], [exit_code] ), raises exit() |
41 |
# Lets the script die with the given message/exit code. |
42 |
# |
43 |
+ # @noreturn die_cannot_run ( [reason] ), raises die (**EX_CANNOT_RUN) |
44 |
+ # Lets the script die due to missing preconditions. |
45 |
+ # |
46 |
# @noreturn OUT_OF_BOUNDS(), raises die() |
47 |
# Lets the script die due to insufficient arg count. |
48 |
# |
49 |
@@ -2582,7 +2592,7 @@ when included in the hook script, most of the enviroment variables readonly. |
50 |
# Returns 0 if $word is in the given list, else 1. |
51 |
# |
52 |
# int qwhich ( *command ) |
53 |
- # Returns 0 if all listed commands are found by "which", else 1. |
54 |
+ # Returns 0 if all listed commands could be found, else 1. |
55 |
# |
56 |
# int sync_allowed ( action_name, [msg_nosync], [msg_sync] ) |
57 |
# Returns 0 if syncing for the given action is allowed, else 1. |
58 |
|
59 |
diff --git a/files/shlib/functions.sh b/files/shlib/functions.sh |
60 |
index 1603376..fb616dc 100644 |
61 |
--- a/files/shlib/functions.sh |
62 |
+++ b/files/shlib/functions.sh |
63 |
@@ -20,6 +20,7 @@ |
64 |
# |
65 |
# core: |
66 |
# @noreturn die ( [message], [exit_code] ), raises exit() |
67 |
+# @noreturn die_cannot_run ( [reason] ), raises die() |
68 |
# @noreturn OUT_OF_BOUNDS(), raises die() |
69 |
# int run_command ( *cmdv ) |
70 |
# int run_command_logged ( *cmdv ) |
71 |
@@ -133,8 +134,11 @@ readonly IFS_NEWLINE=' |
72 |
: ${DEVNULL:=/dev/null} |
73 |
readonly DEVNULL |
74 |
|
75 |
+readonly EX_OK=0 |
76 |
readonly EX_ERR=2 |
77 |
readonly EX_ARG_ERR=5 |
78 |
+# EX_CANNOT_RUN: configurable |
79 |
+EX_CANNOT_RUN=${EX_OK} |
80 |
|
81 |
readonly EX_GIT_ERR=30 |
82 |
readonly EX_GIT_ADD_ERR=35 |
83 |
@@ -193,6 +197,14 @@ die() { |
84 |
exit "${2:-${EX_ERR?}}" |
85 |
} |
86 |
|
87 |
+# @noreturn die_cannot_run ( [reason] ), raises die (**EX_CANNOT_RUN) |
88 |
+# |
89 |
+# Lets the script die due to missing preconditions. |
90 |
+# |
91 |
+die_cannot_run() { |
92 |
+ die "${1:-cannot run.}" "${EX_CANNOT_RUN}" |
93 |
+} |
94 |
+ |
95 |
# @noreturn OUT_OF_BOUNDS(), raises die (**EX_ARG_ERR) |
96 |
# |
97 |
# Catches non-zero shift return and calls die(). |
98 |
@@ -302,11 +314,11 @@ list_has() { |
99 |
|
100 |
# int qwhich ( *command ) |
101 |
# |
102 |
-# Returns true if 'which' finds all listed commands, else false. |
103 |
+# Returns true if all listed commands could be found, else false. |
104 |
# |
105 |
qwhich() { |
106 |
while [ $# -gt 0 ]; do |
107 |
- which "${1}" 1>>${DEVNULL} 2>>${DEVNULL} || return 1 |
108 |
+ hash "${1}" 1>>${DEVNULL} 2>>${DEVNULL} || return 1 |
109 |
shift |
110 |
done |
111 |
return 0 |