Re: [gentoo-dev] Re: [PATCH 1/1] edo.eclass: add new eclass
> 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. It's even more obscure as a name however. :) >> 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). You're right, the return statement is redundant. >> } Ulrich signature.asc Description: PGP signature
Re: [gentoo-dev] Re: [PATCH 1/1] edo.eclass: add new eclass
On Sat, Apr 16, 2022 at 06:48:56AM -0400, Ionen Wolkens wrote: > 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. Err wait, return $? won't help with that, need a temporary variable to preserve. return $? indeed does nothing here :) -- ionen signature.asc Description: PGP signature
Re: [gentoo-dev] Re: [PATCH 1/1] edo.eclass: add new eclass
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. That still mostly work but maybe, e.g. the code need to check if grep returned 2 (aka error) while 1 isn't an error but just didn't match anything. -- ionen signature.asc Description: PGP signature
Re: [gentoo-dev] Re: [PATCH 1/1] edo.eclass: add new eclass
On 16/04/2022 10.38, Ulrich Mueller wrote: 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 ...]] should be in angle brackets, if we follow the usual convention. Maybe even " [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? +1 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). - Flow