On Sat, 16 Apr 2022, Sam James wrote:
+# @FUNCTION: edo
+# @USAGE: command [arg1 [arg2 ...]]
+# @DESCRIPTION:
+# Executes 'command' with any given arguments and exits on failure unless
+# called under 'nonfatal'.
+edo() {
+ elog "$@"
+ "$@" || die -n "Failed to run command: $@ failed"
+}
ebegin "Running $@"
"$@"
eend $? || die -n "$@ failed" > return $?
I think this return statement can be omitted since it will always be
invoked with 0 as argument, and this is the default behavior of implicit function return (IIRC).
On Sat, Apr 16, 2022 at 12:23:18PM +0200, Florian Schmaus wrote:
ebegin "Running $@"
"$@"
eend $? || die -n "$@ failed" > return $?
I think this return statement can be omitted since it will always be invoked with 0 as argument, and this is the default behavior of implicit function return (IIRC).
Not with nonfatal (die is using -n to allow it)
nonfatal edo false || echo "different error handling: $?"
Without return $?, the above will echo 0 or 1 if die was triggered
but (with current implementation) won't be the actual return code.
On Sat, 16 Apr 2022, Sam James wrote:
+# @FUNCTION: edo
Just a remark: A similar command existed a long time ago under the
name "try". [1]
It was executed under "env" [2], should we also do that?
+# @USAGE: command [arg1 [arg2 ...]]
<command> should be in angle brackets, if we follow the usual
convention. Maybe even "<command> [arg]..."
+# @DESCRIPTION:
+# Executes 'command' with any given arguments and exits on failure unless >> +# called under 'nonfatal'.
+edo() {
+ elog "$@"
+ "$@" || die -n "Failed to run command: $@ failed"
+}
Maybe add an ebegin/eend variant?
edobe() {
ebegin "Running $@"
"$@"
eend $? || die -n "$@ failed" > return $?
On Sat, 16 Apr 2022, Florian Schmaus wrote:
edobe() {
nit: I'd personally would use 'edob', as shorter is sometimes better
plus every begin needs an end, so no need to explicitly state that
there is an end.
ebegin "Running $@"
"$@"
eend $? || die -n "$@ failed"
return $?
I think this return statement can be omitted since it will always be
invoked with 0 as argument, and this is the default behavior of
implicit function return (IIRC).
}
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 475 |
Nodes: | 16 (2 / 14) |
Uptime: | 18:24:49 |
Calls: | 9,487 |
Calls today: | 6 |
Files: | 13,617 |
Messages: | 6,121,091 |