1 |
On 16/04/2022 20.14, Sam James wrote: |
2 |
> Bug: https://bugs.gentoo.org/744880 |
3 |
> Signed-off-by: Sam James <sam@g.o> |
4 |
> --- |
5 |
> eclass/edo.eclass | 46 ++++++++++++++++++++++++++++++++++++++++++++++ |
6 |
> 1 file changed, 46 insertions(+) |
7 |
> create mode 100644 eclass/edo.eclass |
8 |
> |
9 |
> diff --git a/eclass/edo.eclass b/eclass/edo.eclass |
10 |
> new file mode 100644 |
11 |
> index 000000000000..7b4ae04c43ab |
12 |
> --- /dev/null |
13 |
> +++ b/eclass/edo.eclass |
14 |
> @@ -0,0 +1,46 @@ |
15 |
> +# Copyright 2022 Gentoo Authors |
16 |
> +# Distributed under the terms of the GNU General Public License v2 |
17 |
> + |
18 |
> +# @ECLASS: edo.class |
19 |
> +# @MAINTAINER: |
20 |
> +# QA Team <qa@g.o> |
21 |
> +# @AUTHOR: |
22 |
> +# Sam James <sam@g.o> |
23 |
> +# @SUPPORTED_EAPIS: 7 8 |
24 |
> +# @BLURB: Convenience function to run commands verbosely and die on failure |
25 |
> +# @DESCRIPTION: |
26 |
> +# This eclass provides the 'edo' command, and an 'edob' variant for ebegin/eend, |
27 |
> +# which dies (exits) on failure and logs the command used verbosely. |
28 |
> +# |
29 |
> + |
30 |
> +case ${EAPI:-0} in |
31 |
> + 7|8) ;; |
32 |
> + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; |
33 |
> +esac |
34 |
> + |
35 |
> +if [[ -z ${_EDO_ECLASS} ]] ; then |
36 |
> + _EDO_CLASS=1 |
37 |
|
38 |
typo: s/_CLASS/_ECLASS/ |
39 |
|
40 |
|
41 |
> + |
42 |
> +# @FUNCTION: edo |
43 |
> +# @USAGE: <command> [<args>...] |
44 |
> +# @DESCRIPTION: |
45 |
> +# Executes 'command' with any given arguments and exits on failure unless |
46 |
> +# called under 'nonfatal'. |
47 |
> +edo() { |
48 |
> + elog "$@" |
49 |
> + "$@" || die -n "Failed to run command: $@ failed" |
50 |
> +} |
51 |
> + |
52 |
> +# @FUNCTION: edob |
53 |
> +# @USAGE: <command> [<args>...] |
54 |
> +# @DESCRIPTION: |
55 |
> +# Executes 'command' with ebegin & eend with any given arguments and exits |
56 |
> +# on failure unless called under 'nonfatal'. |
57 |
|
58 |
Maybe mention that 'command' should be "short". I do not know if we want |
59 |
or can provide a concrete value that determines shortness. |
60 |
|
61 |
|
62 |
> +# Intended for single commands, otherwise regular ebegin/eend should be used. |
63 |
|
64 |
I think it is obvious that it can be only used for single commands. If I |
65 |
am not mistaken, using multiple commands within ebegin/eend also means |
66 |
that those commands, or, at least all commands after the first, can not |
67 |
(or at least "should not") be printed/logged, as I assume that it would |
68 |
break eend()'s positioning. |
69 |
|
70 |
With multiple commands (e.g., cmd1, cmd2, cmd3), I'd probably suggest to |
71 |
|
72 |
edo cmd1 |
73 |
edo cmd2 |
74 |
edo cmd3 |
75 |
|
76 |
since I personally like to avoid the inflationary usage of ebegin/eend |
77 |
and instead recommend to use ebegin/eend only for a few long-running |
78 |
milestone commands in the ebuild (if any). |
79 |
|
80 |
Hence I don't like that the description line above redirects the user to |
81 |
ebegin/eend. It can probably simply be dropped. |
82 |
|
83 |
|
84 |
> +edob() { |
85 |
> + ebegin "Running $@" |
86 |
> + "$@" |
87 |
> + eend $? || die -n "$@ failed" |
88 |
> +} |
89 |
> + |
90 |
> +fi |
91 |
|
92 |
Like ionen, I also wondered if this could be an argument to edo, but I |
93 |
believe this would clutter edo's implementation with argument parsing |
94 |
and additional logic. Hence I believe having two separate functions, as |
95 |
in this patch, is the way to go. |
96 |
|
97 |
Thanks Sam! |
98 |
|
99 |
- Flow |