1 |
Bug: https://bugs.gentoo.org/744880 |
2 |
Signed-off-by: Sam James <sam@g.o> |
3 |
--- |
4 |
eclass/edo.eclass | 46 ++++++++++++++++++++++++++++++++++++++++++++++ |
5 |
1 file changed, 46 insertions(+) |
6 |
create mode 100644 eclass/edo.eclass |
7 |
|
8 |
diff --git a/eclass/edo.eclass b/eclass/edo.eclass |
9 |
new file mode 100644 |
10 |
index 000000000000..7b4ae04c43ab |
11 |
--- /dev/null |
12 |
+++ b/eclass/edo.eclass |
13 |
@@ -0,0 +1,46 @@ |
14 |
+# Copyright 2022 Gentoo Authors |
15 |
+# Distributed under the terms of the GNU General Public License v2 |
16 |
+ |
17 |
+# @ECLASS: edo.class |
18 |
+# @MAINTAINER: |
19 |
+# QA Team <qa@g.o> |
20 |
+# @AUTHOR: |
21 |
+# Sam James <sam@g.o> |
22 |
+# @SUPPORTED_EAPIS: 7 8 |
23 |
+# @BLURB: Convenience function to run commands verbosely and die on failure |
24 |
+# @DESCRIPTION: |
25 |
+# This eclass provides the 'edo' command, and an 'edob' variant for ebegin/eend, |
26 |
+# which dies (exits) on failure and logs the command used verbosely. |
27 |
+# |
28 |
+ |
29 |
+case ${EAPI:-0} in |
30 |
+ 7|8) ;; |
31 |
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; |
32 |
+esac |
33 |
+ |
34 |
+if [[ -z ${_EDO_ECLASS} ]] ; then |
35 |
+ _EDO_CLASS=1 |
36 |
+ |
37 |
+# @FUNCTION: edo |
38 |
+# @USAGE: <command> [<args>...] |
39 |
+# @DESCRIPTION: |
40 |
+# Executes 'command' with any given arguments and exits on failure unless |
41 |
+# called under 'nonfatal'. |
42 |
+edo() { |
43 |
+ elog "$@" |
44 |
+ "$@" || die -n "Failed to run command: $@ failed" |
45 |
+} |
46 |
+ |
47 |
+# @FUNCTION: edob |
48 |
+# @USAGE: <command> [<args>...] |
49 |
+# @DESCRIPTION: |
50 |
+# Executes 'command' with ebegin & eend with any given arguments and exits |
51 |
+# on failure unless called under 'nonfatal'. |
52 |
+# Intended for single commands, otherwise regular ebegin/eend should be used. |
53 |
+edob() { |
54 |
+ ebegin "Running $@" |
55 |
+ "$@" |
56 |
+ eend $? || die -n "$@ failed" |
57 |
+} |
58 |
+ |
59 |
+fi |
60 |
-- |
61 |
2.35.1 |