1 |
>>>>> On Sun, 17 Apr 2022, Sam James wrote: |
2 |
|
3 |
> --- /dev/null |
4 |
> +++ b/eclass/edo.eclass |
5 |
> @@ -0,0 +1,45 @@ |
6 |
> +# Copyright 2022 Gentoo Authors |
7 |
> +# Distributed under the terms of the GNU General Public License v2 |
8 |
> + |
9 |
> +# @ECLASS: edo.class |
10 |
> +# @MAINTAINER: |
11 |
> +# QA Team <qa@g.o> |
12 |
> +# @AUTHOR: |
13 |
> +# Sam James <sam@g.o> |
14 |
> +# @SUPPORTED_EAPIS: 7 8 |
15 |
> +# @BLURB: Convenience function to run commands verbosely and die on failure |
16 |
> +# @DESCRIPTION: |
17 |
> +# This eclass provides the 'edo' command, and an 'edob' variant for ebegin/eend, |
18 |
> +# which dies (exits) on failure and logs the command used verbosely. |
19 |
> +# |
20 |
> + |
21 |
> +case ${EAPI:-0} in |
22 |
|
23 |
Just ${EAPI} here, the fallback isn't necessary. |
24 |
|
25 |
> + 7|8) ;; |
26 |
> + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; |
27 |
> +esac |
28 |
> + |
29 |
> +if [[ -z ${_EDO_ECLASS} ]] ; then |
30 |
> +_EDO_ECLASS=1 |
31 |
> + |
32 |
> +# @FUNCTION: edo |
33 |
> +# @USAGE: <command> [<args>...] |
34 |
> +# @DESCRIPTION: |
35 |
> +# Executes a short 'command' with any given arguments and exits on failure unless |
36 |
|
37 |
Long line. |
38 |
|
39 |
> +# called under 'nonfatal'. |
40 |
> +edo() { |
41 |
> + einfo "$@" |
42 |
> + "$@" || die -n "Failed to run command: $@" |
43 |
> +} |
44 |
> + |
45 |
> +# @FUNCTION: edob |
46 |
> +# @USAGE: <command> [<args>...] |
47 |
> +# @DESCRIPTION: |
48 |
> +# Executes 'command' with ebegin & eend with any given arguments and exits |
49 |
> +# on failure unless called under 'nonfatal'. |
50 |
> +edob() { |
51 |
> + ebegin "Running $@" |
52 |
> + "$@" |
53 |
> + eend $? || die -n "Failed to run command: $@" |
54 |
> +} |
55 |
> + |
56 |
> +fi |