commit:     18109919b4f983da20bf9656b4f819fe3802d904
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Sat Apr 16 06:16:20 2022 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Apr 18 17:43:47 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=18109919

edo.eclass: add new eclass

Bug: https://bugs.gentoo.org/744880
Signed-off-by: Sam James <sam <AT> gentoo.org>

 eclass/edo.eclass | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/eclass/edo.eclass b/eclass/edo.eclass
new file mode 100644
index 000000000000..aa0385842c35
--- /dev/null
+++ b/eclass/edo.eclass
@@ -0,0 +1,45 @@
+# Copyright 2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: edo.class
+# @MAINTAINER:
+# QA Team <[email protected]>
+# @AUTHOR:
+# Sam James <[email protected]>
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: Convenience function to run commands verbosely and die on failure
+# @DESCRIPTION:
+# This eclass provides the 'edo' command, and an 'edob' variant for 
ebegin/eend,
+# which dies (exits) on failure and logs the command used verbosely.
+#
+
+case ${EAPI} in
+       7|8) ;;
+       *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+if [[ -z ${_EDO_ECLASS} ]] ; then
+_EDO_ECLASS=1
+
+# @FUNCTION: edo
+# @USAGE: <command> [<args>...]
+# @DESCRIPTION:
+# Executes a short 'command' with any given arguments and exits on failure
+# unless called under 'nonfatal'.
+edo() {
+       einfo "$@"
+       "$@" || die -n "Failed to run command: $@"
+}
+
+# @FUNCTION: edob
+# @USAGE: <command> [<args>...]
+# @DESCRIPTION:
+# Executes 'command' with ebegin & eend with any given arguments and exits
+# on failure unless called under 'nonfatal'.
+edob() {
+       ebegin "Running $@"
+       "$@"
+       eend $? || die -n "Failed to run command: $@"
+}
+
+fi

Reply via email to